mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
process diamonds on safe delete of type parameter (IDEA-73968)
This commit is contained in:
+17
-12
@@ -367,22 +367,27 @@ public class JavaSafeDeleteProcessor implements SafeDeleteProcessorDelegate {
|
||||
private static void findTypeParameterExternalUsages(final PsiTypeParameter typeParameter, final Collection<UsageInfo> usages) {
|
||||
PsiTypeParameterListOwner owner = typeParameter.getOwner();
|
||||
if (owner != null) {
|
||||
final int index = owner.getTypeParameterList().getTypeParameterIndex(typeParameter);
|
||||
final PsiTypeParameterList parameterList = owner.getTypeParameterList();
|
||||
if (parameterList != null) {
|
||||
final int paramsCount = parameterList.getTypeParameters().length;
|
||||
final int index = parameterList.getTypeParameterIndex(typeParameter);
|
||||
|
||||
ReferencesSearch.search(owner).forEach(new Processor<PsiReference>() {
|
||||
public boolean process(final PsiReference reference) {
|
||||
if (reference instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)reference).getParameterList();
|
||||
if (parameterList != null) {
|
||||
PsiTypeElement[] typeArgs = parameterList.getTypeParameterElements();
|
||||
if (typeArgs.length > index) {
|
||||
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(typeArgs[index], typeParameter, true));
|
||||
ReferencesSearch.search(owner).forEach(new Processor<PsiReference>() {
|
||||
public boolean process(final PsiReference reference) {
|
||||
if (reference instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)reference).getParameterList();
|
||||
if (parameterList != null) {
|
||||
PsiTypeElement[] typeArgs = parameterList.getTypeParameterElements();
|
||||
if (typeArgs.length > index) {
|
||||
if (typeArgs.length == 1 && paramsCount > 1 && typeArgs[0].getType() instanceof PsiDiamondType) return true;
|
||||
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(typeArgs[index], typeParameter, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Test<T<caret>T> {}
|
||||
|
||||
class Foo {
|
||||
void test() {
|
||||
Test<String> test = new Test<>();
|
||||
Test<String> test2 = new Test<String>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Test {}
|
||||
|
||||
class Foo {
|
||||
void test() {
|
||||
Test test = new Test();
|
||||
Test test2 = new Test();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Test<<caret>T, U> {}
|
||||
|
||||
class Foo {
|
||||
void test() {
|
||||
Test<String, Long> test = new Test<>();
|
||||
Test<String, Long> test2 = new Test<String, Long>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Test<U> {}
|
||||
|
||||
class Foo {
|
||||
void test() {
|
||||
Test<Long> test = new Test<>();
|
||||
Test<Long> test2 = new Test<Long>();
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,16 @@ public class SafeDeleteTest extends MultiFileTestCase {
|
||||
doSingleFileTest();
|
||||
}
|
||||
|
||||
public void testLastTypeParam() throws Exception {
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
doSingleFileTest();
|
||||
}
|
||||
|
||||
public void testTypeParamFromDiamond() throws Exception {
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
doSingleFileTest();
|
||||
}
|
||||
|
||||
private void doTest(@NonNls final String qClassName) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user