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); } } }
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); } } }
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); }
private void addAnnotation(LiveIssue issue, AnnotationHolder annotationHolder) { TextRange textRange; if (issue.getRange() != null) { textRange = createTextRange(issue.getRange()); } else { textRange = issue.psiFile().getTextRange(); } String htmlMsg = getHtmlMessage(issue); Annotation annotation = annotationHolder .createAnnotation(getSeverity(issue.getSeverity()), textRange, issue.getMessage(), htmlMsg); annotation.registerFix(new DisableRuleQuickFix(issue.getRuleKey())); if (!issue.flows().isEmpty()) { annotation.registerFix(new ShowLocationsIntention(issue.getRange(), issue.getMessage(), issue.flows())); } if (issue.getRange() == null) { annotation.setFileLevelAnnotation(true); } else { annotation.setTextAttributes(getTextAttrsKey(issue.getSeverity())); } /* * 3 possible ways to set text attributes and error stripe color: * - enforce text attributes ({@link Annotation#setEnforcedTextAttributes}) and we need to set everything * manually (including error stripe color). This won't be configurable in a standard way and won't change based on used color scheme * - rely on one of the default attributes by giving a key {@link com.intellij.openapi.editor.colors.CodeInsightColors} or your own * key (SonarLintTextAttributes) to Annotation#setTextAttributes * - let Annotation#getTextAttributes decide it based on highlight type and severity. */ annotation.setHighlightType(getType(issue.getSeverity())); }