private void annotateNumber(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { Annotation annotation = holder.createInfoAnnotation(element, null); annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.NUMBER); } }
private void highlightTypeError(@NotNull PsiElement element, @NotNull String message, @NotNull AnnotationHolder annotationHolder) { annotationHolder.createErrorAnnotation(element, message); }
@Override public void apply(@NotNull PsiFile file, @NotNull List<Issue> issueList, @NotNull AnnotationHolder holder) { if (issueList.size() > 0) { @Nullable Document document = file.getViewProvider().getDocument(); if (document != null) { String workingDirectory = ensureWorkingDirectory(file.getProject()); for (Issue issue : issueList) { int lineStartOffset = document.getLineStartOffset(issue.line); int start; int end; if (issue.column != null) { start = lineStartOffset + issue.column; end = start + 1; } else { start = lineStartOffset; end = document.getLineEndOffset(issue.line); } Annotation annotation = holder.createWarningAnnotation(new TextRange(start, end), issue.message); annotation.setAfterEndOfLine(end == start); issue.explanation.ifPresent(explanation -> { String toolTip = explanationToToolTip(explanation, workingDirectory); if (!toolTip.isEmpty()) { annotation.setTooltip(toolTip); } }); } } } }
@Override public void annotate(@NotNull PsiElement psiElement, @NotNull com.intellij.lang.annotation.AnnotationHolder annotationHolder) { if (psiElement instanceof ErlangAtom) { ErlangAtom erlangAtom = (ErlangAtom) psiElement; String name = erlangAtom.getName(); if (name.startsWith(ELIXIR_ALIAS_PREFIX)) { Project project = psiElement.getProject(); Collection<NamedElement> namedElementCollection = StubIndex.getElements( ModularName.KEY, name, project, GlobalSearchScope.allScope(project), NamedElement.class ); if (namedElementCollection.size() > 0) { TextRange textRange = psiElement.getTextRange(); String unprefixedName = name.substring(ELIXIR_ALIAS_PREFIX.length(), name.length()); Annotation annotation = annotationHolder.createInfoAnnotation(textRange, "Resolves to Elixir Module " + unprefixedName); annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT); } else { TextRange textRange = psiElement.getTextRange(); annotationHolder.createErrorAnnotation(textRange, "Unresolved Elixir Module"); } } } } }
private static Annotation createAnnotation( AnnotationHolder holder, String message, TextRange textRange, HighlightSeverity severity ) { if (HighlightSeverity.ERROR.equals(severity)) { return holder.createErrorAnnotation(textRange,message); } else if (HighlightSeverity.WEAK_WARNING.equals(severity)) { return holder.createWeakWarningAnnotation(textRange,message); } else if (HighlightSeverity.WARNING.equals(severity)) { return holder.createWarningAnnotation(textRange,message); } else { throw new IllegalArgumentException("Unhandled severity "+severity); } }
PsiElement parent = element.getParent(); if (parent instanceof JFlexMacroDefinition && element == ((JFlexMacroDefinition)parent).getNameIdentifier()) { holder.createInfoAnnotation(element, null).setTextAttributes(JFlexSyntaxHighlighterFactory.MACRO); holder.createInfoAnnotation(element, null).setTextAttributes(JFlexSyntaxHighlighterFactory.MACRO); if (resolve == null) { holder.createWarningAnnotation(element, "Unresolved macro reference"); holder.createInfoAnnotation(((JFlexStateDefinition)element).getNameIdentifier(), null).setTextAttributes(JFlexSyntaxHighlighterFactory.STATE); PsiReference reference = isYYINITIAL ? null : element.getReference(); PsiElement resolve = reference == null ? null : reference.resolve(); holder.createInfoAnnotation(element, null).setTextAttributes(JFlexSyntaxHighlighterFactory.STATE); if (!isYYINITIAL && resolve == null) { holder.createWarningAnnotation(element, "Unresolved state reference"); holder.createInfoAnnotation(element, null).setTextAttributes(JFlexSyntaxHighlighterFactory.CLASS); holder.createInfoAnnotation(element, null).setTextAttributes(JFlexSyntaxHighlighterFactory.RAW_CODE);
holder.createWeakWarningAnnotation( atomKeyword, "Will make documented invisible to the documentation extraction tools like ExDoc.");
protected boolean handleSeparatorElement(@NotNull PsiElement element, @NotNull AnnotationHolder holder, IElementType elementType, CsvFile csvFile) { if (elementType == CsvTypes.COMMA) { TextAttributes textAttributes = holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY); if (!Boolean.TRUE.equals(holder.getCurrentAnnotationSession().getUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY))) { String separator = CsvCodeStyleSettings.getCurrentSeparator(csvFile.getProject(), csvFile.getLanguage()); if (CsvEditorSettingsExternalizable.getInstance().isHighlightTabSeparator() && separator.equals(CsvCodeStyleSettings.TAB_SEPARATOR)) { textAttributes = new TextAttributes(null, CsvEditorSettingsExternalizable.getInstance().getTabHighlightColor(), null, null, 0); holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_KEY, textAttributes); holder.getCurrentAnnotationSession().putUserData(TAB_SEPARATOR_HIGHLIGHT_COLOR_DETERMINED_KEY, Boolean.TRUE); } } if (textAttributes != null) { Annotation annotation = holder.createAnnotation( CSV_COLUMN_INFO_SEVERITY, element.getTextRange(), showInfoBalloon(holder.getCurrentAnnotationSession()) ? "↹" : null ); annotation.setEnforcedTextAttributes(textAttributes); annotation.setNeedsUpdateOnTyping(false); } return true; } return false; }
holder.createAnnotation(HighlightSeverity.WARNING, warningRange, descriptor.getMessage());
private static Annotation createAnnotation( AnnotationHolder holder, String message, PsiElement location, HighlightSeverity severity ) { if (HighlightSeverity.ERROR.equals(severity)) { return holder.createErrorAnnotation(location.getTextRange(),message); } else if (HighlightSeverity.WEAK_WARNING.equals(severity)) { return holder.createWeakWarningAnnotation(location.getTextRange(),message); } else if (HighlightSeverity.WARNING.equals(severity)) { return holder.createWarningAnnotation(location.getTextRange(),message); } else { throw new IllegalArgumentException("Unhandled severity "+severity); } }
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); } } }
String message = XmlStringUtil.escapeString(headerElement == null ? "" : headerElement.getText(), true); String tooltip = null; if (showInfoBalloon(holder.getCurrentAnnotationSession())) { tooltip = XmlStringUtil.wrapInHtml( String.format("%s<br /><br />Header: %s<br />Index: %d", Annotation annotation = holder.createAnnotation(CSV_COLUMN_INFO_SEVERITY, textRange, message, tooltip); annotation.setEnforcedTextAttributes( CsvEditorSettingsExternalizable.getInstance().isColumnHighlightingEnabled() ? CsvColorSettings.getTextAttributesOfColumn(columnInfo.getColumnIndex(), holder.getCurrentAnnotationSession()) : null );
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())); }
private void annotateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { Annotation annotation = holder.createInfoAnnotation(element, null); annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.STRING); }
if (baseType instanceof GoArrayOrSliceType) { if (list.isEmpty()) { holder.createErrorAnnotation(call, "Missing len argument to make"); return; holder.createErrorAnnotation(call, "Too many arguments to make"); return; holder.createErrorAnnotation(call, "Too many arguments to make"); return; if (!(isIntegerConvertibleType(expressionBaseType) || isCType(type))) { String argName = i == 0 ? "size" : "capacity"; holder.createErrorAnnotation(expression, "Non-integer " + argName + " argument to make");
case ERROR_ONE_OFF: case FATAL: holder.createErrorAnnotation(range, issue.annotation); break; holder.createWarningAnnotation(range, issue.annotation); break; holder.createWeakWarningAnnotation(range, issue.annotation);
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); } } }
.createWarningAnnotation(firstChild.getTextRange(), "Twig: Missing Template") .registerFix(new TemplateCreateByNameLocalQuickFix(templateName))
private void annotateInlineCode(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { Annotation annotation = holder.createInfoAnnotation(element, null); annotation.setTextAttributes(BallerinaSyntaxHighlightingColors.DOCUMENTATION_INLINE_CODE); }
private static void checkSelfReference(@NotNull GoReferenceExpression o, PsiElement definition, AnnotationHolder holder) { GoExpression value = null; if (definition instanceof GoVarDefinition) { value = ((GoVarDefinition)definition).getValue(); } else if (definition instanceof GoConstDefinition) { value = ((GoConstDefinition)definition).getValue(); } if (value != null && value.equals(GoPsiImplUtil.getNonStrictTopmostParentOfType(o, GoExpression.class))) { holder.createErrorAnnotation(o, "Cyclic definition detected"); } }