Java Code Examples for com.intellij.openapi.editor.colors.TextAttributesKey#find()

The following examples show how to use com.intellij.openapi.editor.colors.TextAttributesKey#find() . 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: HaxeColorAnnotator.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Nullable
private static TextAttributesKey getAttributeByType(@Nullable HaxeComponentType type, boolean isStatic) {
  if (type == null) {
    return null;
  }
  switch (type) {
    case CLASS:
    case ENUM:
    case TYPEDEF:
      return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_CLASS);
    case INTERFACE:
      return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_INTERFACE);
    case PARAMETER:
      return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_PARAMETER);
    case VARIABLE:
      return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_LOCAL_VARIABLE);
    case FIELD:
      if (isStatic) return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_STATIC_MEMBER_VARIABLE);
      return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_INSTANCE_MEMBER_VARIABLE);
    case METHOD:
      if (isStatic) return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_STATIC_MEMBER_FUNCTION);
      return TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_INSTANCE_MEMBER_FUNCTION);
    default:
      return null;
  }
}
 
Example 2
Source File: DiffOptionsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void updateOptionsList() {
  myOptionsModel.clear();
  myDescriptions.clear();
  Map<TextAttributesKey, TextDiffType> typesByKey = ContainerUtil.newMapFromValues(TextDiffType.MERGE_TYPES.iterator(),
                                                                                   TextDiffType.ATTRIBUTES_KEY);
  for (int i = 0; i < myOptions.getCurrentDescriptions().length; i++) {
    EditorSchemeAttributeDescriptor description = myOptions.getCurrentDescriptions()[i];
    TextAttributesKey type = TextAttributesKey.find(description.getType());
    if (description.getGroup() == ColorAndFontOptions.DIFF_GROUP &&
        typesByKey.keySet().contains(type)) {
      myOptionsModel.add(typesByKey.get(type));
      myDescriptions.put(type.getExternalName(), (MyColorAndFontDescription)description);
    }
  }
  ScrollingUtil.ensureSelectionExists(myOptionsList);
}
 
Example 3
Source File: DiffOptionsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Set<String> processListOptions() {
  Set<String> result = ContainerUtil.newHashSet();
  Map<TextAttributesKey, TextDiffType> typesByKey = ContainerUtil.newMapFromValues(TextDiffType.MERGE_TYPES.iterator(),
                                                                                   TextDiffType.ATTRIBUTES_KEY);
  for (int i = 0; i < myOptions.getCurrentDescriptions().length; i++) {
    EditorSchemeAttributeDescriptor description = myOptions.getCurrentDescriptions()[i];
    TextAttributesKey type = TextAttributesKey.find(description.getType());
    if (description.getGroup() == ColorAndFontOptions.DIFF_GROUP &&
        typesByKey.keySet().contains(type)) {
      result.add(type.getExternalName());
    }
  }

  return result;
}
 
Example 4
Source File: HaxeColorAnnotator.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement node, @NotNull AnnotationHolder holder) {
  if (isNewOperator(node)) {
    holder.createInfoAnnotation(node, null).setTextAttributes(TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_KEYWORD));
  }

  PsiElement element = node;
  if (element instanceof HaxeStringLiteralExpression) {
    return;
  }
  if (element instanceof HaxeReference) {
    final boolean chain = PsiTreeUtil.getChildOfType(element, HaxeReference.class) != null;
    if (chain) {
      if (tryAnnotateQName(node, holder)) return;
    }
    element = ((HaxeReference)element).resolveToComponentName();
  }
  if (element instanceof HaxeComponentName) {
    final boolean isStatic = PsiTreeUtil.getParentOfType(node, HaxeImportStatement.class) == null && checkStatic(element.getParent());
    final TextAttributesKey attribute = getAttributeByType(HaxeComponentType.typeOf(element.getParent()), isStatic);
    if (attribute != null) {
      if (node instanceof HaxeReference) {
        element = ((HaxeReference)node).getReferenceNameElement();
        if (element != null) node = element;
      }
      holder.createInfoAnnotation(node, null).setTextAttributes(attribute);
    }
  }
  if (isKeyword(element)) {
    TextAttributesKey attributesKey = TextAttributesKey.find(HaxeSyntaxHighlighterColors.HAXE_KEYWORD);
    holder.createInfoAnnotation(node, null).setTextAttributes(attributesKey);
  }

  final ASTNode astNode = node.getNode();
  if (astNode != null) {
    IElementType tt = astNode.getElementType();

    if (tt == HaxeTokenTypeSets.PPEXPRESSION) {
      //annotateCompilationExpression(node, holder);
      //FIXME Temporary override:
      holder.createInfoAnnotation(node, null).setTextAttributes(HaxeSyntaxHighlighterColors.DEFINED_VAR);
    }
    if (tt == HaxeTokenTypeSets.PPBODY) {
      holder.createInfoAnnotation(node, null).setTextAttributes(HaxeSyntaxHighlighterColors.CONDITIONALLY_NOT_COMPILED);
    }
  }
}
 
Example 5
Source File: ScopeAttributesUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static TextAttributesKey getScopeTextAttributeKey(@Nonnull String scope) {
  return TextAttributesKey.find("SCOPE_KEY_" + scope);
}