Search in sources :

Example 51 with Annotation

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

the class AndroidColorAnnotator method annotateResourceValue.

/** Annotates the given element with the resolved value of the given {@link ResourceValue} */
private static void annotateResourceValue(@NotNull ResourceType type, @NotNull AnnotationHolder holder, @NotNull PsiElement element, @NotNull ResourceValue value, @NotNull ResourceResolver resourceResolver, @NotNull AndroidFacet facet) {
    Project project = element.getProject();
    if (type == ResourceType.COLOR) {
        Color color = ResourceHelper.resolveColor(resourceResolver, value, project);
        if (color != null) {
            Annotation annotation = holder.createInfoAnnotation(element, null);
            annotation.setGutterIconRenderer(new MyRenderer(element, color));
        }
    } else {
        assert type == ResourceType.DRAWABLE || type == ResourceType.MIPMAP;
        File file = ResourceHelper.resolveDrawable(resourceResolver, value, project);
        if (file != null && file.getPath().endsWith(DOT_XML)) {
            file = pickBitmapFromXml(file, resourceResolver, project, facet, value);
        }
        File iconFile = pickBestBitmap(file);
        if (iconFile != null) {
            Annotation annotation = holder.createInfoAnnotation(element, null);
            annotation.setGutterIconRenderer(new com.android.tools.idea.rendering.GutterIconRenderer(resourceResolver, element, iconFile));
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Annotation(com.intellij.lang.annotation.Annotation)

Example 52 with Annotation

use of com.intellij.lang.annotation.Annotation in project android 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();
    if (DumbService.isDumb(project))
        return;
    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 (LintIdeIssueRegistry.CUSTOM_ERROR == issue || LintIdeIssueRegistry.CUSTOM_WARNING == issue) {
                        Issue original = LintIdeClient.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 (issue == DeprecationDetector.ISSUE || issue == GradleDetector.DEPRECATED) {
                        annotation.setHighlightType(ProblemHighlightType.LIKE_DEPRECATED);
                    }
                    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.lint.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 53 with Annotation

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

the class ActionScriptAnnotatingVisitor method modifierProblem.

private void modifierProblem(JSAttributeList attributeList, JSAttributeList.ModifierType modifierType, String messageKey, String removeFixNameKey) {
    PsiElement modifierElement = attributeList.findModifierElement(modifierType);
    String message = JSBundle.message(messageKey);
    Annotation annotation = myHolder.createErrorAnnotation(modifierElement, message);
    annotation.registerFix(new RemoveASTNodeFix(removeFixNameKey, modifierElement.getNode()));
}
Also used : Annotation(com.intellij.lang.annotation.Annotation)

Example 54 with Annotation

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

the class ActionScriptAnnotatingVisitor method checkNamedObjectIsInCorrespondingFile.

private void checkNamedObjectIsInCorrespondingFile(final JSNamedElement aClass) {
    final PsiFile containingFile = aClass.getContainingFile();
    if (containingFile.getContext() != null)
        return;
    final VirtualFile file = containingFile.getVirtualFile();
    if (file != null && !file.getNameWithoutExtension().equals(aClass.getName()) && ProjectRootManager.getInstance(containingFile.getProject()).getFileIndex().getSourceRootForFile(file) != null) {
        final ASTNode node = aClass.findNameIdentifier();
        if (node != null) {
            final String name = aClass.getName();
            String nameWithExtension = name + "." + file.getExtension();
            final String message = JSBundle.message(aClass instanceof JSClass ? "javascript.validation.message.class.should.be.in.file" : aClass instanceof JSNamespaceDeclaration ? "javascript.validation.message.namespace.should.be.in.file" : aClass instanceof JSVariable ? "javascript.validation.message.variable.should.be.in.file" : "javascript.validation.message.function.should.be.in.file", name, nameWithExtension);
            final Annotation annotation = myHolder.createErrorAnnotation(node, message);
            annotation.registerFix(new RenameFileFix(nameWithExtension));
            annotation.registerFix(new RenameElementFix(aClass) {

                final String text;

                final String familyName;

                {
                    String term = message.substring(0, message.indexOf(' '));
                    text = super.getText().replace("class", StringUtil.decapitalize(term));
                    familyName = super.getFamilyName().replace("Class", term);
                }

                @NotNull
                @Override
                public String getText() {
                    return text;
                }

                @NotNull
                @Override
                public String getFamilyName() {
                    return familyName;
                }
            });
        }
    }
    checkFileUnderSourceRoot(aClass, new SimpleErrorReportingClient());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RenameElementFix(com.intellij.codeInsight.daemon.impl.quickfix.RenameElementFix) NotNull(org.jetbrains.annotations.NotNull) Annotation(com.intellij.lang.annotation.Annotation) ASTNode(com.intellij.lang.ASTNode) RenameFileFix(com.intellij.codeInsight.daemon.impl.quickfix.RenameFileFix)

Example 55 with Annotation

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

the class ActionScriptAnnotatingVisitor method checkMultipleModifiersProblem.

private void checkMultipleModifiersProblem(JSAttributeList attributeList) {
    final ASTNode node = attributeList.getNode();
    for (int i = 0; i < ourModifiersList.size(); ++i) {
        final ASTNode[] modifiers = node.getChildren(ourModifiersList.get(i));
        if (modifiers.length < 2)
            continue;
        String s = modifiers[0].getElementType().toString().toLowerCase(Locale.ENGLISH);
        final String type = s.substring(s.indexOf(':') + 1, s.indexOf('_'));
        for (ASTNode a : modifiers) {
            final Annotation errorAnnotation = JSAnnotatorProblemReporter.createErrorAnnotation(a.getPsi(), JSBundle.message("javascript.validation.message.attribute.was.specified.multiple.times", type), ProblemHighlightType.ERROR, myHolder);
            errorAnnotation.registerFix(new RemoveASTNodeFix(ourModifierFixIds[i], a));
        }
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) Annotation(com.intellij.lang.annotation.Annotation)

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