mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Improve the inspection "Multiple occurrences of the same expression" (IDEA-207247)
This commit is contained in:
+4
-4
@@ -145,16 +145,16 @@ class SideEffectCalculator {
|
||||
PsiClass psiClass = method.getContainingClass();
|
||||
if (psiClass == null) return true;
|
||||
|
||||
if (ClassUtils.isImmutableClass(psiClass) ||
|
||||
MethodUtils.isEquals(method) ||
|
||||
String className = psiClass.getQualifiedName();
|
||||
if (MethodUtils.isEquals(method) ||
|
||||
MethodUtils.isHashCode(method) ||
|
||||
MethodUtils.isToString(method) ||
|
||||
MethodUtils.isCompareTo(method) ||
|
||||
MethodUtils.isComparatorCompare(method)) {
|
||||
MethodUtils.isComparatorCompare(method) ||
|
||||
ClassUtils.isImmutableClass(psiClass) && !JAVA_IO_FILE.equals(className)) { // methods of File have or are sensitive to side effects
|
||||
return false;
|
||||
}
|
||||
|
||||
String className = psiClass.getQualifiedName();
|
||||
if (JAVA_UTIL_OBJECTS.equals(className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.io.*;
|
||||
|
||||
class C {
|
||||
void testConstructor(String path) {
|
||||
File a = <weak_warning descr="Multiple occurrences of 'new File(path)'">new File(path)</weak_warning>;
|
||||
File b = <weak_warning descr="Multiple occurrences of 'new File(path)'">new File(path)</weak_warning>;
|
||||
}
|
||||
|
||||
void testMethods(String path) throws IOException {
|
||||
File f = new File(path);
|
||||
|
||||
boolean a = f.createNewFile();
|
||||
boolean b = f.createNewFile();
|
||||
|
||||
boolean c = f.delete();
|
||||
boolean d = f.delete();
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ class DuplicateExpressionsTest : LightCodeInsightFixtureTestCase() {
|
||||
fun testMathRandom() = doTest(1)
|
||||
fun testVariable() = doTest(1)
|
||||
fun testLambda() = doTest(20)
|
||||
fun testFile() = doTest(1)
|
||||
|
||||
private fun doTest(threshold: Int = 50) {
|
||||
val oldThreshold = inspection.complexityThreshold
|
||||
|
||||
Reference in New Issue
Block a user