From 61f7b58fc5cee15dc0eb280e315358500b4a2a64 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Fri, 16 Jun 2017 14:47:53 +0300 Subject: [PATCH] type migration: use deeply immediate migration type copy instead of original one --- .../typeMigration/TypeMigrationLabeler.java | 6 ++-- .../SmartTypePointerManagerImpl.java | 29 ++++++++++--------- .../impl/source/PsiClassReferenceType.java | 7 ----- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java index 3cfb1c5412b7..b9fd3159c4c4 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationLabeler.java @@ -1073,9 +1073,11 @@ public class TypeMigrationLabeler { myMigrationRoots = new LinkedList<>(); myTypeEvaluator = new TypeEvaluator(myMigrationRoots, this, myProject); - + SmartTypePointerManager smartTypePointerManager = SmartTypePointerManager.getInstance(myProject); for (PsiElement victim : victims) { - addMigrationRoot(victim, myMigrationRootTypeFunction.fun(victim), null, false, true, true); + // use deeply immediate types + PsiType migrationType = smartTypePointerManager.createSmartTypePointer(myMigrationRootTypeFunction.fun(victim)).getType(); + addMigrationRoot(victim, migrationType, null, false, true, true); } if (autoMigrate) { diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java index de96bcf7776a..0b28631e5494 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/smartPointers/SmartTypePointerManagerImpl.java @@ -18,10 +18,8 @@ package com.intellij.psi.impl.smartPointers; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.impl.PsiSubstitutorImpl; -import com.intellij.psi.impl.source.PsiClassReferenceType; import com.intellij.psi.impl.source.PsiImmediateClassType; import com.intellij.psi.util.PsiUtil; -import com.intellij.util.Function; import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; @@ -115,9 +113,9 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager { private static class ClassTypePointer extends TypePointerBase { private final SmartPsiElementPointer myClass; - private final Map myMap; + private final Map, SmartTypePointer> myMap; - public ClassTypePointer(@NotNull PsiClassType type, @NotNull SmartPsiElementPointer aClass, @NotNull Map map) { + public ClassTypePointer(@NotNull PsiClassType type, @NotNull SmartPsiElementPointer aClass, @NotNull Map, SmartTypePointer> map) { super(type); myClass = aClass; myMap = map; @@ -128,10 +126,10 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager { final PsiElement classElement = myClass.getElement(); if (!(classElement instanceof PsiClass)) return null; Map resurrected = new HashMap<>(); - final Set> set = myMap.entrySet(); - for (Map.Entry entry : set) { + final Set, SmartTypePointer>> set = myMap.entrySet(); + for (Map.Entry, SmartTypePointer> entry : set) { PsiElement element = entry.getKey().getElement(); - if (element instanceof PsiTypeParameter) { + if (element != null) { SmartTypePointer typePointer = entry.getValue(); resurrected.put((PsiTypeParameter)element, typePointer == null ? null : typePointer.getType()); } @@ -188,19 +186,22 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager { if (aClass == null) { return createClassReferenceTypePointer(classType); } - if (classType instanceof PsiClassReferenceType) { - classType = ((PsiClassReferenceType)classType).createImmediateCopy(); - } final PsiSubstitutor substitutor = resolveResult.getSubstitutor(); - final HashMap map = new HashMap<>(); + final HashMap, SmartTypePointer> pointerMap = new HashMap<>(); + final Map map = new HashMap<>(); for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) { final PsiType substitutionResult = substitutor.substitute(typeParameter); if (substitutionResult != null) { - final SmartPsiElementPointer pointer = myPsiPointerManager.createSmartPsiElementPointer(typeParameter); - map.put(pointer, substitutionResult.accept(this)); + final SmartPsiElementPointer pointer = myPsiPointerManager.createSmartPsiElementPointer(typeParameter); + SmartTypePointer typePointer = substitutionResult.accept(this); + pointerMap.put(pointer, typePointer); + map.put(typeParameter, typePointer.getType()); } } - return new ClassTypePointer(classType, myPsiPointerManager.createSmartPsiElementPointer(aClass), map); + + return new ClassTypePointer(new PsiImmediateClassType(aClass, PsiSubstitutorImpl.createSubstitutor(map)), + myPsiPointerManager.createSmartPsiElementPointer(aClass), + pointerMap); } @Override diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java index 8a460a3eac80..30fe77f59f5e 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java @@ -217,13 +217,6 @@ public class PsiClassReferenceType extends PsiClassType.Stub { return getReference().getTypeParameters(); } - @NotNull - public PsiClassType createImmediateCopy() { - ClassResolveResult resolveResult = resolveGenerics(); - PsiClass element = resolveResult.getElement(); - return element == null ? this : new PsiImmediateClassType(element, resolveResult.getSubstitutor()); - } - @NotNull @Override public String getPresentableText(boolean annotated) {