mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-300046 add pattern usage type for java patterns
GitOrigin-RevId: 8fce1a459ef4d18c6f5aef44eb4988b1770a6ffa
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8d81cdcef7
commit
29f21baf4a
@@ -142,6 +142,10 @@ public final class JavaUsageTypeProvider implements UsageTypeProviderEx {
|
||||
return UsageType.ANNOTATION;
|
||||
}
|
||||
|
||||
if (element.getParent() instanceof PsiTypeElement && element.getParent().getParent() instanceof PsiPattern) {
|
||||
return UsageType.PATTERN;
|
||||
}
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(element, PsiImportStatementBase.class, false) != null) return UsageType.CLASS_IMPORT;
|
||||
PsiReferenceList referenceList = PsiTreeUtil.getParentOfType(element, PsiReferenceList.class);
|
||||
if (referenceList != null) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
record Rec(int x, String s) {
|
||||
void foo(Object o) {
|
||||
if (o instanceof <caret>Rec(int patternX, String s) r) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
record Rec(int x, String s) {
|
||||
void foo(Object o) {
|
||||
switch (o) {
|
||||
case <caret>Rec(int patternX, String s) -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,16 @@ public class JavaUsageTypeProviderTest extends LightJavaCodeInsightFixtureTestCa
|
||||
assertUsageType(UsageType.CLASS_PERMITS_LIST, myFixture.findClass("Foo"));
|
||||
}
|
||||
|
||||
public void testPatternInSwitch() {
|
||||
myFixture.configureByFiles("PatternInSwitch.java");
|
||||
assertUsageType(UsageType.PATTERN, myFixture.findClass("Rec"));
|
||||
}
|
||||
|
||||
public void testPatternInInstanceof() {
|
||||
myFixture.configureByFiles("PatternInInstanceof.java");
|
||||
assertUsageType(UsageType.PATTERN, myFixture.findClass("Rec"));
|
||||
}
|
||||
|
||||
private void assertUsageType(UsageType expected, PsiClass target) {
|
||||
UsageTarget[] targets = {new PsiElement2UsageTargetAdapter(target)};
|
||||
PsiElement element = myFixture.getReferenceAtCaretPositionWithAssertion().getElement();
|
||||
|
||||
@@ -61,6 +61,7 @@ usage.type.new.anonymous=New anonymous inheritor creation
|
||||
usage.type.new.array=New array creation
|
||||
usage.type.annotation=Annotation
|
||||
usage.type.type.parameter=Type parameter
|
||||
usage.type.type.pattern=Pattern
|
||||
usage.type.read=Value read
|
||||
usage.type.write=Value write
|
||||
preview.usages.action.text=Preview Source
|
||||
|
||||
@@ -29,6 +29,7 @@ public final class UsageType {
|
||||
public static final UsageType CLASS_NEW_ARRAY = new UsageType(UsageViewBundle.messagePointer("usage.type.new.array"));
|
||||
public static final UsageType ANNOTATION = new UsageType(UsageViewBundle.messagePointer("usage.type.annotation"));
|
||||
public static final UsageType TYPE_PARAMETER = new UsageType(UsageViewBundle.messagePointer("usage.type.type.parameter"));
|
||||
public static final UsageType PATTERN = new UsageType(UsageViewBundle.messagePointer("usage.type.type.parameter"));
|
||||
|
||||
public static final UsageType READ = new UsageType(UsageViewBundle.messagePointer("usage.type.read"));
|
||||
public static final UsageType WRITE = new UsageType(UsageViewBundle.messagePointer("usage.type.write"));
|
||||
|
||||
Reference in New Issue
Block a user