void (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); PsiElement modifierOrList = getModifierOrList(modifiersList, PsiModifier.ABSTRACT); if (method.getParent() instanceof GroovyFileBase) { if (isMethodAbstract) { String message = GroovyBundle.message("script.method.cannot.have.modifier.abstract"); AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, message) .range(modifierOrList); registerMakeAbstractMethodNotAbstractFix(builder, method, false, message, modifierOrList.getTextRange()).create(); } checkModifierIsNotAllowed(modifiersList, PsiModifier.NATIVE, GroovyBundle.message("script.cannot.have.modifier.native"), holder); } //type definition methods else if (method.getParent() != null && method.getParent().getParent() instanceof GrTypeDefinition containingTypeDef) { if (containingTypeDef.isTrait()) { checkModifierIsNotAllowed(modifiersList, PsiModifier.PROTECTED, GroovyBundle.message("trait.method.cannot.be.protected"), holder); } //interface else 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) { String message = GroovyBundle.message("anonymous.class.cannot.have.abstract.method"); AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, message).range( modifierOrList); registerMakeAbstractMethodNotAbstractFix(builder, method, false, message, modifierOrList.getTextRange()).create(); } } //class else { PsiModifierList typeDefModifiersList = containingTypeDef.getModifierList(); LOG.assertTrue(typeDefModifiersList != null, "modifiers list must be not null"); if (!typeDefModifiersList.hasModifierProperty(PsiModifier.ABSTRACT) && isMethodAbstract) { String message = GroovyBundle.message("only.abstract.class.can.have.abstract.method"); AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, message) .range(modifiersList); registerMakeAbstractMethodNotAbstractFix(builder, method, true, message, modifierOrList.getTextRange()).create(); } } if (method.isConstructor()) { checkModifierIsNotAllowed(modifiersList, PsiModifier.STATIC, GroovyBundle.message("constructor.cannot.have.static.modifier"), holder); } } if (method.hasModifierProperty(PsiModifier.NATIVE) && method.getBlock() != null) { String message = GroovyBundle.message("native.methods.cannot.have.body"); PsiElement list = getModifierOrList(modifiersList, PsiModifier.NATIVE); AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, message) .range(list); builder = registerLocalFix(builder, new GrModifierFix((PsiMember)modifiersList.getParent(), PsiModifier.NATIVE, true, false, GrModifierFix.MODIFIER_LIST), modifiersList, message, ProblemHighlightType.ERROR, list.getTextRange()); builder.withFix(QuickFixFactory.getInstance().createDeleteMethodBodyFix(method)) .create(); } }