mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
JavaUsageTypeProvider: add special UsageType for permits clause: IDEA-243891
GitOrigin-RevId: bba4d7a50ee91aaf3c1e2ead2d0b56d48f7ba1ed
This commit is contained in:
committed by
intellij-monorepo-bot
parent
452bcc203e
commit
ae1bd43e87
@@ -151,7 +151,10 @@ public class JavaUsageTypeProvider implements UsageTypeProviderEx {
|
||||
if (PsiTreeUtil.getParentOfType(element, PsiImportStatementBase.class, false) != null) return UsageType.CLASS_IMPORT;
|
||||
PsiReferenceList referenceList = PsiTreeUtil.getParentOfType(element, PsiReferenceList.class);
|
||||
if (referenceList != null) {
|
||||
if (referenceList.getParent() instanceof PsiClass) return UsageType.CLASS_EXTENDS_IMPLEMENTS_LIST;
|
||||
if (referenceList.getParent() instanceof PsiClass) {
|
||||
if (referenceList.getRole() != PsiReferenceList.Role.PERMITS_LIST) return UsageType.CLASS_EXTENDS_IMPLEMENTS_LIST;
|
||||
return UsageType.CLASS_PERMITS_LIST;
|
||||
}
|
||||
if (referenceList.getParent() instanceof PsiMethod) return UsageType.CLASS_METHOD_THROWS_LIST;
|
||||
}
|
||||
if (PsiTreeUtil.getParentOfType(element, PsiTypeParameterList.class) != null ||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class MethodReferenceConstructor permits <caret>Foo { }
|
||||
|
||||
non-sealed class Foo {}
|
||||
@@ -19,12 +19,19 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import com.intellij.usages.UsageTarget;
|
||||
import com.intellij.usages.impl.rules.JavaUsageTypeProvider;
|
||||
import com.intellij.usages.impl.rules.UsageType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavaUsageTypeProviderTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_15;
|
||||
}
|
||||
|
||||
public void testNestedClassAccess() {
|
||||
myFixture.configureByFiles("NestedClassAccess.java", "Foo.java");
|
||||
assertUsageType(UsageType.CLASS_NESTED_CLASS_ACCESS, myFixture.findClass("Foo"));
|
||||
@@ -55,6 +62,11 @@ public class JavaUsageTypeProviderTest extends LightJavaCodeInsightFixtureTestCa
|
||||
assertUsageType(UsageType.CLASS_NEW_OPERATOR, myFixture.findClass("Foo"));
|
||||
}
|
||||
|
||||
public void testPermitsClause() {
|
||||
myFixture.configureByFiles("PermitsClause.java");
|
||||
assertUsageType(UsageType.CLASS_PERMITS_LIST, myFixture.findClass("Foo"));
|
||||
}
|
||||
|
||||
private void assertUsageType(UsageType expected, PsiClass target) {
|
||||
UsageTarget[] targets = {new PsiElement2UsageTargetAdapter(target)};
|
||||
PsiElement element = myFixture.getReferenceAtCaretPositionWithAssertion().getElement();
|
||||
|
||||
@@ -35,6 +35,7 @@ usage.type.instanceof=Usage in instanceof
|
||||
usage.type.import=Usage in import
|
||||
usage.type.cast.target=Usage in cast target type
|
||||
usage.type.extends=Usage in extends/implements clause
|
||||
usage.type.permits=Usage in permits clause
|
||||
usage.type.static.member=Class static member access
|
||||
usage.type.nested.class=Nested class access
|
||||
usage.type.throws.list=Method throws list
|
||||
|
||||
@@ -15,6 +15,7 @@ public final class UsageType {
|
||||
public static final UsageType CLASS_IMPORT = new UsageType(UsageViewBundle.messagePointer("usage.type.import"));
|
||||
public static final UsageType CLASS_CAST_TO = new UsageType(UsageViewBundle.messagePointer("usage.type.cast.target"));
|
||||
public static final UsageType CLASS_EXTENDS_IMPLEMENTS_LIST = new UsageType(UsageViewBundle.messagePointer("usage.type.extends"));
|
||||
public static final UsageType CLASS_PERMITS_LIST = new UsageType(UsageViewBundle.messagePointer("usage.type.permits"));
|
||||
public static final UsageType CLASS_STATIC_MEMBER_ACCESS = new UsageType(UsageViewBundle.messagePointer("usage.type.static.member"));
|
||||
public static final UsageType CLASS_NESTED_CLASS_ACCESS = new UsageType(UsageViewBundle.messagePointer("usage.type.nested.class"));
|
||||
public static final UsageType CLASS_METHOD_THROWS_LIST = new UsageType(UsageViewBundle.messagePointer("usage.type.throws.list"));
|
||||
|
||||
Reference in New Issue
Block a user