Java Code Examples for com.intellij.lang.annotation.Annotation#setTextAttributes()

The following examples show how to use com.intellij.lang.annotation.Annotation#setTextAttributes() . 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: SQFControlStructureCommandAnnotator.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
	if (!(element instanceof SQFCommand)) {
		return;
	}
	SQFCommand command = (SQFCommand) element;
	switch (command.getCommandName().toLowerCase()) {
		case "if": //fall
		case "then": //fall
		case "else": //fall
		case "for": //fall
		case "foreach": //fall
		case "switch": //fall
		case "case": //fall
		case "default": //fall
		case "while"://fall
		case "do": {
			Annotation annotation = holder.createInfoAnnotation(command, "");
			annotation.setTextAttributes(SQFSyntaxHighlighter.CONTROL_STRUCTURE_COMMAND);
			break;
		}
	}
}
 
Example 2
Source File: RedefinedTokenAnnotation.java    From glsl4idea with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void annotate(GLSLRedefinedToken identifier, AnnotationHolder holder) {
    String definition;

    final IElementType identifierType = identifier.getNode().getElementType();
    if(identifierType instanceof GLSLElementTypes.RedefinedTokenElementType){
        definition = ((GLSLElementTypes.RedefinedTokenElementType) identifierType).text;
    }else{
        GLSLMacroReference reference = identifier.getReference();
        GLSLDefineDirective referent = (reference != null) ? reference.resolve() : null;
        definition = (referent != null) ? referent.getBoundText() : null;
    }

    Annotation annotation = holder.createInfoAnnotation(identifier, definition);
    annotation.setTextAttributes(GLSLHighlighter.GLSL_REDEFINED_TOKEN[0]);
}
 
Example 3
Source File: SQFControlStructureCommandAnnotator.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
	if (!(element instanceof SQFCommand)) {
		return;
	}
	SQFCommand command = (SQFCommand) element;
	switch (command.getCommandName().toLowerCase()) {
		case "if": //fall
		case "then": //fall
		case "else": //fall
		case "for": //fall
		case "foreach": //fall
		case "switch": //fall
		case "case": //fall
		case "default": //fall
		case "while"://fall
		case "do": {
			Annotation annotation = holder.createInfoAnnotation(command, "");
			annotation.setTextAttributes(SQFSyntaxHighlighter.CONTROL_STRUCTURE_COMMAND);
			break;
		}
	}
}
 
Example 4
Source File: BashAnnotator.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private void highlightKeywordTokens(@NotNull PsiElement element, @NotNull AnnotationHolder annotationHolder) {
    ASTNode node = element.getNode();
    if (node == null) {
        return;
    }

    IElementType elementType = node.getElementType();
    boolean isKeyword = elementType == BashTokenTypes.IN_KEYWORD_REMAPPED
            || elementType == BashTokenTypes.WORD && "!".equals(element.getText());

    if (isKeyword) {
        Annotation annotation = annotationHolder.createInfoAnnotation(element, null);
        annotation.setTextAttributes(BashSyntaxHighlighter.KEYWORD);
    }
}
 
Example 5
Source File: HaxeExpressionEvaluatorContext.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@NotNull
public Annotation addUnreachable(PsiElement element) {
  if (holder == null) return createDummyAnnotation();
  Annotation annotation = holder.createInfoAnnotation(element, null);
  annotation.setTextAttributes(HaxeSyntaxHighlighterColors.LINE_COMMENT);
  return annotation;
}
 
Example 6
Source File: VariableHighlightAnnotator.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  if (element instanceof SoyVariableReferenceIdentifier
      || element instanceof SoyVariableDefinitionIdentifier
      || element instanceof SoyParamDefinitionIdentifier) {
    Annotation annotation = holder.createInfoAnnotation(element, null);
    annotation.setTextAttributes(SoySyntaxHighlighter.VARIABLE);
  }
}
 
Example 7
Source File: SQFMagicVarColorizerAnnotator.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
	if (element instanceof SQFVariable) {
		SQFVariable var = (SQFVariable) element;
		if (var.isMagicVar()) {
			Annotation a = holder.createInfoAnnotation(TextRange.from(element.getTextOffset(), var.getTextLength()), null);
			a.setTextAttributes(SQFSyntaxHighlighter.MAGIC_VAR);
		}
	}
}
 
Example 8
Source File: SQFMagicVarColorizerAnnotator.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
	if (element instanceof SQFVariable) {
		SQFVariable var = (SQFVariable) element;
		if (var.isMagicVar()) {
			Annotation a = holder.createInfoAnnotation(TextRange.from(element.getTextOffset(), var.getTextLength()), null);
			a.setTextAttributes(SQFSyntaxHighlighter.MAGIC_VAR);
		}
	}
}
 
Example 9
Source File: PreprocessorColorizerAnnotator.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
	String elementText = element.getText();
	if (elementText.length() >= 1 && elementText.charAt(0) == '#') {
		int macroNameEnd = elementText.indexOf(' ');
		Annotation a = holder.createInfoAnnotation(TextRange.from(element.getTextOffset(), macroNameEnd < 0 ? elementText.length() : macroNameEnd), null);
		a.setTextAttributes(HeaderSyntaxHighlighter.PREPROCESSOR);
	}
}
 
Example 10
Source File: BashAnnotator.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private void annotateCommand(BashCommand bashCommand, AnnotationHolder annotationHolder) {
    PsiElement cmdElement = null;
    TextAttributesKey attributesKey = null;

    //if the command consists of a single variable then it should not be highlighted
    //otherwise the variable would be shown without its own variable highlighting
    if (BashPsiUtils.isSingleChildParent(bashCommand, BashTokenTypes.VARIABLE)) {
        return;
    }

    if (BashPsiUtils.isSingleChildParent(bashCommand, BashString.class)) {
        return;
    }

    if (BashPsiUtils.isSingleChildParent(bashCommand, BashBackquote.class)) {
        return;
    }

    if (BashPsiUtils.isSingleChildParent(bashCommand, BashSubshellCommand.class)) {
        return;
    }

    if (bashCommand.isFunctionCall()) {
        cmdElement = bashCommand.commandElement();
        attributesKey = BashSyntaxHighlighter.FUNCTION_CALL;
    } else if (bashCommand.isExternalCommand()) {
        cmdElement = bashCommand.commandElement();
        attributesKey = BashSyntaxHighlighter.EXTERNAL_COMMAND;
    } else if (bashCommand.isInternalCommand()) {
        cmdElement = bashCommand.commandElement();
        attributesKey = BashSyntaxHighlighter.INTERNAL_COMMAND;
    }

    if (cmdElement != null && attributesKey != null) {
        final Annotation annotation = annotationHolder.createInfoAnnotation(cmdElement, null);
        annotation.setTextAttributes(attributesKey);
    }
}
 
Example 11
Source File: BaseAnnotator.java    From Custom-Syntax-Highlighter with MIT License 5 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) {

  if (element instanceof LeafPsiElement) {
    final TextAttributesKey kind = getKeywordKind(element);
    if (kind == null) {
      return;
    }
    final TextRange textRange = element.getTextRange();
    final TextRange range = new TextRange(textRange.getStartOffset(), textRange.getEndOffset());
    final Annotation annotation = holder.createAnnotation(HighlightSeverity.INFORMATION, range, null);

    annotation.setTextAttributes(kind);
  }
}
 
Example 12
Source File: BashAnnotator.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private void annotateHereDoc(BashHereDoc element, AnnotationHolder annotationHolder) {
    final Annotation annotation = annotationHolder.createInfoAnnotation(element, null);
    annotation.setTextAttributes(BashSyntaxHighlighter.HERE_DOC);
    annotation.setNeedsUpdateOnTyping(false);

    if (element.isEvaluatingVariables()) {
        highlightVariables(element, annotationHolder);
    }
}
 
Example 13
Source File: HighlightingAnnotator.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void visitReferenceExpression(ReferenceExpression node) {
  ASTNode nameNode = node.getNameElement();
  if (nameNode != null
      && BuiltInNamesProvider.getBuiltInNames(node.getProject()).contains(nameNode.getText())) {
    Annotation annotation = getHolder().createInfoAnnotation(nameNode, null);
    annotation.setTextAttributes(BuildSyntaxHighlighter.BUILD_BUILTIN_NAME);
  }
  super.visitReferenceExpression(node);
}
 
Example 14
Source File: DocumentationUtil.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
/**
 * Annotates the given comment so that tags like @command, @bis, and @fnc (Arma Intellij Plugin specific tags) are properly annotated
 *
 * @param annotator the annotator
 * @param comment   the comment
 */
public static void annotateDocumentationWithArmaPluginTags(@NotNull AnnotationHolder annotator, @NotNull PsiComment comment) {
	List<String> allowedTags = new ArrayList<>(3);
	allowedTags.add("command");
	allowedTags.add("bis");
	allowedTags.add("fnc");
	Pattern patternTag = Pattern.compile("@([a-zA-Z]+) ([a-zA-Z_0-9]+)");
	Matcher matcher = patternTag.matcher(comment.getText());
	String tag;
	Annotation annotation;
	int startTag, endTag, startArg, endArg;
	while (matcher.find()) {
		if (matcher.groupCount() < 2) {
			continue;
		}
		tag = matcher.group(1);
		if (!allowedTags.contains(tag)) {
			continue;
		}
		startTag = matcher.start(1);
		endTag = matcher.end(1);
		startArg = matcher.start(2);
		endArg = matcher.end(2);
		annotation = annotator.createAnnotation(HighlightSeverity.INFORMATION, TextRange.create(comment.getTextOffset() + startTag - 1, comment.getTextOffset() + endTag), null);
		annotation.setTextAttributes(DefaultLanguageHighlighterColors.DOC_COMMENT_TAG);
		annotation = annotator.createAnnotation(HighlightSeverity.INFORMATION, TextRange.create(comment.getTextOffset() + startArg, comment.getTextOffset() + endArg), null);
		annotation.setTextAttributes(DefaultLanguageHighlighterColors.DOC_COMMENT_TAG_VALUE);
	}
}
 
Example 15
Source File: BashAnnotator.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
private void annotateFunctionDef(BashFunctionDefName functionName, AnnotationHolder annotationHolder) {
    Annotation annotation = annotationHolder.createInfoAnnotation(functionName, null);
    annotation.setTextAttributes(BashSyntaxHighlighter.FUNCTION_DEF_NAME);
}
 
Example 16
Source File: JSGraphQLEndpointDocHighlightAnnotator.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private void setTextAttributes(PsiElement element, AnnotationHolder holder, TextAttributesKey key) {
	final Annotation annotation = holder.createInfoAnnotation(element, null);
	annotation.setTextAttributes(key);
}
 
Example 17
Source File: JSGraphQLEndpointHighlightAnnotator.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private void setTextAttributes(PsiElement element, AnnotationHolder holder, TextAttributesKey key) {
	final Annotation annotation = holder.createInfoAnnotation(element, null);
	annotation.setTextAttributes(key);
}
 
Example 18
Source File: BashAnnotator.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
private void annotateRedirectExpression(BashRedirectExpr element, AnnotationHolder annotationHolder) {
    Annotation annotation = annotationHolder.createInfoAnnotation(element, null);
    annotation.setTextAttributes(BashSyntaxHighlighter.REDIRECTION);
}
 
Example 19
Source File: NASMAnnotator.java    From JetBrains-NASM-Language with MIT License 4 votes vote down vote up
private void highlightTextRange(TextRange range, @NotNull TextAttributesKey textAttributes, @NotNull AnnotationHolder holder) {
    Annotation annotation = holder.createInfoAnnotation(range, null);
    annotation.setTextAttributes(textAttributes);
}
 
Example 20
Source File: NASMAnnotator.java    From JetBrains-NASM-Language with MIT License 4 votes vote down vote up
private void highlightTextRange(int startOffset, int length, @NotNull TextAttributesKey textAttributes, @NotNull AnnotationHolder holder) {
    TextRange range = new TextRange(startOffset, startOffset + length);
    Annotation annotation = holder.createInfoAnnotation(range, null);
    annotation.setTextAttributes(textAttributes);
}