com.intellij.openapi.editor.colors.CodeInsightColors Java Examples

The following examples show how to use com.intellij.openapi.editor.colors.CodeInsightColors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChangeSignaturePassFactory.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void doApplyInformationToEditor() {
  HighlightInfo info = null;
  final InplaceChangeSignature currentRefactoring = InplaceChangeSignature.getCurrentRefactoring(myEditor);
  if (currentRefactoring != null) {
    final ChangeInfo changeInfo = currentRefactoring.getStableChange();
    final PsiElement element = changeInfo.getMethod();
    int offset = myEditor.getCaretModel().getOffset();
    if (element == null || !element.isValid()) return;
    final TextRange elementTextRange = element.getTextRange();
    if (elementTextRange == null || !elementTextRange.contains(offset)) return;
    final LanguageChangeSignatureDetector<ChangeInfo> detector = LanguageChangeSignatureDetectors.INSTANCE.forLanguage(changeInfo.getLanguage());
    TextRange range = detector.getHighlightingRange(changeInfo);
    TextAttributes attributes = new TextAttributes(null, null,
                                                   myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES)
                                                           .getEffectColor(),
                                                   null, Font.PLAIN);
    HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(range);
    builder.textAttributes(attributes);
    builder.descriptionAndTooltip(SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED);
    info = builder.createUnconditionally();
    QuickFixAction.registerQuickFixAction(info, new ApplyChangeSignatureAction(currentRefactoring.getInitialName()));
  }
  Collection<HighlightInfo> infos = info != null ? Collections.singletonList(info) : Collections.emptyList();
  UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
}
 
Example #2
Source File: PsiFileNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  PsiFile value = getValue();
  data.setPresentableText(value.getName());
  data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));

  VirtualFile file = getVirtualFile();
  if (file != null && file.is(VFileProperty.SYMLINK)) {
    String target = file.getCanonicalPath();
    if (target == null) {
      data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      data.setTooltip(CommonBundle.message("vfs.broken.link"));
    }
    else {
      data.setTooltip(FileUtil.toSystemDependentName(target));
    }
  }
}
 
Example #3
Source File: ColorSettingsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addInspectionSeverityAttributes(List<AttributesDescriptor> descriptors) {
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.weak.warning"), CodeInsightColors.WEAK_WARNING_ATTRIBUTES));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
  descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));

  for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
    for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
      final TextAttributesKey attributesKey = highlightInfoType.getAttributesKey();
      descriptors.add(new AttributesDescriptor(toDisplayName(attributesKey), attributesKey));
    }
  }
}
 
Example #4
Source File: Annotation.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the text attribute key used for highlighting the annotation. If not specified
 * explicitly, the key is determined automatically based on the problem highlight type and
 * the annotation severity.
 *
 * @return the text attribute key used for highlighting
 */
@Nonnull
public TextAttributesKey getTextAttributes() {
  if (myEnforcedAttributesKey != null) return myEnforcedAttributesKey;

  if (myHighlightType == ProblemHighlightType.GENERIC_ERROR_OR_WARNING) {
    if (mySeverity == HighlightSeverity.ERROR) return CodeInsightColors.ERRORS_ATTRIBUTES;
    if (mySeverity == HighlightSeverity.WARNING) return CodeInsightColors.WARNINGS_ATTRIBUTES;
    if (mySeverity == HighlightSeverity.WEAK_WARNING) return CodeInsightColors.WEAK_WARNING_ATTRIBUTES;
  }

  if (myHighlightType == ProblemHighlightType.GENERIC_ERROR) {
    return CodeInsightColors.ERRORS_ATTRIBUTES;
  }

  if (myHighlightType == ProblemHighlightType.LIKE_DEPRECATED) {
    return CodeInsightColors.DEPRECATED_ATTRIBUTES;
  }
  if (myHighlightType == ProblemHighlightType.LIKE_UNUSED_SYMBOL) {
    return CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES;
  }
  if (myHighlightType == ProblemHighlightType.LIKE_UNKNOWN_SYMBOL || myHighlightType == ProblemHighlightType.ERROR) {
    return CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES;
  }
  return HighlighterColors.NO_HIGHLIGHTING;
}
 
Example #5
Source File: SearchForUsagesRunnable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void flashUsageScriptaculously(@Nonnull final Usage usage) {
  if (!(usage instanceof UsageInfo2UsageAdapter)) {
    return;
  }
  UsageInfo2UsageAdapter usageInfo = (UsageInfo2UsageAdapter)usage;

  Editor editor = usageInfo.openTextEditor(true);
  if (editor == null) return;
  TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);

  RangeBlinker rangeBlinker = new RangeBlinker(editor, attributes, 6);
  List<Segment> segments = new ArrayList<>();
  Processor<Segment> processor = Processors.cancelableCollectProcessor(segments);
  usageInfo.processRangeMarkers(processor);
  rangeBlinker.resetMarkers(segments);
  rangeBlinker.startBlinking();
}
 
Example #6
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static JPanel createSeparatorLine(@Nonnull EditorColorsScheme colorsScheme) {
  Color color = colorsScheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
  if (color == null) {
    color = JBColor.namedColor("Group.separatorColor", new JBColor(Gray.xCD, Gray.x51));
  }

  return JBUI.Panels.simplePanel().withBorder(JBUI.Borders.customLine(color, 1, 0, 0, 0));
}
 
Example #7
Source File: ScopeTreeViewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  Font font = UIUtil.getTreeFont();
  setFont(font.deriveFont(font.getSize() + JBUI.scale(1f)));

  if (value instanceof PackageDependenciesNode) {
    PackageDependenciesNode node = (PackageDependenciesNode)value;
    try {
      setIcon(node.getIcon());
    }
    catch (IndexNotReadyException ignore) {
    }
    final SimpleTextAttributes regularAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    TextAttributes textAttributes = regularAttributes.toTextAttributes();
    if (node instanceof BasePsiNode && ((BasePsiNode)node).isDeprecated()) {
      textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).clone();
    }
    final PsiElement psiElement = node.getPsiElement();
    textAttributes.setForegroundColor(CopyPasteManager.getInstance().isCutElement(psiElement) ? CopyPasteManager.CUT_COLOR : node.getColor());
    append(node.toString(), SimpleTextAttributes.fromTextAttributes(textAttributes));

    String oldToString = toString();
    if (!myProject.isDisposed()) {
      for (ProjectViewNodeDecorator decorator : Extensions.getExtensions(ProjectViewNodeDecorator.EP_NAME, myProject)) {
        decorator.decorate(node, this);
      }
    }
    if (toString().equals(oldToString)) {   // nothing was decorated
      final String locationString = node.getComment();
      if (locationString != null && locationString.length() > 0) {
        append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
      }
    }
  }
}
 
Example #8
Source File: ActionUsagePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ActionUsagePanel() {
  myEditor = (EditorEx)createEditor("", 10, 3, -1);
  setLayout(new BorderLayout());
  add(myEditor.getComponent(), BorderLayout.CENTER);
  TextAttributes blinkAttributes =
          EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
  myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE);
}
 
Example #9
Source File: IntentionUsagePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public IntentionUsagePanel() {
  myEditor = (EditorEx)createEditor("", 10, 3, -1);
  setLayout(new BorderLayout());
  add(myEditor.getComponent(), BorderLayout.CENTER);
  TextAttributes blinkAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
  myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE);
}
 
Example #10
Source File: LineMarkersPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LineMarkerInfo<PsiElement> createMethodSeparatorLineMarker(@Nonnull PsiElement startFrom, @Nonnull EditorColorsManager colorsManager) {
  LineMarkerInfo<PsiElement> info = new LineMarkerInfo<>(startFrom, startFrom.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
  EditorColorsScheme scheme = colorsManager.getGlobalScheme();
  info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
  info.separatorPlacement = SeparatorPlacement.TOP;
  return info;
}
 
Example #11
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void highlightBrace(@Nonnull TextRange braceRange, boolean matched) {
  EditorColorsScheme scheme = myEditor.getColorsScheme();
  final TextAttributes attributes =
          matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES)
                  : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);


  RangeHighlighter rbraceHighlighter =
          myEditor.getMarkupModel().addRangeHighlighter(
                  braceRange.getStartOffset(), braceRange.getEndOffset(), HighlighterLayer.LAST + 1, attributes, HighlighterTargetArea.EXACT_RANGE);
  rbraceHighlighter.setGreedyToLeft(false);
  rbraceHighlighter.setGreedyToRight(false);
  registerHighlighter(rbraceHighlighter);
}
 
Example #12
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static SimpleTextAttributes createBreadcrumbsTextAttributes(@Nonnull EditorColorsScheme colorsScheme, boolean selected) {
  Color backgroundColor = getBackgroundColor(colorsScheme, selected);
  TextAttributes attributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
  if (attributes != null) {
    Color unusedForeground = attributes.getForegroundColor();
    if (unusedForeground != null) {
      return SimpleTextAttributes.fromTextAttributes(new TextAttributes(unusedForeground, backgroundColor, null, null, Font.PLAIN));
    }
  }

  return SimpleTextAttributes.fromTextAttributes(createDefaultTextAttributesWithBackground(colorsScheme, backgroundColor));
}
 
Example #13
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static TextAttributes getFollowedHyperlinkAttributes(@Nonnull RangeHighlighter range) {
  HyperlinkInfoTextAttributes attrs = HYPERLINK.get(range);
  TextAttributes result = attrs != null ? attrs.getFollowedHyperlinkAttributes() : null;
  if (result == null) {
    result = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.FOLLOWED_HYPERLINK_ATTRIBUTES);
  }
  return result;
}
 
Example #14
Source File: ProblemDescriptorUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static HighlightInfoType highlightTypeFromDescriptor(@Nonnull ProblemDescriptor problemDescriptor,
                                                            @Nonnull HighlightSeverity severity,
                                                            @Nonnull SeverityRegistrar severityRegistrar) {
  final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
  switch (highlightType) {
    case GENERIC_ERROR_OR_WARNING:
      return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
    case LIKE_DEPRECATED:
      return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.DEPRECATED.getAttributesKey());
    case LIKE_UNKNOWN_SYMBOL:
      if (severity == HighlightSeverity.ERROR) {
        return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.WRONG_REF.getAttributesKey());
      }
      if (severity == HighlightSeverity.WARNING) {
        return new HighlightInfoType.HighlightInfoTypeImpl(severity, CodeInsightColors.WEAK_WARNING_ATTRIBUTES);
      }
      return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
    case LIKE_UNUSED_SYMBOL:
      return new HighlightInfoType.HighlightInfoTypeImpl(severity, HighlightInfoType.UNUSED_SYMBOL.getAttributesKey());
    case INFO:
      return HighlightInfoType.INFO;
    case WEAK_WARNING:
      return HighlightInfoType.WEAK_WARNING;
    case ERROR:
      return HighlightInfoType.WRONG_REF;
    case GENERIC_ERROR:
      return HighlightInfoType.ERROR;
    case INFORMATION:
      final TextAttributesKey attributes = ((ProblemDescriptorBase)problemDescriptor).getEnforcedTextAttributes();
      if (attributes != null) {
        return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
      }
      return HighlightInfoType.INFORMATION;
  }
  throw new RuntimeException("Cannot map " + highlightType);
}
 
Example #15
Source File: CoverageLineMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static TextAttributesKey getAttributesKey(LineData lineData) {
  if (lineData != null) {
    switch (lineData.getStatus()) {
      case LineCoverage.FULL:
        return CodeInsightColors.LINE_FULL_COVERAGE;
      case LineCoverage.PARTIAL:
        return CodeInsightColors.LINE_PARTIAL_COVERAGE;
    }
  }

  return CodeInsightColors.LINE_NONE_COVERAGE;
}
 
Example #16
Source File: CSharpHighlightUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
public static HighlightInfo highlightNamed(@Nonnull HighlightInfoHolder holder, @Nullable PsiElement element, @Nullable PsiElement target, @Nullable PsiElement owner)
{
	if(target == null || element == null)
	{
		return null;
	}

	IElementType elementType = target.getNode().getElementType();
	if(CSharpTokenSets.KEYWORDS.contains(elementType))  // don't highlight keywords
	{
		return null;
	}

	if(isMethodRef(owner, element))
	{
		HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CSharpHighlightKey.METHOD_REF).create();
		holder.add(highlightInfo);
	}

	TextAttributesKey defaultTextAttributeKey = getDefaultTextAttributeKey(element, target);
	if(defaultTextAttributeKey == null)
	{
		return null;
	}

	HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(defaultTextAttributeKey).create();
	holder.add(info);
	if(!(target instanceof CSharpIdentifier) && DotNetAttributeUtil.hasAttribute(element, DotNetTypes.System.ObsoleteAttribute))
	{
		holder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(target).textAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES).create());
	}

	return info;
}
 
Example #17
Source File: JavaColorSettings.java    From Custom-Syntax-Highlighter with MIT License 4 votes vote down vote up
private static Map<String, TextAttributesKey> createAdditionalHlAttrs() {
  final Map<String, TextAttributesKey> descriptors = new THashMap<>();

  descriptors.put("field", ObjectUtils.notNull(TextAttributesKey.find("INSTANCE_FIELD_ATTRIBUTES"),
      DefaultLanguageHighlighterColors.INSTANCE_FIELD));
  descriptors.put("unusedField", CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
  descriptors.put("error", CodeInsightColors.ERRORS_ATTRIBUTES);
  descriptors.put("warning", CodeInsightColors.WARNINGS_ATTRIBUTES);
  descriptors.put("weak_warning", CodeInsightColors.WEAK_WARNING_ATTRIBUTES);
  descriptors.put("server_problems", CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING);
  descriptors.put("server_duplicate", CodeInsightColors.DUPLICATE_FROM_SERVER);
  descriptors.put("unknownType", CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
  descriptors.put("localVar", ObjectUtils.notNull(TextAttributesKey.find("LOCAL_VARIABLE_ATTRIBUTES"),
      DefaultLanguageHighlighterColors.LOCAL_VARIABLE));
  descriptors.put("reassignedLocalVar", ObjectUtils.notNull(TextAttributesKey.find("REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES"),
      DefaultLanguageHighlighterColors.REASSIGNED_LOCAL_VARIABLE));
  descriptors.put("reassignedParameter", ObjectUtils.notNull(TextAttributesKey.find("REASSIGNED_PARAMETER_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.REASSIGNED_PARAMETER));
  descriptors.put("implicitAnonymousParameter",
      ObjectUtils.notNull(TextAttributesKey.find("IMPLICIT_ANONYMOUS_CLASS_PARAMETER_ATTRIBUTES);"),
          DefaultLanguageHighlighterColors.CLASS_NAME));
  descriptors.put("static", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FIELD_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.STATIC_FIELD));
  descriptors.put("static_final", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FINAL_FIELD_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.STATIC_FIELD));
  descriptors.put("deprecated", CodeInsightColors.DEPRECATED_ATTRIBUTES);
  descriptors.put("for_removal", CodeInsightColors.MARKED_FOR_REMOVAL_ATTRIBUTES);
  descriptors.put("constructorCall", ObjectUtils.notNull(TextAttributesKey.find("CONSTRUCTOR_CALL_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.FUNCTION_CALL));
  descriptors.put("constructorDeclaration", ObjectUtils.notNull(TextAttributesKey.find("CONSTRUCTOR_DECLARATION_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.FUNCTION_DECLARATION));
  descriptors.put("methodCall", ObjectUtils.notNull(TextAttributesKey.find("METHOD_CALL_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.FUNCTION_CALL));
  descriptors.put("methodDeclaration", ObjectUtils.notNull(TextAttributesKey.find("METHOD_DECLARATION_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.FUNCTION_DECLARATION));
  descriptors.put("static_method", ObjectUtils.notNull(TextAttributesKey.find("STATIC_METHOD_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.STATIC_METHOD));
  descriptors.put("abstract_method", ObjectUtils.notNull(TextAttributesKey.find("ABSTRACT_METHOD_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.FUNCTION_CALL));
  descriptors.put("inherited_method", ObjectUtils.notNull(TextAttributesKey.find("INHERITED_METHOD_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.FUNCTION_CALL));
  descriptors.put("param", ObjectUtils.notNull(TextAttributesKey.find("PARAMETER_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.PARAMETER));
  descriptors.put("lambda_param", ObjectUtils.notNull(TextAttributesKey.find("LAMBDA_PARAMETER_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.PARAMETER));
  descriptors.put("class", ObjectUtils.notNull(TextAttributesKey.find("CLASS_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.CLASS_NAME));
  descriptors.put("anonymousClass", ObjectUtils.notNull(TextAttributesKey.find("ANONYMOUS_CLASS_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.CLASS_NAME));
  descriptors.put("typeParameter", ObjectUtils.notNull(TextAttributesKey.find("TYPE_PARAMETER_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.PARAMETER));
  descriptors.put("abstractClass", ObjectUtils.notNull(TextAttributesKey.find("ABSTRACT_CLASS_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.CLASS_NAME));
  descriptors.put("interface", ObjectUtils.notNull(TextAttributesKey.find("INTERFACE_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.INTERFACE_NAME));
  descriptors.put("enum", ObjectUtils.notNull(TextAttributesKey.find("ENUM_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.CLASS_NAME));
  descriptors.put("annotationName", ObjectUtils.notNull(TextAttributesKey.find("ANNOTATION_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.METADATA));
  descriptors.put("annotationAttributeName", ObjectUtils.notNull(TextAttributesKey.find("ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.METADATA));
  descriptors.put("javadocTagValue", ObjectUtils.notNull(TextAttributesKey.find("DOC_COMMENT_TAG_VALUE);"),
      DefaultLanguageHighlighterColors.DOC_COMMENT_TAG_VALUE));
  descriptors.put("instanceFinalField", ObjectUtils.notNull(TextAttributesKey.find("INSTANCE_FINAL_FIELD_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.INSTANCE_FIELD));
  descriptors.put("staticallyConstImported", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FINAL_FIELD_IMPORTED_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.STATIC_FIELD));
  descriptors.put("staticallyImported", ObjectUtils.notNull(TextAttributesKey.find("STATIC_FIELD_IMPORTED_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.STATIC_FIELD));
  descriptors.put("static_imported_method", ObjectUtils.notNull(TextAttributesKey.find("STATIC_METHOD_CALL_IMPORTED_ATTRIBUTES);"),
      DefaultLanguageHighlighterColors.STATIC_METHOD));

  descriptors.put("keyword", JavaColorSettings.JAVA_KEYWORD);
  descriptors.put("this", JavaColorSettings.THIS_SUPER);
  descriptors.put("sf", JavaColorSettings.STATIC_FINAL);
  descriptors.put("modifier", JavaColorSettings.MODIFIER);

  return descriptors;
}
 
Example #18
Source File: RecentLocationsRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static TextAttributes createEmptyTextForegroundTextAttributes(@Nonnull EditorColorsScheme colorsScheme) {
  TextAttributes unusedAttributes = colorsScheme.getAttributes(CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
  return unusedAttributes != null ? unusedAttributes : SimpleTextAttributes.GRAYED_ATTRIBUTES.toTextAttributes();
}
 
Example #19
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void highlightBraces(@Nullable TextRange lBrace, @Nullable TextRange rBrace, boolean matched, boolean scopeHighlighting, @Nonnull FileType fileType) {
  if (!matched && fileType == PlainTextFileType.INSTANCE) {
    return;
  }

  EditorColorsScheme scheme = myEditor.getColorsScheme();
  final TextAttributes attributes =
          matched ? scheme.getAttributes(CodeInsightColors.MATCHED_BRACE_ATTRIBUTES)
                  : scheme.getAttributes(CodeInsightColors.UNMATCHED_BRACE_ATTRIBUTES);

  if (rBrace != null && !scopeHighlighting) {
    highlightBrace(rBrace, matched);
  }

  if (lBrace != null && !scopeHighlighting) {
    highlightBrace(lBrace, matched);
  }

  FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); // null in default project
  if (fileEditorManager == null || !myEditor.equals(fileEditorManager.getSelectedTextEditor())) {
    return;
  }

  if (lBrace != null && rBrace !=null) {
    final int startLine = myEditor.offsetToLogicalPosition(lBrace.getStartOffset()).line;
    final int endLine = myEditor.offsetToLogicalPosition(rBrace.getEndOffset()).line;
    if (endLine - startLine > 0) {
      final Runnable runnable = () -> {
        if (myProject.isDisposed() || myEditor.isDisposed()) return;
        Color color = attributes.getBackgroundColor();
        if (color == null) return;
        color = ColorUtil.isDark(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()) ? ColorUtil.shift(color, 1.5d) : color.darker();
        lineMarkFragment(startLine, endLine, color);
      };

      if (!scopeHighlighting) {
        myAlarm.addRequest(runnable, 300);
      }
      else {
        runnable.run();
      }
    }
    else {
      removeLineMarkers();
    }

    if (!scopeHighlighting) {
      showScopeHint(lBrace.getStartOffset(), lBrace.getEndOffset());
    }
  }
  else {
    if (!myCodeInsightSettings.HIGHLIGHT_SCOPE) {
      removeLineMarkers();
    }
  }
}
 
Example #20
Source File: EditorHyperlinkSupport.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static TextAttributes getHyperlinkAttributes() {
  return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES);
}
 
Example #21
Source File: TodoAttributesUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static TextAttributes getDefaultColorSchemeTextAttributes() {
  return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.TODO_DEFAULT_ATTRIBUTES).clone();
}
 
Example #22
Source File: CSharpLineMarkerProvider.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@Nonnull PsiElement element)
{
	if(myDaemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && (element instanceof DotNetQualifiedElement))
	{
		if(element.getNode().getTreeParent() == null)
		{
			return null;
		}

		final PsiElement parent = element.getParent();
		if(!(parent instanceof DotNetMemberOwner))
		{
			return null;
		}

		if(ArrayUtil.getFirstElement(((DotNetMemberOwner) parent).getMembers()) == element)
		{
			return null;
		}

		LineMarkerInfo info = new LineMarkerInfo<PsiElement>(element, element.getTextRange(), null, Pass.UPDATE_ALL, FunctionUtil.<Object, String>nullConstant(), null,
				GutterIconRenderer.Alignment.RIGHT);
		EditorColorsScheme scheme = myEditorColorsManager.getGlobalScheme();
		info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
		info.separatorPlacement = SeparatorPlacement.TOP;
		return info;
	}

	final Ref<LineMarkerInfo> ref = Ref.create();
	Consumer<LineMarkerInfo> consumer = new Consumer<LineMarkerInfo>()
	{
		@Override
		public void consume(LineMarkerInfo markerInfo)
		{
			ref.set(markerInfo);
		}
	};

	//noinspection ForLoopReplaceableByForEach
	for(int j = 0; j < ourSingleCollector.length; j++)
	{
		LineMarkerCollector ourCollector = ourSingleCollector[j];
		ourCollector.collect(element, consumer);
	}

	return ref.get();
}
 
Example #23
Source File: UnreachableAnnotation.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
public UnreachableAnnotation() {
    unreachableAttributes = TextAttributesKey.createTextAttributesKey("GLSL.UNREACHABLE", CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES);
}
 
Example #24
Source File: JSGraphQLEndpointDocHighlightAnnotator.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {

	final IElementType elementType = element.getNode().getElementType();

       // highlight TO-DO items
       if(elementType == JSGraphQLEndpointDocTokenTypes.DOCTEXT) {
		final String elementText = element.getText().toLowerCase();
		if(isTodoToken(elementText)) {
			setTextAttributes(element, holder, CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
               holder.getCurrentAnnotationSession().putUserData(TODO_ELEMENT, element);
			return;
		} else {
               PsiElement prevSibling = element.getPrevSibling();
               while (prevSibling != null) {
                   if(prevSibling == holder.getCurrentAnnotationSession().getUserData(TODO_ELEMENT)) {
                       setTextAttributes(element, holder, CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
                       return;
                   }
                   prevSibling = prevSibling.getPrevSibling();
               }
           }
	}

	final PsiComment comment = PsiTreeUtil.getContextOfType(element, PsiComment.class);
	if (comment != null && JSGraphQLEndpointDocPsiUtil.isDocumentationComment(comment)) {
		final TextAttributesKey textAttributesKey = ATTRIBUTES.get(elementType);
		if (textAttributesKey != null) {
			setTextAttributes(element, holder, textAttributesKey);
		}
		// highlight invalid argument names after @param
		if(elementType == JSGraphQLEndpointDocTokenTypes.DOCVALUE) {
			final JSGraphQLEndpointFieldDefinition field = PsiTreeUtil.getNextSiblingOfType(comment, JSGraphQLEndpointFieldDefinition.class);
			if(field != null) {
				final JSGraphQLEndpointDocTag tag = PsiTreeUtil.getParentOfType(element, JSGraphQLEndpointDocTag.class);
				if(tag != null && tag.getDocName().getText().equals("@param")) {
					final String paramName = element.getText();
					final JSGraphQLEndpointInputValueDefinitions arguments = PsiTreeUtil.findChildOfType(field, JSGraphQLEndpointInputValueDefinitions.class);
					if(arguments == null) {
						// no arguments so invalid use of @param
						holder.createErrorAnnotation(element, "Invalid use of @param. The property has no arguments");
					} else {
						final JSGraphQLEndpointInputValueDefinition[] inputValues = PsiTreeUtil.getChildrenOfType(arguments, JSGraphQLEndpointInputValueDefinition.class);
						boolean found = false;
						if(inputValues != null) {
							for (JSGraphQLEndpointInputValueDefinition inputValue: inputValues) {
								if(inputValue.getInputValueDefinitionIdentifier().getText().equals(paramName)) {
									found = true;
									break;
								}
							}
						}
						if(!found) {
							holder.createErrorAnnotation(element, "@param name '" + element.getText() + "' doesn't match any of the field arguments");
						}

					}
				}
			}
		}
	}
}