Added auto-importing in JetChangePropertyActions.addTypeAnnotation(). It is used in "specify type explicitly" intention and "introduce variable" refactoring. Corrected auto-importing for cases of nested classes (e.g. Map.Entry).

This commit is contained in:
Evgeny Gerashchenko
2012-04-21 02:39:23 +04:00
parent 32605248c5
commit 82b4304f0e
8 changed files with 68 additions and 24 deletions
@@ -529,6 +529,23 @@ public class TypeUtils {
return null;
}
private static void addAllClassDescriptors(@NotNull JetType type, @NotNull Set<ClassDescriptor> set) {
ClassDescriptor cd = getClassDescriptor(type);
if (cd != null) {
set.add(cd);
}
for (TypeProjection projection : type.getArguments()) {
addAllClassDescriptors(projection.getType(), set);
}
}
@NotNull
public static List<ClassDescriptor> getAllClassDescriptors(@NotNull JetType type) {
Set<ClassDescriptor> classDescriptors = new HashSet<ClassDescriptor>();
addAllClassDescriptors(type, classDescriptors);
return new ArrayList<ClassDescriptor>(classDescriptors);
}
public static boolean hasUnsubstitutedTypeParameters(JetType type) {
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
return true;
@@ -30,10 +30,7 @@ import org.jetbrains.jet.lang.types.Variance;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.*;
/**
* @author abreslav
@@ -122,6 +119,15 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
}
}
private static List<String> getOuterClassesNames(ClassDescriptor cd) {
ArrayList<String> result = new ArrayList<String>();
while (cd.getContainingDeclaration() instanceof ClassifierDescriptor) {
result.add(cd.getName());
cd = (ClassDescriptor)cd.getContainingDeclaration();
}
return result;
}
private String renderDefaultType(JetType type, boolean shortNamesOnly) {
StringBuilder sb = new StringBuilder();
ClassifierDescriptor cd = type.getConstructor().getDeclarationDescriptor();
@@ -132,7 +138,18 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
typeNameObject = type.getConstructor();
}
else {
typeNameObject = shortNamesOnly ? cd.getName() : DescriptorUtils.getFQName(cd);
if (shortNamesOnly) {
// for nested classes qualified name should be used
typeNameObject = cd.getName();
DeclarationDescriptor parent = cd.getContainingDeclaration();
while (parent instanceof ClassDescriptor) {
typeNameObject = parent.getName() + "." + typeNameObject;
parent = parent.getContainingDeclaration();
}
}
else {
typeNameObject = DescriptorUtils.getFQName(cd);
}
}
sb.append(typeNameObject);