Create from usage: Refactoring.

This commit is contained in:
Jack Zhou
2013-04-19 21:41:37 -04:00
parent 4044aae489
commit fc6c2be73b
@@ -171,7 +171,21 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase {
}
public void substitute(TypeSubstitution[] substitutions) {
cachedTypeCandidates = substituteTypes(cachedTypeCandidates, substitutions, variance);
Set<JetType> newTypes = new LinkedHashSet<JetType>(Arrays.asList(cachedTypeCandidates));
for (TypeSubstitution substitution : substitutions) { // each substitution can be applied or not, so we offer all options
List<JetType> toAdd = new ArrayList<JetType>();
List<JetType> toRemove = new ArrayList<JetType>();
for (JetType type : newTypes) {
toAdd.add(substituteType(type, substitution, variance));
// substitution.byType are type arguments, but they cannot already occur in the type before substitution
if (containsType(type, substitution.getByType())) {
toRemove.add(type);
}
}
newTypes.addAll(toAdd);
newTypes.removeAll(toRemove);
}
cachedTypeCandidates = newTypes.toArray(new JetType[newTypes.size()]);
}
}
@@ -904,25 +918,6 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase {
type.isNullable(), newArguments, type.getMemberScope());
}
@NotNull
private static JetType[] substituteTypes(@NotNull JetType[] types, @NotNull TypeSubstitution[] substitutions, @NotNull Variance variance) {
Set<JetType> newTypes = new LinkedHashSet<JetType>(Arrays.asList(types));
for (TypeSubstitution substitution : substitutions) { // each substitution can be applied or not, so we offer all options
List<JetType> toAdd = new ArrayList<JetType>();
List<JetType> toRemove = new ArrayList<JetType>();
for (JetType type : newTypes) {
toAdd.add(substituteType(type, substitution, variance));
// substitution.byType are type arguments, but they cannot already occur before substitution
if (containsType(type, substitution.getByType())) {
toRemove.add(type);
}
}
newTypes.addAll(toAdd);
newTypes.removeAll(toRemove);
}
return newTypes.toArray(new JetType[newTypes.size()]);
}
private static boolean containsType(JetType outer, JetType inner) {
if (outer.equals(inner)) {
return true;