[java-inspections] 'Remove pattern variable' fix is available on deconstruction pattern component but produces red code

IDEA-298527

GitOrigin-RevId: 32645ea4938384d31bbe4750c3867e3b00f3fafe
This commit is contained in:
Andrey.Cherkasov
2022-08-29 17:01:12 +04:00
committed by intellij-monorepo-bot
parent 1252088717
commit 1c7aea69ba
8 changed files with 52 additions and 2 deletions

View File

@@ -425,13 +425,13 @@ class PostHighlightingVisitor {
return highlightInfo;
}
}
else if (parameter instanceof PsiPatternVariable) {
else if (parameter instanceof PsiPatternVariable variable) {
HighlightInfo highlightInfo = checkUnusedParameter(parameter, identifier, null);
if (highlightInfo != null) {
if (declarationScope.getParent() instanceof PsiSwitchBlock) {
QuickFixAction.registerQuickFixAction(highlightInfo, quickFixFactory.createRenameToIgnoredFix(parameter, false));
}
else {
else if (!(variable.getPattern() instanceof PsiTypeTestPattern pattern && pattern.getParent() instanceof PsiDeconstructionList)) {
QuickFixAction.registerQuickFixAction(highlightInfo, quickFixFactory.createDeleteFix(parameter));
}
return highlightInfo;

View File

@@ -0,0 +1,10 @@
// "Remove pattern variable" "true-preview"
class Test {
record Point(double x, double y) {}
record Rect(Point point1, Point point2) {}
void foo(Object obj) {
if (obj instanceof Rect(Point(double x, double y) point1, Point point2)) {}
}
}

View File

@@ -0,0 +1,10 @@
// "Remove pattern variable" "true-preview"
class Test {
record Point(double x, double y) {}
record Rect(Point point1, Point point2) {}
void foo(Object obj) {
if (obj instanceof Rect(Point(double x, double y), Point point2) rect) {}
}
}

View File

@@ -0,0 +1,10 @@
// "Remove pattern variable" "true-preview"
class Test {
record Point(double x, double y) {}
record Rect(Point point1, Point point2) {}
void foo(Object obj) {
if (obj instanceof Rect(Point(double x, double y) point1, Point point2) rect<caret>) {}
}
}

View File

@@ -0,0 +1,10 @@
// "Remove pattern variable" "true-preview"
class Test {
record Point(double x, double y) {}
record Rect(Point point1, Point point2) {}
void foo(Object obj) {
if (obj instanceof Rect(Point(double x, double y) point1<caret>, Point point2) rect) {}
}
}

View File

@@ -0,0 +1,10 @@
// "Remove pattern variable" "false"
class Test {
record Point(double x, double y) {}
record Rect(Point point1, Point point2) {}
void foo(Object obj) {
if (obj instanceof Rect(Point(double x<caret>, double y) point1, Point point2) rect) {}
}
}