Search in sources :

Example 56 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 57 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)

Example 58 with Annotation

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

the class GroovyAnnotator method visitTypeDefinition.

@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
    final PsiElement parent = typeDefinition.getParent();
    if (!(typeDefinition.isAnonymous() || parent instanceof GrTypeDefinitionBody || parent instanceof GroovyFile || typeDefinition instanceof GrTypeParameter)) {
        final TextRange range = GrHighlightUtil.getClassHeaderTextRange(typeDefinition);
        final Annotation errorAnnotation = myHolder.createErrorAnnotation(range, GroovyBundle.message("class.definition.is.not.expected.here"));
        errorAnnotation.registerFix(new GrMoveClassToCorrectPlaceFix(typeDefinition));
    }
    checkTypeDefinition(myHolder, typeDefinition);
    checkImplementedMethodsOfClass(myHolder, typeDefinition);
    checkConstructors(myHolder, typeDefinition);
    checkAnnotationCollector(myHolder, typeDefinition);
    checkSameNameMethodsWithDifferentAccessModifiers(myHolder, typeDefinition.getCodeMethods());
    checkInheritorOfSelfTypes(myHolder, typeDefinition);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Annotation(com.intellij.lang.annotation.Annotation)

Example 59 with Annotation

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

the class GroovyAnnotator method visitOpenBlock.

@Override
public void visitOpenBlock(@NotNull GrOpenBlock block) {
    if (block.getParent() instanceof GrMethod) {
        final GrMethod method = (GrMethod) block.getParent();
        if (method.getModifierList().hasExplicitModifier(PsiModifier.ABSTRACT) || GrTraitUtil.isInterface(method.getContainingClass())) {
            final Annotation annotation = myHolder.createErrorAnnotation(block, GroovyBundle.message("abstract.methods.must.not.have.body"));
            registerMakeAbstractMethodNotAbstractFix(annotation, method, true);
        }
    }
}
Also used : Annotation(com.intellij.lang.annotation.Annotation)

Example 60 with Annotation

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

the class GroovyAnnotator method checkTypeDefinitionModifiers.

private static void checkTypeDefinitionModifiers(AnnotationHolder holder, GrTypeDefinition typeDefinition) {
    GrModifierList modifiersList = typeDefinition.getModifierList();
    if (modifiersList == null)
        return;
    /**** class ****/
    checkAccessModifiers(holder, modifiersList, typeDefinition);
    checkDuplicateModifiers(holder, modifiersList, typeDefinition);
    PsiClassType[] extendsListTypes = typeDefinition.getExtendsListTypes();
    for (PsiClassType classType : extendsListTypes) {
        PsiClass psiClass = classType.resolve();
        if (psiClass != null && psiClass.hasModifierProperty(PsiModifier.FINAL)) {
            final Annotation annotation = holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("final.class.cannot.be.extended"));
            registerFix(annotation, new GrModifierFix(typeDefinition, PsiModifier.FINAL, false, false, GrModifierFix.MODIFIER_LIST_OWNER), typeDefinition);
        }
    }
    if (!typeDefinition.isEnum()) {
        checkForAbstractAndFinalCombination(holder, typeDefinition, modifiersList);
    }
    checkModifierIsNotAllowed(modifiersList, PsiModifier.TRANSIENT, GroovyBundle.message("modifier.transient.not.allowed.here"), holder);
    checkModifierIsNotAllowed(modifiersList, PsiModifier.VOLATILE, GroovyBundle.message("modifier.volatile.not.allowed.here"), holder);
    /**** interface ****/
    if (typeDefinition.isInterface()) {
        checkModifierIsNotAllowed(modifiersList, PsiModifier.FINAL, GroovyBundle.message("intarface.cannot.have.modifier.final"), holder);
    }
    if (GroovyConfigUtils.getInstance().isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_8)) {
        if (typeDefinition.getContainingClass() == null && !(typeDefinition instanceof GrTraitTypeDefinition)) {
            checkModifierIsNotAllowed(modifiersList, PsiModifier.STATIC, holder);
        }
    }
}
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)

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