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);
}
}
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);
}
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);
}
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);
}
}
}
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);
}
}
}
Aggregations