use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class JavaStylePropertiesInvocationInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitMethodCallExpression(@NotNull GrMethodCallExpression methodCallExpression) {
super.visitMethodCallExpression(methodCallExpression);
visitMethodCall(methodCallExpression);
}
@Override
public void visitApplicationStatement(@NotNull GrApplicationStatement applicationStatement) {
super.visitApplicationStatement(applicationStatement);
visitMethodCall(applicationStatement);
}
private void visitMethodCall(GrMethodCall methodCall) {
if (JavaStylePropertiesUtil.isPropertyAccessor(methodCall)) {
final String message = GroovyInspectionBundle.message("java.style.property.access");
final GrExpression expression = methodCall.getInvokedExpression();
if (expression instanceof GrReferenceExpression) {
PsiElement referenceNameElement = ((GrReferenceExpression) expression).getReferenceNameElement();
registerError(referenceNameElement, message, myFixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
}
};
}
use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class ClashingTraitMethodsInspectionBase method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
super.visitTypeDefinition(typeDefinition);
List<PsiClass> superTraits = collectImplementedTraits(typeDefinition);
if (superTraits.size() < 2)
return;
List<ClashingMethod> clashingMethods = collectClassingMethods(typeDefinition);
for (ClashingMethod clashing : clashingMethods) {
registerError(typeDefinition.getNameIdentifierGroovy(), buildWarning(clashing), new LocalQuickFix[] { getFix() }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
@NotNull
private String buildWarning(@NotNull ClashingMethod entry) {
return "Traits " + buildTraitString(entry) + " contain clashing methods with signature " + buildSignatureString(entry);
}
@NotNull
private String buildSignatureString(@NotNull ClashingMethod entry) {
HierarchicalMethodSignature signature = entry.getSignature();
return PsiFormatUtil.formatMethod(signature.getMethod(), signature.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
}
@NotNull
private String buildTraitString(@NotNull ClashingMethod entry) {
return StringUtil.join(entry.getSuperTraits(), tr -> tr.getName(), ", ");
}
};
}
use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class GrDeprecatedAPIUsageInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression ref) {
super.visitReferenceExpression(ref);
checkRef(ref);
}
@Override
public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement ref) {
super.visitCodeReferenceElement(ref);
checkRef(ref);
}
private void checkRef(GrReferenceElement ref) {
PsiElement resolved = ref.resolve();
if (isDeprecated(resolved)) {
PsiElement toHighlight = getElementToHighlight(ref);
registerError(toHighlight, GroovyBundle.message("0.is.deprecated", ref.getReferenceName()), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.LIKE_DEPRECATED);
}
}
@NotNull
public PsiElement getElementToHighlight(@NotNull GrReferenceElement refElement) {
final PsiElement refNameElement = refElement.getReferenceNameElement();
return refNameElement != null ? refNameElement : refElement;
}
private boolean isDeprecated(PsiElement resolved) {
if (resolved instanceof PsiDocCommentOwner) {
return ((PsiDocCommentOwner) resolved).isDeprecated();
}
if (resolved instanceof PsiModifierListOwner && PsiImplUtil.isDeprecatedByAnnotation((PsiModifierListOwner) resolved)) {
return true;
}
return false;
}
};
}
use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class GrPackageInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitFile(@NotNull GroovyFileBase file) {
if (!(file instanceof GroovyFile))
return;
if (!myCheckScripts && file.isScript())
return;
String expectedPackage = ExpectedPackageNameProviderKt.inferExpectedPackageName((GroovyFile) file);
String actual = file.getPackageName();
if (!expectedPackage.equals(actual)) {
PsiElement toHighlight = getElementToHighlight((GroovyFile) file);
if (toHighlight == null)
return;
registerError(toHighlight, "Package name mismatch. Actual: '" + actual + "', expected: '" + expectedPackage + "'", new LocalQuickFix[] { new ChangePackageQuickFix(expectedPackage), GroovyQuickFixFactory.getInstance().createGrMoveToDirFix(actual) }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
};
}
use of org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor in project intellij-community by JetBrains.
the class GrReassignedInClosureLocalVarInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) {
super.visitReferenceExpression(referenceExpression);
if (!PsiUtil.isLValue(referenceExpression))
return;
final PsiElement resolved = referenceExpression.resolve();
if (!PsiUtil.isLocalVariable(resolved))
return;
final PsiType checked = GrReassignedLocalVarsChecker.getReassignedVarType(referenceExpression, false);
if (checked == null)
return;
final GrControlFlowOwner varFlowOwner = ControlFlowUtils.findControlFlowOwner(resolved);
final GrControlFlowOwner refFlorOwner = ControlFlowUtils.findControlFlowOwner(referenceExpression);
if (isOtherScopeAndType(referenceExpression, checked, varFlowOwner, refFlorOwner)) {
String flowDescription = getFlowDescription(refFlorOwner);
final String message = GroovyInspectionBundle.message("local.var.0.is.reassigned", ((GrNamedElement) resolved).getName(), flowDescription);
registerError(referenceExpression, message, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
};
}
Aggregations