com.intellij.lang.annotation.Annotation Java Examples
The following examples show how to use
com.intellij.lang.annotation.Annotation.
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: BuckAnnotator.java From buck with Apache License 2.0 | 6 votes |
/** Annotates targets that refer to files relative to this file. */ private boolean annotateStringAsLocalFile( BuckSimpleExpression targetExpression, String targetValue, AnnotationHolder annotationHolder) { Optional<VirtualFile> targetFile = Optional.of(targetExpression) .map(PsiElement::getContainingFile) .map(PsiFile::getVirtualFile) .map(VirtualFile::getParent) .map(dir -> dir.findFileByRelativePath(targetValue)) .filter(VirtualFile::exists); if (!targetFile.isPresent()) { return false; } Annotation annotation = annotationHolder.createInfoAnnotation(targetExpression, targetFile.get().getPath()); annotation.setTextAttributes(BuckSyntaxHighlighter.BUCK_FILE_NAME); return true; }
Example #2
Source File: AnnotatorUtils.java From litho with Apache License 2.0 | 6 votes |
static void addError( AnnotationHolder holder, SpecModelValidationError error, List<IntentionAction> fixes) { PsiElement errorElement = (PsiElement) error.element; Annotation errorAnnotation = holder.createErrorAnnotation( Optional.of(errorElement) .filter(element -> element instanceof PsiClass || element instanceof PsiMethod) .map(PsiNameIdentifierOwner.class::cast) .map(PsiNameIdentifierOwner::getNameIdentifier) .orElse(errorElement), error.message); if (!fixes.isEmpty()) { for (IntentionAction fix : fixes) { errorAnnotation.registerFix(fix); } } }
Example #3
Source File: LSPAnnotator.java From lsp4intellij with Apache License 2.0 | 6 votes |
private void updateAnnotations(AnnotationHolder holder, EditorEventManager eventManager) { final List<Annotation> annotations = eventManager.getAnnotations(); if (annotations == null) { return; } annotations.forEach(annotation -> { // TODO: Use 'newAnnotation'; 'createAnnotation' is deprecated. Annotation anon = holder.createAnnotation(annotation.getSeverity(), new TextRange(annotation.getStartOffset(), annotation.getEndOffset()), annotation.getMessage()); if (annotation.getQuickFixes() == null || annotation.getQuickFixes().isEmpty()) { return; } annotation.getQuickFixes().forEach(quickFixInfo -> anon.registerFix(quickFixInfo.quickFix)); }); }
Example #4
Source File: LSPAnnotator.java From lsp4intellij with Apache License 2.0 | 6 votes |
@Nullable protected Annotation createAnnotation(Editor editor, AnnotationHolder holder, Diagnostic diagnostic) { final int start = DocumentUtils.LSPPosToOffset(editor, diagnostic.getRange().getStart()); final int end = DocumentUtils.LSPPosToOffset(editor, diagnostic.getRange().getEnd()); if (start >= end) { return null; } final TextRange textRange = new TextRange(start, end); switch (diagnostic.getSeverity()) { // TODO: Use 'newAnnotation'; 'create*Annotation' methods are deprecated. case Error: return holder.createErrorAnnotation(textRange, diagnostic.getMessage()); case Warning: return holder.createWarningAnnotation(textRange, diagnostic.getMessage()); case Information: return holder.createInfoAnnotation(textRange, diagnostic.getMessage()); default: return holder.createWeakWarningAnnotation(textRange, diagnostic.getMessage()); } }
Example #5
Source File: RedefinedTokenAnnotation.java From glsl4idea with GNU Lesser General Public License v3.0 | 6 votes |
@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 #6
Source File: HighlightInfo.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull static HighlightInfo fromAnnotation(@Nonnull Annotation annotation, boolean batchMode) { TextAttributes forcedAttributes = annotation.getEnforcedTextAttributes(); TextAttributesKey key = annotation.getTextAttributes(); TextAttributesKey forcedAttributesKey = forcedAttributes == null && key != HighlighterColors.NO_HIGHLIGHTING ? key : null; HighlightInfo info = new HighlightInfo(forcedAttributes, forcedAttributesKey, convertType(annotation), annotation.getStartOffset(), annotation.getEndOffset(), annotation.getMessage(), annotation.getTooltip(), annotation.getSeverity(), annotation.isAfterEndOfLine(), annotation.needsUpdateOnTyping(), annotation.isFileLevelAnnotation(), 0, annotation.getProblemGroup(), null, annotation.getGutterIconRenderer()); List<? extends Annotation.QuickFixInfo> fixes = batchMode ? annotation.getBatchFixes() : annotation.getQuickFixes(); if (fixes != null) { for (Annotation.QuickFixInfo quickFixInfo : fixes) { TextRange range = quickFixInfo.textRange; HighlightDisplayKey k = quickFixInfo.key != null ? quickFixInfo.key : HighlightDisplayKey.find(ANNOTATOR_INSPECTION_SHORT_NAME); info.registerFix(quickFixInfo.quickFix, null, HighlightDisplayKey.getDisplayNameByKey(k), range, k); } } return info; }
Example #7
Source File: BashAnnotator.java From BashSupport with Apache License 2.0 | 6 votes |
private void annotateWord(PsiElement bashWord, AnnotationHolder annotationHolder) { //we have to mark the remapped tokens (which are words now) to have the default word formatting. PsiElement child = bashWord.getFirstChild(); while (child != null && false) { if (!noWordHighlightErase.contains(child.getNode().getElementType())) { Annotation annotation = annotationHolder.createInfoAnnotation(child, null); annotation.setEnforcedTextAttributes(TextAttributes.ERASE_MARKER); annotation = annotationHolder.createInfoAnnotation(child, null); annotation.setEnforcedTextAttributes(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(HighlighterColors.TEXT)); } child = child.getNextSibling(); } }
Example #8
Source File: DefaultHighlightVisitor.java From consulo with Apache License 2.0 | 6 votes |
@Override public void visit(@Nonnull PsiElement element) { if (element instanceof PsiErrorElement) { if (myHighlightErrorElements) visitErrorElement((PsiErrorElement)element); } else { if (myRunAnnotators) runAnnotators(element); } if (myAnnotationHolder.hasAnnotations()) { for (Annotation annotation : myAnnotationHolder) { myHolder.add(HighlightInfo.fromAnnotation(annotation, myBatchMode)); } myAnnotationHolder.clear(); } }
Example #9
Source File: InflateViewAnnotator.java From idea-android-studio-plugin with GNU General Public License v2.0 | 6 votes |
@Override public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) { InflateContainer inflateContainer = matchInflate(psiElement); if(inflateContainer == null) { return; } Annotation inflateLocal = annotationHolder.createWeakWarningAnnotation(psiElement, null); inflateLocal.setHighlightType(null); inflateLocal.registerFix(new InflateLocalVariableAction(inflateContainer.getPsiLocalVariable(), inflateContainer.getXmlFile())); Annotation inflateThis = annotationHolder.createWeakWarningAnnotation(psiElement, null); inflateThis.setHighlightType(null); inflateThis.registerFix(new InflateThisExpressionAction(inflateContainer.getPsiLocalVariable(), inflateContainer.getXmlFile())); }
Example #10
Source File: LatteAnnotator.java From intellij-latte with MIT License | 6 votes |
private void checkNetteAttr(@NotNull LatteNetteAttr element, @NotNull AnnotationHolder holder) { PsiElement attrName = element.getAttrName(); String tagName = attrName.getText(); boolean prefixed = false; if (tagName.startsWith("n:inner-")) { prefixed = true; tagName = tagName.substring(8); } else if (tagName.startsWith("n:tag-")) { prefixed = true; tagName = tagName.substring(6); } else { tagName = tagName.substring(2); } Project project = element.getProject(); LatteTagSettings macro = LatteConfiguration.getInstance(project).getTag(tagName); if (macro == null || macro.getType() == LatteTagSettings.Type.UNPAIRED) { Annotation annotation = holder.createErrorAnnotation(attrName, "Unknown attribute tag " + attrName.getText()); annotation.registerFix(new AddCustomPairMacro(tagName)); if (!prefixed) annotation.registerFix(new AddCustomAttrOnlyMacro(tagName)); } else if (prefixed && macro.getType() != LatteTagSettings.Type.PAIR && macro.getType() != LatteTagSettings.Type.AUTO_EMPTY) { holder.createErrorAnnotation(attrName, "Attribute tag n:" + tagName + " can not be used with prefix."); } }
Example #11
Source File: SQFControlStructureCommandAnnotator.java From arma-intellij-plugin with MIT License | 6 votes |
@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 #12
Source File: GraphQLValidationAnnotator.java From js-graphql-intellij-plugin with MIT License | 6 votes |
private Optional<Annotation> createErrorAnnotation(@NotNull AnnotationHolder annotationHolder, PsiElement errorPsiElement, String message) { if (GraphQLRelayModernAnnotationFilter.getService(errorPsiElement.getProject()).errorIsIgnored(errorPsiElement)) { return Optional.empty(); } // error locations from graphql-java will give us the beginning of a type definition including the description final GraphQLQuotedString quotedString = PsiTreeUtil.getParentOfType(errorPsiElement, GraphQLQuotedString.class); if (quotedString != null) { // check if this is the description final GraphQLDescriptionAware descriptionAware = PsiTreeUtil.getParentOfType(quotedString, GraphQLDescriptionAware.class); if (descriptionAware != null && descriptionAware.getDescription() == quotedString) { final GraphQLIdentifier describedName = PsiTreeUtil.findChildOfType(descriptionAware, GraphQLIdentifier.class); if (describedName != null) { // highlight the identifier (e.g. type name) that has the error instead errorPsiElement = describedName; } } } return Optional.of(annotationHolder.createErrorAnnotation(errorPsiElement, message)); }
Example #13
Source File: ShopwareLightCodeInsightFixtureTestCase.java From idea-php-shopware-plugin with MIT License | 5 votes |
public void assertAnnotationNotContains(String filename, String content, String contains) { for (Annotation annotation : getAnnotationsAtCaret(filename, content)) { if(annotation.getMessage().contains(contains)) { fail(String.format("Fail not matching '%s' with '%s'", contains, annotation)); } } }
Example #14
Source File: BashAnnotator.java From BashSupport with Apache License 2.0 | 5 votes |
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 #15
Source File: UnusedRefAnnotator.java From intellij-swagger with MIT License | 5 votes |
private void warn( final PsiElement psiElement, final AnnotationHolder annotationHolder, final PsiElement searchableCurrentElement, final String warning) { final PsiReference first = ReferencesSearch.search(searchableCurrentElement).findFirst(); if (first == null) { Annotation annotation = annotationHolder.createWeakWarningAnnotation(psiElement, warning); annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL); } }
Example #16
Source File: BaseAnnotator.java From Custom-Syntax-Highlighter with MIT License | 5 votes |
@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 #17
Source File: BuckAnnotator.java From buck with Apache License 2.0 | 5 votes |
/** Colorize named arguments in function invocations. */ private void annotateBuckArgument(BuckArgument argument, AnnotationHolder annotationHolder) { Optional.ofNullable(argument.getIdentifier()) .ifPresent( identifier -> { Annotation annotation = annotationHolder.createInfoAnnotation(identifier, null); annotation.setTextAttributes(BuckSyntaxHighlighter.BUCK_PROPERTY_LVALUE); }); }
Example #18
Source File: HaxeExpressionEvaluatorContext.java From intellij-haxe with Apache License 2.0 | 5 votes |
@NotNull public Annotation addWarning(PsiElement element, String error, HaxeFixer... fixers) { if (holder == null) return createDummyAnnotation(); Annotation annotation = holder.createWarningAnnotation(element, error); for (HaxeFixer fixer : fixers) { annotation.registerFix(fixer); } return annotation; }
Example #19
Source File: SQFMagicVarColorizerAnnotator.java From arma-intellij-plugin with MIT License | 5 votes |
@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 #20
Source File: WebReferencesAnnotatorBase.java From consulo with Apache License 2.0 | 5 votes |
@Override public void apply(@Nonnull PsiFile file, MyInfo[] infos, @Nonnull AnnotationHolder holder) { if (infos.length == 0) { return; } final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file); for (MyInfo info : infos) { if (!info.myResult) { final PsiElement element = info.myAnchor.retrieve(); if (element != null) { final int start = element.getTextRange().getStartOffset(); final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset()); final String message = getErrorMessage(info.myUrl); final Annotation annotation; if (displayLevel == HighlightDisplayLevel.ERROR) { annotation = holder.createErrorAnnotation(range, message); } else if (displayLevel == HighlightDisplayLevel.WARNING) { annotation = holder.createWarningAnnotation(range, message); } else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) { annotation = holder.createInfoAnnotation(range, message); } else { annotation = holder.createWarningAnnotation(range, message); } for (IntentionAction action : getQuickFixes()) { annotation.registerFix(action); } } } } }
Example #21
Source File: ProtoErrorsAnnotator.java From protobuf-jetbrains-plugin with Apache License 2.0 | 5 votes |
private void markError(ASTNode parent, @Nullable ASTNode node, String message) { Annotation annotation; if (node == null) { annotation = holder.createErrorAnnotation(parent, message); } else { annotation = holder.createErrorAnnotation(node, message); } annotation.setHighlightType(ProblemHighlightType.GENERIC_ERROR); }
Example #22
Source File: DocumentationUtil.java From arma-intellij-plugin with MIT License | 5 votes |
/** * 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 #23
Source File: SassLintExternalAnnotator.java From sass-lint-plugin with MIT License | 5 votes |
@Override public void apply(@NotNull PsiFile file, ExternalLintAnnotationResult<LintResult> annotationResult, @NotNull AnnotationHolder holder) { if (annotationResult == null) { return; } InspectionProjectProfileManager inspectionProjectProfileManager = InspectionProjectProfileManager.getInstance(file.getProject()); SeverityRegistrar severityRegistrar = inspectionProjectProfileManager.getSeverityRegistrar(); // HighlightDisplayKey inspectionKey = getHighlightDisplayKeyByClass(); // HighlightSeverity severity = InspectionUtil.getSeverity(inspectionProjectProfileManager, inspectionKey, file); EditorColorsScheme colorsScheme = annotationResult.input.colorsScheme; Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document == null) { return; } SassLintProjectComponent component = annotationResult.input.project.getComponent(SassLintProjectComponent.class); for (SassLint.Issue warn : annotationResult.result.sassLint.file.errors) { HighlightSeverity severity = getHighlightSeverity(warn, component.treatAsWarnings); TextAttributes forcedTextAttributes = InspectionUtil.getTextAttributes(colorsScheme, severityRegistrar, severity); Annotation annotation = createAnnotation(holder, file, document, warn, severity, forcedTextAttributes, false); // if (annotation != null) { // int offset = StringUtil.lineColToOffset(document.getText(), warn.line - 1, warn.column); // PsiElement lit = PsiUtil.getElementAtOffset(file, offset); // BaseActionFix actionFix = Fixes.getFixForRule(warn.rule, lit); // if (actionFix != null) { // annotation.registerFix(actionFix, null, inspectionKey); // } // annotation.registerFix(new SuppressActionFix(warn.rule, lit), null, inspectionKey); // } } }
Example #24
Source File: HighlightingAnnotator.java From intellij with Apache License 2.0 | 5 votes |
@Override public void visitParameter(Parameter node) { FunctionStatement function = PsiTreeUtil.getParentOfType(node, FunctionStatement.class); if (function != null) { PsiElement anchor = node.hasDefaultValue() ? node.getFirstChild() : node; final Annotation annotation = getHolder().createInfoAnnotation(anchor, null); annotation.setTextAttributes(BuildSyntaxHighlighter.BUILD_PARAMETER); } }
Example #25
Source File: ANTLRv4ExternalAnnotatorTest.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void shouldRegisterCreateRuleQuickFix() { // given: Annotation annotation = new Annotation(0,0, HighlightSeverity.WARNING, "msg", "tooltip"); PsiFile file = Mockito.mock(PsiFile.class); Mockito.when(file.getText()).thenReturn("sample text"); // when: ANTLRv4ExternalAnnotator.registerFixForAnnotation(annotation, new GrammarIssue(new ANTLRMessage(ErrorType.UNDEFINED_RULE_REF)), file); // then: Annotation.QuickFixInfo quickFix = Iterables.getOnlyElement(annotation.getQuickFixes()); Assert.assertTrue(quickFix.quickFix instanceof CreateRuleFix); }
Example #26
Source File: HighlightingAnnotator.java From intellij with Apache License 2.0 | 5 votes |
@Override public void visitFunctionStatement(FunctionStatement node) { ASTNode nameNode = node.getNameNode(); if (nameNode != null) { Annotation annotation = getHolder().createInfoAnnotation(nameNode, null); annotation.setTextAttributes(BuildSyntaxHighlighter.BUILD_FN_DEFINITION); } }
Example #27
Source File: SymfonyLightCodeInsightFixtureTestCase.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public void assertAnnotationNotContains(String filename, String content, String contains) { for (Annotation annotation : getAnnotationsAtCaret(filename, content)) { if(annotation.getMessage().contains(contains)) { fail(String.format("Fail not matching '%s' with '%s'", contains, annotation)); } } }
Example #28
Source File: DrupalLightCodeInsightFixtureTestCase.java From idea-php-drupal-symfony2-bridge with MIT License | 5 votes |
public void assertAnnotationContains(String filename, String content, String contains) { List<String> matches = new ArrayList<String>(); for (Annotation annotation : getAnnotationsAtCaret(filename, content)) { matches.add(annotation.toString()); if(annotation.getMessage().contains(contains)) { return; } } fail(String.format("Fail matches '%s' with one of %s", contains, matches)); }
Example #29
Source File: LoadStatementAnnotatorTest.java From intellij with Apache License 2.0 | 5 votes |
private void assertHasAnnotation(BuildFile file, String message, HighlightSeverity type) { assertThat( validateFile(file) .stream() .filter(ann -> ann.getSeverity().equals(type)) .map(Annotation::getMessage) .collect(Collectors.toList())) .contains(message); }
Example #30
Source File: FlutterEditorAnnotator.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void attachIcon(final PsiElement element, AnnotationHolder holder, Icon icon) { try { final Annotation annotation = holder.createInfoAnnotation(element, null); annotation.setGutterIconRenderer(new FlutterIconRenderer(icon, element)); } catch (Exception ignored) { } }