mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
pull up: postpone type params replacement: substituted types can contain type params from base class with names that exist in current class (IDEA-87543)
This commit is contained in:
@@ -891,6 +891,7 @@ public class RefactoringUtil {
|
||||
final Iterable<PsiTypeParameter> parametersIterable,
|
||||
final PsiSubstitutor substitutor,
|
||||
final PsiElementFactory factory) {
|
||||
final Map<PsiElement, PsiElement> replacement = new LinkedHashMap<PsiElement, PsiElement>();
|
||||
for (PsiTypeParameter parameter : parametersIterable) {
|
||||
PsiType substitutedType = substitutor.substitute(parameter);
|
||||
if (substitutedType == null) {
|
||||
@@ -900,12 +901,17 @@ public class RefactoringUtil {
|
||||
final PsiElement element = reference.getElement();
|
||||
final PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiTypeElement) {
|
||||
parent.replace(factory.createTypeElement(substitutedType));
|
||||
replacement.put(parent, factory.createTypeElement(substitutedType));
|
||||
} else if (element instanceof PsiJavaCodeReferenceElement && substitutedType instanceof PsiClassType) {
|
||||
element.replace(factory.createReferenceElementByType((PsiClassType)substitutedType));
|
||||
replacement.put(element, factory.createReferenceElementByType((PsiClassType)substitutedType));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PsiElement element : replacement.keySet()) {
|
||||
if (element.isValid()) {
|
||||
element.replace(replacement.get(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
interface Bar<T> { }
|
||||
|
||||
interface Base<T> { }
|
||||
|
||||
class Foo<T,U> implements Base<U> {
|
||||
void fo<caret>o(Bar<U> bar) { }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
interface Bar<T> { }
|
||||
|
||||
interface Base<T> {
|
||||
void foo(Bar<T> bar);
|
||||
}
|
||||
|
||||
class Foo<T,U> implements Base<U> {
|
||||
@Override
|
||||
public void foo(Bar<U> bar) { }
|
||||
}
|
||||
@@ -115,6 +115,10 @@ public class PullUpTest extends LightRefactoringTestCase {
|
||||
doTest(false, new RefactoringTestUtil.MemberDescriptor("I", PsiClass.class));
|
||||
}
|
||||
|
||||
public void testTypeParamsConflictingNames() throws Exception {
|
||||
doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class));
|
||||
}
|
||||
|
||||
private void doTest(RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
|
||||
doTest(true, membersToFind);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user