use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GroovyDocCheckInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitDocMethodReference(@NotNull GrDocMethodReference reference) {
checkGrDocMemberReference(reference);
}
@Override
public void visitDocFieldReference(@NotNull GrDocFieldReference reference) {
checkGrDocMemberReference(reference);
}
@Override
public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement refElement) {
GroovyResolveResult resolveResult = refElement.advancedResolve();
if (refElement.getReferenceName() == null)
return;
if (PsiTreeUtil.getParentOfType(refElement, GroovyDocPsiElement.class, true, GrMember.class, GrCodeBlock.class) == null)
return;
final PsiElement resolved = resolveResult.getElement();
if (resolved != null)
return;
final PsiElement toHighlight = refElement.getReferenceNameElement();
registerError(toHighlight, GroovyBundle.message("cannot.resolve", refElement.getReferenceName()));
}
private void checkGrDocMemberReference(final GrDocMemberReference reference) {
if (reference.resolve() != null)
return;
registerError(reference.getReferenceNameElement(), GroovyBundle.message("cannot.resolve", reference.getReferenceName()));
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class NewInstanceOfSingletonInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitNewExpression(@NotNull GrNewExpression newExpression) {
if (newExpression.getArrayDeclaration() != null)
return;
GrCodeReferenceElement refElement = newExpression.getReferenceElement();
if (refElement == null)
return;
PsiElement resolved = refElement.resolve();
if (!(resolved instanceof GrTypeDefinition))
return;
PsiAnnotation annotation = AnnotationUtil.findAnnotation((GrTypeDefinition) resolved, GROOVY_LANG_SINGLETON);
if (annotation == null)
return;
registerError(newExpression, GroovyInspectionBundle.message("new.instance.of.singleton"), ContainerUtil.ar(new ReplaceWithInstanceAccessFix()), ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class GrNewExpressionInfo method getElementToHighlight.
@NotNull
@Override
public PsiElement getElementToHighlight() {
GrNewExpression call = getCall();
GrArgumentList argList = call.getArgumentList();
if (argList != null)
return argList;
GrCodeReferenceElement ref = call.getReferenceElement();
if (ref != null)
return ref;
throw new IncorrectOperationException("reference of new expression should exist if it is a constructor call");
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class CustomAnnotationChecker method isAnnotationApplicable.
@Nullable
public static String isAnnotationApplicable(@NotNull GrAnnotation annotation, @Nullable PsiAnnotationOwner owner) {
if (!(owner instanceof PsiElement))
return null;
PsiElement ownerToUse = owner instanceof PsiModifierList ? ((PsiElement) owner).getParent() : (PsiElement) owner;
PsiAnnotation.TargetType[] elementTypeFields = GrAnnotationImpl.getApplicableElementTypeFields(ownerToUse);
if (elementTypeFields.length != 0 && !GrAnnotationImpl.isAnnotationApplicableTo(annotation, elementTypeFields)) {
String annotationTargetText = JavaErrorMessages.message("annotation.target." + elementTypeFields[0]);
GrCodeReferenceElement ref = annotation.getClassReference();
return JavaErrorMessages.message("annotation.not.applicable", ref.getText(), annotationTargetText);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement in project intellij-community by JetBrains.
the class ChangeExtendsImplementsQuickFix method collectRefs.
private static void collectRefs(GrCodeReferenceElement[] refs, Collection<String> classes, Collection<String> interfaces, Collection<String> unknown) {
for (GrCodeReferenceElement ref : refs) {
final PsiElement extendsElement = ref.resolve();
String canonicalText = ref.getCanonicalText();
if (extendsElement instanceof PsiClass) {
if (((PsiClass) extendsElement).isInterface()) {
interfaces.add(canonicalText);
} else {
classes.add(canonicalText);
}
} else {
unknown.add(canonicalText);
}
}
}
Aggregations