Search in sources :

Example 71 with Annotation

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

the class GroovyPostHighlightingPass method doApplyInformationToEditor.

@Override
public void doApplyInformationToEditor() {
    if (myUnusedDeclarations == null || myUnusedImports == null) {
        return;
    }
    AnnotationHolder annotationHolder = new AnnotationHolderImpl(new AnnotationSession(myFile));
    List<HighlightInfo> infos = new ArrayList<>(myUnusedDeclarations);
    for (GrImportStatement unusedImport : myUnusedImports) {
        Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
        annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
        annotation.registerFix(GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(false));
        infos.add(HighlightInfo.fromAnnotation(annotation));
    }
    UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
    if (myUnusedImports != null && !myUnusedImports.isEmpty()) {
        IntentionAction fix = GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(true);
        if (fix.isAvailable(myProject, myEditor, myFile) && myFile.isWritable()) {
            fix.invoke(myProject, myEditor, myFile);
        }
    }
}
Also used : AnnotationSession(com.intellij.lang.annotation.AnnotationSession) AnnotationHolder(com.intellij.lang.annotation.AnnotationHolder) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) Annotation(com.intellij.lang.annotation.Annotation)

Example 72 with Annotation

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

the class XsltAnnotator method visitXPathToken.

@Override
public void visitXPathToken(XPathToken token) {
    if (XPathTokenTypes.REL_OPS.contains(token.getTokenType())) {
        if (token.textContains('<')) {
            final Annotation ann = myHolder.createErrorAnnotation(token, "'<' must be escaped as '&lt;' in XSLT documents");
            ann.registerFix(new ConvertToEntityFix(token));
            ann.registerFix(new FlipOperandsFix(token));
        }
    }
}
Also used : FlipOperandsFix(org.intellij.lang.xpath.xslt.quickfix.FlipOperandsFix) ConvertToEntityFix(org.intellij.lang.xpath.xslt.quickfix.ConvertToEntityFix) Annotation(com.intellij.lang.annotation.Annotation)

Example 73 with Annotation

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

the class GroovyAnnotator method checkMethodDefinitionModifiers.

private static void checkMethodDefinitionModifiers(AnnotationHolder holder, GrMethod method) {
    final GrModifierList modifiersList = method.getModifierList();
    checkAccessModifiers(holder, modifiersList, method);
    checkDuplicateModifiers(holder, modifiersList, method);
    checkOverrideAnnotation(holder, modifiersList, method);
    checkModifierIsNotAllowed(modifiersList, PsiModifier.VOLATILE, GroovyBundle.message("method.has.incorrect.modifier.volatile"), holder);
    checkForAbstractAndFinalCombination(holder, method, modifiersList);
    //script methods
    boolean isMethodAbstract = modifiersList.hasExplicitModifier(PsiModifier.ABSTRACT);
    if (method.getParent() instanceof GroovyFileBase) {
        if (isMethodAbstract) {
            final Annotation annotation = holder.createErrorAnnotation(getModifierOrList(modifiersList, PsiModifier.ABSTRACT), GroovyBundle.message("script.method.cannot.have.modifier.abstract"));
            registerMakeAbstractMethodNotAbstractFix(annotation, method, false);
        }
        checkModifierIsNotAllowed(modifiersList, PsiModifier.NATIVE, GroovyBundle.message("script.cannot.have.modifier.native"), holder);
    } else //type definition methods
    if (method.getParent() != null && method.getParent().getParent() instanceof GrTypeDefinition) {
        GrTypeDefinition containingTypeDef = ((GrTypeDefinition) method.getParent().getParent());
        if (containingTypeDef.isTrait()) {
            checkModifierIsNotAllowed(modifiersList, PsiModifier.PROTECTED, GroovyBundle.message("trait.method.cannot.be.protected"), holder);
        } else //interface
        if (containingTypeDef.isInterface()) {
            checkModifierIsNotAllowed(modifiersList, PsiModifier.STATIC, GroovyBundle.message("interface.must.have.no.static.method"), holder);
            checkModifierIsNotAllowed(modifiersList, PsiModifier.PRIVATE, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PRIVATE), holder);
            checkModifierIsNotAllowed(modifiersList, PsiModifier.PROTECTED, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PROTECTED), holder);
        } else if (containingTypeDef.isAnonymous()) {
            if (isMethodAbstract) {
                final Annotation annotation = holder.createErrorAnnotation(getModifierOrList(modifiersList, PsiModifier.ABSTRACT), GroovyBundle.message("anonymous.class.cannot.have.abstract.method"));
                registerMakeAbstractMethodNotAbstractFix(annotation, method, false);
            }
        } else //class
        {
            PsiModifierList typeDefModifiersList = containingTypeDef.getModifierList();
            LOG.assertTrue(typeDefModifiersList != null, "modifiers list must be not null");
            if (!typeDefModifiersList.hasModifierProperty(PsiModifier.ABSTRACT) && isMethodAbstract) {
                final Annotation annotation = holder.createErrorAnnotation(modifiersList, GroovyBundle.message("only.abstract.class.can.have.abstract.method"));
                registerMakeAbstractMethodNotAbstractFix(annotation, method, true);
            }
        }
        if (method.isConstructor()) {
            checkModifierIsNotAllowed(modifiersList, PsiModifier.STATIC, GroovyBundle.message("constructor.cannot.have.static.modifier"), holder);
        }
    }
    if (method.hasModifierProperty(PsiModifier.NATIVE) && method.getBlock() != null) {
        final Annotation annotation = holder.createErrorAnnotation(getModifierOrList(modifiersList, PsiModifier.NATIVE), GroovyBundle.message("native.methods.cannot.have.body"));
        registerFix(annotation, new GrModifierFix((PsiMember) modifiersList.getParent(), PsiModifier.NATIVE, true, false, GrModifierFix.MODIFIER_LIST), modifiersList);
        annotation.registerFix(QuickFixFactory.getInstance().createDeleteMethodBodyFix(method));
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrModifierFix(org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix) Annotation(com.intellij.lang.annotation.Annotation)

Example 74 with Annotation

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

the class GroovyAnnotator method checkAccessModifiers.

private static void checkAccessModifiers(AnnotationHolder holder, @NotNull GrModifierList modifierList, PsiMember member) {
    boolean hasPrivate = modifierList.hasExplicitModifier(PsiModifier.PRIVATE);
    boolean hasPublic = modifierList.hasExplicitModifier(PsiModifier.PUBLIC);
    boolean hasProtected = modifierList.hasExplicitModifier(PsiModifier.PROTECTED);
    if (hasPrivate && hasPublic || hasPrivate && hasProtected || hasPublic && hasProtected) {
        final Annotation annotation = holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers"));
        if (hasPrivate) {
            registerFix(annotation, new GrModifierFix(member, PsiModifier.PRIVATE, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
        }
        if (hasProtected) {
            registerFix(annotation, new GrModifierFix(member, PsiModifier.PROTECTED, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
        }
        if (hasPublic) {
            registerFix(annotation, new GrModifierFix(member, PsiModifier.PUBLIC, false, false, GrModifierFix.MODIFIER_LIST), modifierList);
        }
    } else if (member instanceof PsiClass && member.getContainingClass() == null && GroovyConfigUtils.getInstance().isVersionAtLeast(member, GroovyConfigUtils.GROOVY2_0)) {
        checkModifierIsNotAllowed(modifierList, PsiModifier.PRIVATE, GroovyBundle.message("top.level.class.maynot.have.private.modifier"), holder);
        checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("top.level.class.maynot.have.protected.modifier"), holder);
    }
}
Also used : GrModifierFix(org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix) Annotation(com.intellij.lang.annotation.Annotation)

Example 75 with Annotation

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

the class GroovyAnnotator method checkTypeArgForPrimitive.

private void checkTypeArgForPrimitive(@Nullable GrTypeElement element, String message) {
    if (element == null || !(element.getType() instanceof PsiPrimitiveType))
        return;
    final Annotation annotation = myHolder.createErrorAnnotation(element, message);
    registerFix(annotation, new GrReplacePrimitiveTypeWithWrapperFix(element), element);
}
Also used : 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