use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrHighlightUtil method getClassHeaderTextRange.
public static TextRange getClassHeaderTextRange(GrTypeDefinition clazz) {
final GrModifierList modifierList = clazz.getModifierList();
final int startOffset = modifierList != null ? modifierList.getTextOffset() : clazz.getTextOffset();
final GrImplementsClause implementsClause = clazz.getImplementsClause();
final int endOffset;
if (implementsClause != null) {
endOffset = implementsClause.getTextRange().getEndOffset();
} else {
final GrExtendsClause extendsClause = clazz.getExtendsClause();
if (extendsClause != null) {
endOffset = extendsClause.getTextRange().getEndOffset();
} else {
endOffset = clazz.getNameIdentifierGroovy().getTextRange().getEndOffset();
}
}
return new TextRange(startOffset, endOffset);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList 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));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyAnnotator method checkGetterOfImmutable.
private static void checkGetterOfImmutable(AnnotationHolder holder, GrMethod method) {
if (!GroovyPropertyUtils.isSimplePropertyGetter(method))
return;
PsiClass aClass = method.getContainingClass();
if (aClass == null)
return;
PsiModifierList aClassModifierList = aClass.getModifierList();
if (aClassModifierList == null)
return;
if (!PsiImplUtil.hasImmutableAnnotation(aClassModifierList))
return;
PsiField field = GroovyPropertyUtils.findFieldForAccessor(method, false);
if (field == null || !(field instanceof GrField))
return;
GrModifierList fieldModifierList = ((GrField) field).getModifierList();
if (fieldModifierList == null)
return;
if (fieldModifierList.hasExplicitVisibilityModifiers())
return;
holder.createErrorAnnotation(method.getNameIdentifierGroovy(), GroovyBundle.message("repetitive.method.name.0", method.getName()));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList 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);
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyAnnotator method visitForInClause.
@Override
public void visitForInClause(@NotNull GrForInClause forInClause) {
final GrVariable var = forInClause.getDeclaredVariable();
if (var == null)
return;
final GrModifierList modifierList = var.getModifierList();
if (modifierList == null)
return;
final PsiElement[] modifiers = modifierList.getModifiers();
for (PsiElement modifier : modifiers) {
if (modifier instanceof PsiAnnotation)
continue;
final String modifierText = modifier.getText();
if (PsiModifier.FINAL.equals(modifierText))
continue;
if (GrModifier.DEF.equals(modifierText))
continue;
myHolder.createErrorAnnotation(modifier, GroovyBundle.message("not.allowed.modifier.in.forin", modifierText));
}
}
Aggregations