mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
[java-inspection] IDEA-379322 Pattern conversion is suggested when the record variable is used
GitOrigin-RevId: d1d378f0264d23227afbadcb11ec4f2f8c2dcf49
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2e21c8f3ce
commit
c3826e657d
+1
-4
@@ -66,16 +66,13 @@ public final class DeconstructionCanBeUsedInspection extends AbstractBaseJavaLoc
|
||||
continue;
|
||||
}
|
||||
PsiRecordComponent component = getComponent(reference);
|
||||
if (component == null) continue;
|
||||
if (component == null) return Collections.emptyList();
|
||||
if (!used.add(component) && !shouldFindAll) continue;
|
||||
PsiElementFactory factory = PsiElementFactory.getInstance(reference.getProject());
|
||||
PsiExpression call = factory.createExpressionFromText(reference.getText() + "." + component.getName() + "()", reference);
|
||||
if (SideEffectChecker.mayHaveSideEffects(call)) return Collections.emptyList();
|
||||
int index = ArrayUtil.indexOf(components, component);
|
||||
result.get(index).add((PsiReferenceExpression)PsiUtil.skipParenthesizedExprUp(reference.getParent()));
|
||||
if (!shouldFindAll && used.size() == components.length) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return used.size() == components.length ? result : Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace with record pattern" "false"
|
||||
class X {
|
||||
record R(String oldText, String newText) {
|
||||
}
|
||||
|
||||
void patternBug(Object obj) {
|
||||
if (obj instanceof R<caret> r) {
|
||||
System.out.println(r.oldText());
|
||||
System.out.println(r.newText());
|
||||
System.out.println(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user