Search in sources :

Example 91 with Annotation

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

the class DartAnnotator method createAnnotation.

@Nullable
private static Annotation createAnnotation(@NotNull final AnnotationHolder holder, @NotNull final DartServerData.DartError error, final int fileTextLength) {
    int highlightingStart = error.getOffset();
    int highlightingEnd = error.getOffset() + error.getLength();
    if (highlightingEnd > fileTextLength)
        highlightingEnd = fileTextLength;
    if (highlightingStart > 0 && highlightingStart >= highlightingEnd)
        highlightingStart = highlightingEnd - 1;
    final TextRange textRange = new TextRange(highlightingStart, highlightingEnd);
    final String severity = error.getSeverity();
    final String message = StringUtil.notNullize(error.getMessage());
    final ProblemHighlightType specialHighlightType = getSpecialHighlightType(message);
    final Annotation annotation;
    if (AnalysisErrorSeverity.INFO.equals(severity) && specialHighlightType == null) {
        annotation = holder.createWeakWarningAnnotation(textRange, message);
        annotation.setTextAttributes(DartSyntaxHighlighterColors.HINT);
    } else if (AnalysisErrorSeverity.WARNING.equals(severity) || (AnalysisErrorSeverity.INFO.equals(severity) && specialHighlightType != null)) {
        annotation = holder.createWarningAnnotation(textRange, message);
        annotation.setTextAttributes(DartSyntaxHighlighterColors.WARNING);
    } else if (AnalysisErrorSeverity.ERROR.equals(severity)) {
        annotation = holder.createErrorAnnotation(textRange, message);
        annotation.setTextAttributes(DartSyntaxHighlighterColors.ERROR);
    } else {
        annotation = null;
    }
    if (annotation != null && specialHighlightType != null) {
        annotation.setTextAttributes(null);
        annotation.setHighlightType(specialHighlightType);
    }
    return annotation;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) ProblemHighlightType(com.intellij.codeInspection.ProblemHighlightType) Annotation(com.intellij.lang.annotation.Annotation) Nullable(org.jetbrains.annotations.Nullable)

Example 92 with Annotation

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

the class FlexMxmlColorAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (!(element instanceof XmlAttribute) || !JavaScriptSupportLoader.isFlexMxmFile(element.getContainingFile())) {
        return;
    }
    if (!LineMarkerSettings.getSettings().isEnabled(new ColorLineMarkerProvider())) {
        return;
    }
    XmlAttribute attribute = (XmlAttribute) element;
    XmlAttributeDescriptor descriptor = attribute.getDescriptor();
    if (!(descriptor instanceof AnnotationBackedDescriptorImpl)) {
        return;
    }
    AnnotationBackedDescriptorImpl annotationBackedDescriptor = (AnnotationBackedDescriptorImpl) descriptor;
    String format = annotationBackedDescriptor.getFormat();
    if (!FlexCssPropertyDescriptor.COLOR_FORMAT.equals(format)) {
        return;
    }
    final String value = attribute.getValue();
    if (value == null || value.length() == 0) {
        return;
    }
    if (!JSCommonTypeNames.ARRAY_CLASS_NAME.equals(annotationBackedDescriptor.getType())) {
        XmlAttributeValue valueElement = attribute.getValueElement();
        if (valueElement != null) {
            Annotation annotation = holder.createInfoAnnotation(valueElement, null);
            annotation.setGutterIconRenderer(new MyRenderer(value, attribute));
        }
    }
}
Also used : ColorLineMarkerProvider(com.intellij.ui.ColorLineMarkerProvider) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AnnotationBackedDescriptorImpl(com.intellij.javascript.flex.mxml.schema.AnnotationBackedDescriptorImpl) Annotation(com.intellij.lang.annotation.Annotation)

Example 93 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 94 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 95 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)97 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 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 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)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 HbCloseBlockMustache (com.dmarcotte.handlebars.psi.HbCloseBlockMustache)2