mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use interface where possible: rebind type params (IDEA-139615)
This commit is contained in:
+23
@@ -182,7 +182,14 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
|
||||
if (element != null) {
|
||||
final PsiReference ref = element.getReference();
|
||||
assert ref != null;
|
||||
final PsiElement typeParams = createReferenceTypeParameterList(aSuper, ref);
|
||||
PsiElement newElement = ref.bindToElement(aSuper);
|
||||
if (typeParams != null && newElement instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)newElement).getParameterList();
|
||||
if (parameterList != null) {
|
||||
parameterList.replace(typeParams);
|
||||
}
|
||||
}
|
||||
|
||||
if (newElement.getParent() instanceof PsiTypeElement) {
|
||||
if (newElement.getParent().getParent() instanceof PsiTypeCastExpression) {
|
||||
@@ -194,6 +201,22 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
|
||||
}
|
||||
}
|
||||
|
||||
private static PsiElement createReferenceTypeParameterList(PsiClass aSuper, PsiReference ref) {
|
||||
PsiElement typeParams = null;
|
||||
if (ref instanceof PsiJavaCodeReferenceElement) {
|
||||
final JavaResolveResult result = ((PsiJavaCodeReferenceElement)ref).advancedResolve(false);
|
||||
final PsiElement aClass = result.getElement();
|
||||
if (aClass instanceof PsiClass) {
|
||||
final PsiSubstitutor substitutor =
|
||||
TypeConversionUtil.getSuperClassSubstitutor(aSuper, (PsiClass)aClass, result.getSubstitutor());
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(aClass.getProject());
|
||||
final PsiClassType classType = factory.createType(aSuper, substitutor);
|
||||
typeParams = factory.createReferenceFromText(classType.getCanonicalText(), aClass).getParameterList();
|
||||
}
|
||||
}
|
||||
return typeParams;
|
||||
}
|
||||
|
||||
private static void fixPossiblyRedundantCast(PsiTypeCastExpression cast) throws IncorrectOperationException {
|
||||
PsiTypeElement castTypeElement = cast.getCastType();
|
||||
if (castTypeElement == null) return;
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface SuperBar<T> {
|
||||
void f();
|
||||
}
|
||||
interface Bar<T, S> extends SuperBar<S> {}
|
||||
class Client {
|
||||
void foo(SuperBar<Integer> b) {
|
||||
b.f();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface SuperBar<T> {
|
||||
void f();
|
||||
}
|
||||
interface Bar<T, S> extends SuperBar<S> {}
|
||||
class Client {
|
||||
void foo(Bar<String, Integer> b) {
|
||||
b.f();
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ public class TurnRefsToSuperTest extends MultiFileTestCase {
|
||||
public void testTypeArgumentsParam() throws Exception { doTest("Clazz", "IntF", false); }
|
||||
public void testTryWithResources1() throws Exception { doTest("Test.MyResourceImpl", "Test.MyResource", false); }
|
||||
public void testTryWithResources2() throws Exception { doTest("Test.MyResourceImpl", "Test.MyResource", false); }
|
||||
public void testDifferentNumberOfParams() throws Exception { doTest("Bar", "SuperBar", false); }
|
||||
|
||||
//todo[ann] fix and uncomment
|
||||
//public void testStaticCallArguments() throws Exception { doTest("Impl", "Int", false); }
|
||||
|
||||
Reference in New Issue
Block a user