mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
more inspections to report unsteady local results (IDEA-268840)
GitOrigin-RevId: 07527de7fb57861bc766a879c1abf3ae7de7d1bf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
da59dcf960
commit
64d0132021
+7
@@ -25,6 +25,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BaseInspectionVisitor extends JavaElementVisitor {
|
||||
|
||||
@@ -169,6 +170,12 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor {
|
||||
final String description = inspection.buildErrorString(infos);
|
||||
holder.registerProblem(location, description, highlightType, fixes);
|
||||
}
|
||||
|
||||
protected final void registerPossibleProblem(@Nullable PsiElement element) {
|
||||
if (element != null) {
|
||||
holder.registerPossibleProblem(element);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void registerErrorAtOffset(@NotNull PsiElement location, int offset, int length, Object... infos) {
|
||||
registerErrorAtOffset(location, offset, length, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, infos);
|
||||
|
||||
+2
@@ -130,6 +130,7 @@ public class DeclareCollectionAsInterfaceInspection extends BaseInspection {
|
||||
@Override
|
||||
public void visitVariable(@NotNull PsiVariable variable) {
|
||||
if (isOnTheFly() && DeclarationSearchUtils.isTooExpensiveToSearch(variable, false)) {
|
||||
registerPossibleProblem(variable.getNameIdentifier());
|
||||
return;
|
||||
}
|
||||
if (ignoreLocalVariables && variable instanceof PsiLocalVariable) {
|
||||
@@ -173,6 +174,7 @@ public class DeclareCollectionAsInterfaceInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
if (isOnTheFly() && DeclarationSearchUtils.isTooExpensiveToSearch(method, false)) {
|
||||
registerPossibleProblem(method.getNameIdentifier());
|
||||
return;
|
||||
}
|
||||
final PsiType type = method.getReturnType();
|
||||
|
||||
+4
-3
@@ -70,6 +70,10 @@ public class MethodOnlyUsedFromInnerClassInspection extends BaseInspection {
|
||||
if (method.getNameIdentifier() == null) {
|
||||
return;
|
||||
}
|
||||
if (DeclarationSearchUtils.isTooExpensiveToSearch(method, false)) {
|
||||
registerPossibleProblem(method.getNameIdentifier());
|
||||
return;
|
||||
}
|
||||
final MethodReferenceFinder processor = new MethodReferenceFinder(method);
|
||||
final PsiClass innerClass = processor.getOnlyAccessInnerClass();
|
||||
if (innerClass == null) {
|
||||
@@ -123,9 +127,6 @@ public class MethodOnlyUsedFromInnerClassInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
public PsiClass getOnlyAccessInnerClass() {
|
||||
if (DeclarationSearchUtils.isTooExpensiveToSearch(method, true)) {
|
||||
return null;
|
||||
}
|
||||
ReferencesSearch.search(method).forEach(this);
|
||||
return myContainingClass;
|
||||
}
|
||||
|
||||
+8
-2
@@ -391,7 +391,10 @@ public class StaticMethodOnlyUsedInOneClassInspection extends BaseGlobalInspecti
|
||||
super.visitField(field);
|
||||
if (!field.hasModifierProperty(PsiModifier.STATIC) || field.hasModifierProperty(PsiModifier.PRIVATE)) return;
|
||||
if (field instanceof PsiEnumConstant || isSingletonField(field)) return;
|
||||
if (DeclarationSearchUtils.isTooExpensiveToSearch(field, true)) return;
|
||||
if (DeclarationSearchUtils.isTooExpensiveToSearch(field, false)) {
|
||||
registerPossibleProblem(field.getNameIdentifier());
|
||||
return;
|
||||
}
|
||||
final PsiClass usageClass = getUsageClass(field);
|
||||
if (usageClass == null) return;
|
||||
registerFieldError(field, field, usageClass);
|
||||
@@ -408,7 +411,10 @@ public class StaticMethodOnlyUsedInOneClassInspection extends BaseGlobalInspecti
|
||||
if (MethodUtils.isFactoryMethod(method) || MethodUtils.isConvenienceOverload(method)) {
|
||||
return;
|
||||
}
|
||||
if (DeclarationSearchUtils.isTooExpensiveToSearch(method, true)) return;
|
||||
if (DeclarationSearchUtils.isTooExpensiveToSearch(method, false)) {
|
||||
registerPossibleProblem(method.getNameIdentifier());
|
||||
return;
|
||||
}
|
||||
final PsiClass usageClass = getUsageClass(method);
|
||||
if (usageClass == null) return;
|
||||
registerMethodError(method, method, usageClass);
|
||||
|
||||
Reference in New Issue
Block a user