use of org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix in project intellij-community by JetBrains.
the class GroovyAnnotator method checkForAbstractAndFinalCombination.
private static void checkForAbstractAndFinalCombination(AnnotationHolder holder, GrMember member, GrModifierList modifiersList) {
if (member.hasModifierProperty(PsiModifier.FINAL) && member.hasModifierProperty(PsiModifier.ABSTRACT)) {
final Annotation annotation = holder.createErrorAnnotation(modifiersList, GroovyBundle.message("illegal.combination.of.modifiers.abstract.and.final"));
registerFix(annotation, new GrModifierFix(member, PsiModifier.FINAL, false, false, GrModifierFix.MODIFIER_LIST), modifiersList);
registerFix(annotation, new GrModifierFix(member, PsiModifier.ABSTRACT, false, false, GrModifierFix.MODIFIER_LIST), modifiersList);
}
}
use of org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix in project intellij-community by JetBrains.
the class GroovyAnnotator method checkDuplicateModifiers.
private static void checkDuplicateModifiers(AnnotationHolder holder, @NotNull GrModifierList list, PsiMember member) {
final PsiElement[] modifiers = list.getModifiers();
Set<String> set = new THashSet<>(modifiers.length);
for (PsiElement modifier : modifiers) {
if (modifier instanceof GrAnnotation)
continue;
@GrModifier.GrModifierConstant String name = modifier.getText();
if (set.contains(name)) {
final Annotation annotation = holder.createErrorAnnotation(list, GroovyBundle.message("duplicate.modifier", name));
registerFix(annotation, new GrModifierFix(member, name, false, false, GrModifierFix.MODIFIER_LIST), list);
} else {
set.add(name);
}
}
}
use of org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix in project intellij-community by JetBrains.
the class GroovyAnnotator method checkFieldModifiers.
private static void checkFieldModifiers(AnnotationHolder holder, GrVariableDeclaration fieldDeclaration) {
GrVariable[] variables = fieldDeclaration.getVariables();
if (variables.length == 0)
return;
GrVariable variable = variables[0];
if (!(variable instanceof GrField))
return;
final GrField member = (GrField) variable;
final GrModifierList modifierList = fieldDeclaration.getModifierList();
checkAccessModifiers(holder, modifierList, member);
checkDuplicateModifiers(holder, modifierList, member);
if (modifierList.hasExplicitModifier(PsiModifier.VOLATILE) && modifierList.hasExplicitModifier(PsiModifier.FINAL)) {
final Annotation annotation = holder.createErrorAnnotation(modifierList, GroovyBundle.message("illegal.combination.of.modifiers.volatile.and.final"));
registerFix(annotation, new GrModifierFix(member, PsiModifier.VOLATILE, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
registerFix(annotation, new GrModifierFix(member, PsiModifier.FINAL, true, false, GrModifierFix.MODIFIER_LIST), modifierList);
}
if (member.getContainingClass() instanceof GrInterfaceDefinition) {
checkModifierIsNotAllowed(modifierList, PsiModifier.PRIVATE, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PRIVATE), holder);
checkModifierIsNotAllowed(modifierList, PsiModifier.PROTECTED, GroovyBundle.message("interface.members.are.not.allowed.to.be", PsiModifier.PROTECTED), holder);
}
}
use of org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix in project intellij-community by JetBrains.
the class GroovyVariableCanBeFinalInspection method process.
private static void process(@NotNull GrControlFlowOwner owner, @NotNull GrVariable variable, @NotNull ProblemsHolder problemsHolder) {
if (variable.hasModifierProperty(PsiModifier.FINAL))
return;
if (!checkVariableDeclaredInsideScope(owner, variable))
return;
if (checkVariableAssignedInsideClosureOrAnonymous(owner, variable))
return;
final boolean isParameterTooltip = variable instanceof GrParameter && (((GrParameter) variable).getDeclarationScope() instanceof GrMethod || ((GrParameter) variable).getDeclarationScope() instanceof GrClosableBlock);
final String tooltip = GroovyInspectionBundle.message(isParameterTooltip ? "parameter.can.be.final.tooltip" : "variable.can.be.final.tooltip", variable.getName());
problemsHolder.registerProblem(variable.getNameIdentifierGroovy(), tooltip, new GrModifierFix(variable, PsiModifier.FINAL, true, ID_MODIFIER_LIST_PROVIDER));
}
use of org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix in project intellij-community by JetBrains.
the class GrMethodMayBeStaticInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitMethod(@NotNull GrMethod method) {
if (checkMethod(method)) {
final GrModifierFix modifierFix = new GrModifierFix(method, PsiModifier.STATIC, false, true, descriptor -> {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = element.getParent();
assert parent instanceof GrMethod : "element: " + element + ", parent:" + parent;
return ((GrMethod) parent).getModifierList();
});
registerError(method.getNameIdentifierGroovy(), message("method.may.be.static"), new LocalQuickFix[] { modifierFix }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
};
}
Aggregations