[java-inspections] DuplicateExpressions: recognize stable methods from GetterDescriptor; add some methods from java.io.File

Fixes to some extent IDEA-114778 IntelliJ: add "locate multiple occurrence"

GitOrigin-RevId: a20d9db31a79cdc963075993a09a6a6115947621
This commit is contained in:
Tagir Valeev
2024-09-02 17:38:09 +02:00
committed by intellij-monorepo-bot
parent cb1b1c7f61
commit 3c7271ac4e
2 changed files with 7 additions and 1 deletions

View File

@@ -36,7 +36,9 @@ public final class GetterDescriptor extends PsiVarDescriptor {
CallMatcher.instanceCall("java.lang.reflect.Method", "getReturnType"),
CallMatcher.instanceCall(CommonClassNames.JAVA_LANG_CLASS, "getName", "isInterface", "isArray", "isPrimitive", "isSynthetic",
"isAnonymousClass", "isLocalClass", "isMemberClass", "getDeclaringClass", "getEnclosingClass",
"getSimpleName", "getCanonicalName")
"getSimpleName", "getCanonicalName"),
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getName", "getParent", "getPath", "getAbsolutePath",
"getParentFile", "getAbsoluteFile", "toPath")
);
private final @NotNull PsiMethod myGetter;
private final boolean myStable;

View File

@@ -2,6 +2,7 @@
package com.intellij.codeInspection.duplicateExpressions;
import com.intellij.codeInspection.dataFlow.CommonDataflow;
import com.intellij.codeInspection.dataFlow.jvm.descriptors.GetterDescriptor;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.containers.ContainerUtil;
@@ -182,6 +183,9 @@ final class SideEffectCalculator {
if ("java.nio.file.Paths".equals(className)) {
return !"get".equals(method.getName());
}
if (method.getParameterList().getParametersCount() == 0 && new GetterDescriptor(method).isStable()) {
return false;
}
return true;
}