Search in sources :

Example 81 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class JavaFxAnnotator method attachColorIcon.

private static void attachColorIcon(final PsiElement element, AnnotationHolder holder, String attributeValueText) {
    try {
        Color color = null;
        if (attributeValueText.startsWith("#")) {
            color = ColorUtil.fromHex(attributeValueText.substring(1));
        } else {
            final String hexCode = ColorMap.getHexCodeForColorName(StringUtil.toLowerCase(attributeValueText));
            if (hexCode != null) {
                color = ColorUtil.fromHex(hexCode);
            }
        }
        if (color != null) {
            final ColorIcon icon = JBUI.scale(new ColorIcon(8, color));
            final Annotation annotation = holder.createInfoAnnotation(element, null);
            annotation.setGutterIconRenderer(new ColorIconRenderer(icon, element));
        }
    } catch (Exception ignored) {
    }
}
Also used : ColorIcon(com.intellij.util.ui.ColorIcon) Annotation(com.intellij.lang.annotation.Annotation)

Example 82 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class PropertiesAnnotator method annotate.

public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (!(element instanceof IProperty))
        return;
    final Property property = (Property) element;
    PropertiesFile propertiesFile = property.getPropertiesFile();
    Collection<IProperty> others = propertiesFile.findPropertiesByKey(property.getUnescapedKey());
    ASTNode keyNode = ((PropertyImpl) property).getKeyNode();
    if (others.size() != 1) {
        Annotation annotation = holder.createErrorAnnotation(keyNode, PropertiesBundle.message("duplicate.property.key.error.message"));
        annotation.registerFix(PropertiesQuickFixFactory.getInstance().createRemovePropertyFix(property));
    }
    highlightTokens(property, keyNode, holder, new PropertiesHighlighter());
    ASTNode valueNode = ((PropertyImpl) property).getValueNode();
    if (valueNode != null) {
        highlightTokens(property, valueNode, holder, new PropertiesValueHighlighter());
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PropertyImpl(com.intellij.lang.properties.psi.impl.PropertyImpl) Property(com.intellij.lang.properties.psi.Property) Annotation(com.intellij.lang.annotation.Annotation) PropertiesValueHighlighter(com.intellij.lang.properties.editor.PropertiesValueHighlighter)

Example 83 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class DomHighlightingLiteTest method testDefaultAnnotator.

public void testDefaultAnnotator() throws Throwable {
    final DefaultDomAnnotator annotator = new DefaultDomAnnotator() {

        @Override
        protected DomElementAnnotationsManagerImpl getAnnotationsManager(final DomElement element) {
            return myAnnotationsManager;
        }
    };
    final StringBuilder s = new StringBuilder();
    final ArrayList<Annotation> toFill = new ArrayList<>();
    final MyDomElementsInspection inspection = new MyDomElementsInspection() {

        @Override
        public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
            s.append("visited");
        }
    };
    annotator.runInspection(inspection, myElement, toFill);
    assertEquals("visited", s.toString());
    final DomElementsProblemsHolderImpl holder = assertNotEmptyHolder(myAnnotationsManager.getProblemHolder(myElement));
    assertEmpty(toFill);
    annotator.runInspection(inspection, myElement, toFill);
    assertEquals("visited", s.toString());
    assertSame(holder, assertNotEmptyHolder(myAnnotationsManager.getProblemHolder(myElement)));
    assertEmpty(toFill);
}
Also used : DefaultDomAnnotator(com.intellij.util.xml.impl.DefaultDomAnnotator) ArrayList(java.util.ArrayList) Annotation(com.intellij.lang.annotation.Annotation)

Example 84 with Annotation

use of com.intellij.lang.annotation.Annotation in project kotlin by JetBrains.

the class AndroidLintExternalAnnotator method apply.

@Override
public void apply(@NotNull PsiFile file, State state, @NotNull AnnotationHolder holder) {
    if (state.isDirty()) {
        return;
    }
    final Project project = file.getProject();
    for (ProblemData problemData : state.getProblems()) {
        final Issue issue = problemData.getIssue();
        final String message = problemData.getMessage();
        final TextRange range = problemData.getTextRange();
        if (range.getStartOffset() == range.getEndOffset()) {
            continue;
        }
        final Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(project, issue, file);
        if (pair == null) {
            continue;
        }
        final AndroidLintInspectionBase inspection = pair.getFirst();
        HighlightDisplayLevel displayLevel = pair.getSecond();
        if (inspection != null) {
            final HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
            if (key != null) {
                final PsiElement startElement = file.findElementAt(range.getStartOffset());
                final PsiElement endElement = file.findElementAt(range.getEndOffset() - 1);
                if (startElement != null && endElement != null && !inspection.isSuppressedFor(startElement)) {
                    if (problemData.getConfiguredSeverity() != null) {
                        HighlightDisplayLevel configuredLevel = AndroidLintInspectionBase.toHighlightDisplayLevel(problemData.getConfiguredSeverity());
                        if (configuredLevel != null) {
                            displayLevel = configuredLevel;
                        }
                    }
                    final Annotation annotation = createAnnotation(holder, message, range, displayLevel, issue);
                    for (AndroidLintQuickFix fix : inspection.getQuickFixes(startElement, endElement, message)) {
                        if (fix.isApplicable(startElement, endElement, AndroidQuickfixContexts.EditorContext.TYPE)) {
                            annotation.registerFix(new MyFixingIntention(fix, startElement, endElement));
                        }
                    }
                    for (IntentionAction intention : inspection.getIntentions(startElement, endElement)) {
                        annotation.registerFix(intention);
                    }
                    String id = key.getID();
                    if (IntellijLintIssueRegistry.CUSTOM_ERROR == issue || IntellijLintIssueRegistry.CUSTOM_WARNING == issue) {
                        Issue original = IntellijLintClient.findCustomIssue(message);
                        if (original != null) {
                            id = original.getId();
                        }
                    }
                    annotation.registerFix(new SuppressLintIntentionAction(id, startElement));
                    annotation.registerFix(new MyDisableInspectionFix(key));
                    annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
                    if (INCLUDE_IDEA_SUPPRESS_ACTIONS) {
                        final SuppressQuickFix[] suppressActions = inspection.getBatchSuppressActions(startElement);
                        for (SuppressQuickFix action : suppressActions) {
                            if (action.isAvailable(project, startElement)) {
                                ProblemHighlightType type = annotation.getHighlightType();
                                annotation.registerFix(action, null, key, InspectionManager.getInstance(project).createProblemDescriptor(startElement, endElement, message, type, true, LocalQuickFix.EMPTY_ARRAY));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Issue(com.android.tools.klint.detector.api.Issue) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) Annotation(com.intellij.lang.annotation.Annotation) Project(com.intellij.openapi.project.Project) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) PsiElement(com.intellij.psi.PsiElement)

Example 85 with Annotation

use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.

the class DomElementsHighlightingUtil method createAnnotation.

@Nullable
public static Annotation createAnnotation(final DomElementProblemDescriptor problemDescriptor) {
    return createProblemDescriptors(problemDescriptor, s -> {
        String text = problemDescriptor.getDescriptionTemplate();
        if (StringUtil.isEmpty(text))
            text = null;
        final HighlightSeverity severity = problemDescriptor.getHighlightSeverity();
        TextRange range = s.first;
        if (text == null)
            range = TextRange.from(range.getStartOffset(), 0);
        range = range.shiftRight(s.second.getTextRange().getStartOffset());
        final Annotation annotation = createAnnotation(severity, range, text);
        if (problemDescriptor instanceof DomElementResolveProblemDescriptor) {
            annotation.setTextAttributes(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
        }
        for (LocalQuickFix fix : problemDescriptor.getFixes()) {
            if (fix instanceof IntentionAction)
                annotation.registerFix((IntentionAction) fix);
        }
        return annotation;
    });
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) TextRange(com.intellij.openapi.util.TextRange) Annotation(com.intellij.lang.annotation.Annotation) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Annotation (com.intellij.lang.annotation.Annotation)98 PsiElement (com.intellij.psi.PsiElement)24 ASTNode (com.intellij.lang.ASTNode)22 TextRange (com.intellij.openapi.util.TextRange)19 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)15 Project (com.intellij.openapi.project.Project)11 NotNull (org.jetbrains.annotations.NotNull)10 PsiFile (com.intellij.psi.PsiFile)8 GrModifierFix (org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix)6 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)4 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)4 Editor (com.intellij.openapi.editor.Editor)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)4 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)3 Module (com.intellij.openapi.module.Module)3 PsiReference (com.intellij.psi.PsiReference)3 IElementType (com.intellij.psi.tree.IElementType)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 Nullable (org.jetbrains.annotations.Nullable)3