use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyAnnotator method visitVariable.
@Override
public void visitVariable(@NotNull GrVariable variable) {
checkName(variable);
PsiElement parent = variable.getParent();
if (parent instanceof GrForInClause) {
PsiElement delimiter = ((GrForInClause) parent).getDelimiter();
if (delimiter.getNode().getElementType() == GroovyTokenTypes.mCOLON) {
GrTypeElement typeElement = variable.getTypeElementGroovy();
GrModifierList modifierList = variable.getModifierList();
if (typeElement == null && StringUtil.isEmptyOrSpaces(modifierList.getText())) {
Annotation annotation = myHolder.createErrorAnnotation(variable.getNameIdentifierGroovy(), GroovyBundle.message("java.style.for.each.statement.requires.a.type.declaration"));
annotation.registerFix(new ReplaceDelimiterFix());
}
}
}
PsiNamedElement duplicate = ResolveUtil.findDuplicate(variable);
if (duplicate instanceof GrVariable && (variable instanceof GrField || ResolveUtil.isScriptField(variable) || !(duplicate instanceof GrField))) {
final String key = duplicate instanceof GrField ? "field.already.defined" : "variable.already.defined";
myHolder.createErrorAnnotation(variable.getNameIdentifierGroovy(), GroovyBundle.message(key, variable.getName()));
}
PsiType type = variable.getDeclaredType();
if (type instanceof PsiEllipsisType && !isLastParameter(variable)) {
TextRange range = getEllipsisRange(variable);
if (range == null) {
range = getTypeRange(variable);
}
if (range != null) {
myHolder.createErrorAnnotation(range, GroovyBundle.message("ellipsis.type.is.not.allowed.here"));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList 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.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrUnnecessaryPublicModifierInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@Override
public void visitElement(PsiElement modifier) {
if (modifier.getNode().getElementType() != GroovyTokenTypes.kPUBLIC)
return;
PsiElement list = modifier.getParent();
if (!(list instanceof GrModifierList))
return;
PsiElement parent = list.getParent();
// It may be put there explicitly to prevent getter/setter generation.
if (parent instanceof GrVariableDeclaration)
return;
holder.registerProblem(modifier, GroovyInspectionBundle.message("unnecessary.modifier.description", PsiModifier.PUBLIC), ProblemHighlightType.LIKE_UNUSED_SYMBOL, FIX);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class SpockUnrollReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
GrAnnotationNameValuePair nvp = (GrAnnotationNameValuePair) element.getParent();
String name = nvp.getName();
if (name != null && !name.equals("value"))
return PsiReference.EMPTY_ARRAY;
PsiElement argumentList = nvp.getParent();
if (!(argumentList instanceof GrAnnotationArgumentList))
return PsiReference.EMPTY_ARRAY;
PsiElement eAnnotation = argumentList.getParent();
if (!(eAnnotation instanceof GrAnnotation))
return PsiReference.EMPTY_ARRAY;
GrAnnotation annotation = (GrAnnotation) eAnnotation;
String shortName = annotation.getShortName();
if (!shortName.equals("Unroll") && !shortName.equals("spock.lang.Unroll"))
return PsiReference.EMPTY_ARRAY;
PsiElement modifierList = annotation.getParent();
if (!(modifierList instanceof GrModifierList))
return PsiReference.EMPTY_ARRAY;
PsiElement eMethod = modifierList.getParent();
if (!(eMethod instanceof GrMethod))
return PsiReference.EMPTY_ARRAY;
final GrMethod method = (GrMethod) eMethod;
ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
TextRange rangeInElement = manipulator.getRangeInElement(element);
String text = rangeInElement.substring(element.getText());
final List<SpockVariableReference> references = new ArrayList<>();
Matcher matcher = PATTERN.matcher(text);
while (matcher.find()) {
TextRange range = new TextRange(rangeInElement.getStartOffset() + matcher.start(1), rangeInElement.getStartOffset() + matcher.end(1));
references.add(new SpockVariableReference(element, range, references, method));
}
return references.toArray(new PsiReference[references.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrVariableDeclarationImpl method findSuitableModifier.
private PsiElement findSuitableModifier() {
final GrModifierList list = getModifierList();
PsiElement defModifier = list.getModifier(GrModifier.DEF);
if (defModifier != null)
return defModifier;
PsiElement finalModifier = list.getModifier(PsiModifier.FINAL);
if (finalModifier != null)
return finalModifier;
for (PsiElement element : list.getModifiers()) {
if (!(element instanceof GrAnnotation)) {
return element;
}
}
return null;
}
Aggregations