use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class ClashingGettersInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
super.visitTypeDefinition(typeDefinition);
Map<String, PsiMethod> getters = new HashMap<>();
for (PsiMethod method : typeDefinition.getMethods()) {
final String methodName = method.getName();
if (!GroovyPropertyUtils.isSimplePropertyGetter(method))
continue;
final String propertyName = GroovyPropertyUtils.getPropertyNameByGetterName(methodName, true);
final PsiMethod otherGetter = getters.get(propertyName);
if (otherGetter != null && !methodName.equals(otherGetter.getName())) {
final Pair<PsiElement, String> description = getGetterDescription(method);
final Pair<PsiElement, String> otherDescription = getGetterDescription(otherGetter);
if (description.first != null) {
registerError(description.first, description.second, otherDescription.second);
}
if (otherDescription.first != null) {
registerError(otherDescription.first, otherDescription.second, description.second);
}
} else {
getters.put(propertyName, method);
}
}
}
};
}
use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class ChangeToMethodInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitExpression(@NotNull GrExpression expression) {
Transformation<?> transformation = getTransformation(expression);
if (transformation == null)
return;
PsiElement highlightingElement = getHighlightingElement(expression);
if (highlightingElement == null)
return;
if (transformation.couldApplyRow(expression)) {
registerError(highlightingElement, message("replace.with.method.message", transformation.getMethod()), new LocalQuickFix[] { getFix(transformation) }, GENERIC_ERROR_OR_WARNING);
}
}
};
}
use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor 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.codeInspection.BaseInspectionVisitor 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.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class TypeCustomizerInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitFile(@NotNull GroovyFileBase file) {
CompilerConfiguration configuration = CompilerConfiguration.getInstance(file.getProject());
if (configuration != null && !configuration.isResourceFile(file.getVirtualFile()) && fileSeemsToBeTypeCustomizer(file)) {
final LocalQuickFix[] fixes = { new AddToResourceFix(file) };
final String message = GroovyInspectionBundle.message("type.customizer.is.not.marked.as.a.resource.file");
registerError(file, message, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
};
}
Aggregations