Introduced getFqNameSafe method.

This commit is contained in:
Evgeny Gerashchenko
2013-12-04 18:51:06 +04:00
parent 3352d8a954
commit a49551dd35
22 changed files with 50 additions and 37 deletions
@@ -109,7 +109,7 @@ public class RangeCodegenUtil {
// Must be a standard library class
return null;
}
return map.get(DescriptorUtils.getFqName(declarationDescriptor).toSafe());
return map.get(DescriptorUtils.getFqNameSafe(declarationDescriptor));
}
public static boolean isOptimizableRangeTo(CallableDescriptor rangeTo) {
@@ -135,7 +135,7 @@ public class SamWrapperCodegen extends ParentCodegenAwareImpl {
FqName packageClassFqName = PackageClassUtils.getPackageClassFqName(JetPsiUtil.getFQName(containingFile));
String packageInternalName = JvmClassName.byFqNameWithoutInnerClasses(packageClassFqName).getInternalName();
return packageInternalName + "$sam$" + samInterface.getName().asString() + "$" +
Integer.toHexString(CodegenUtil.getPathHashCode(containingFile.getVirtualFile()) * 31 + DescriptorUtils.getFqName(
Integer.toHexString(CodegenUtil.getPathHashCode(containingFile.getVirtualFile()) * 31 + DescriptorUtils.getFqNameSafe(
samInterface).hashCode());
}
}
@@ -138,7 +138,7 @@ public class IntrinsicMethods {
declareIntrinsicProperty(Name.identifier("CharSequence"), Name.identifier("length"), new StringLength());
declareIntrinsicProperty(Name.identifier("String"), Name.identifier("length"), new StringLength());
registerStaticField(getFqName(KotlinBuiltIns.getInstance().getUnit()).toSafe(), Name.identifier("VALUE"));
registerStaticField(getFqNameSafe(KotlinBuiltIns.getInstance().getUnit()), Name.identifier("VALUE"));
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
FqName rangeClassFqName = RangeCodegenUtil.getRangeClassFqName(type);
@@ -282,7 +282,7 @@ public class SignaturesPropagationData {
for (JetType supertype : TypeUtils.getAllSupertypes(containingClass.getDefaultType())) {
ClassifierDescriptor klass = supertype.getConstructor().getDeclarationDescriptor();
assert klass != null;
FqName fqName = DescriptorUtils.getFqName(klass).toSafe();
FqName fqName = DescriptorUtils.getFqNameSafe(klass);
for (FunctionDescriptor fun : klass.getDefaultType().getMemberScope().getFunctions(functionName)) {
CallableMemberDescriptor.Kind kind = fun.getKind();
@@ -98,7 +98,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
}
private JetType visitCommonType(@NotNull ClassDescriptor classDescriptor, @NotNull JetTypeElement type) {
return visitCommonType(DescriptorUtils.getFqName(classDescriptor).toSafe().asString(), type);
return visitCommonType(DescriptorUtils.getFqNameSafe(classDescriptor).asString(), type);
}
@NotNull
@@ -109,7 +109,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
TypeConstructor originalTypeConstructor = originalType.getConstructor();
ClassifierDescriptor declarationDescriptor = originalTypeConstructor.getDeclarationDescriptor();
assert declarationDescriptor != null;
FqName originalClassFqName = DescriptorUtils.getFqName(declarationDescriptor).toSafe();
FqName originalClassFqName = DescriptorUtils.getFqNameSafe(declarationDescriptor);
ClassDescriptor classFromLibrary = getAutoTypeAnalogWithinBuiltins(originalClassFqName, qualifiedName);
if (!isSameName(qualifiedName, originalClassFqName.asString()) && classFromLibrary == null) {
throw new AlternativeSignatureMismatchException("Alternative signature type mismatch, expected: %s, actual: %s",
@@ -97,9 +97,7 @@ public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
@Override
protected void register(@NotNull Class<?> javaClass, @NotNull ClassDescriptor kotlinDescriptor, @NotNull Direction direction) {
if (direction == Direction.BOTH || direction == Direction.KOTLIN_TO_JAVA) {
FqNameUnsafe fqNameUnsafe = DescriptorUtils.getFqName(kotlinDescriptor);
assert fqNameUnsafe.isSafe() : "FQ name of a mapped class should be safe: " + fqNameUnsafe;
FqName fqName = fqNameUnsafe.toSafe();
FqName fqName = DescriptorUtils.getFqNameSafe(kotlinDescriptor);
register(fqName, AsmTypeConstants.getType(javaClass));
registerFqName(fqName, new FqName(javaClass.getCanonicalName()));
}
@@ -402,7 +402,7 @@ public class QualifiedExpressionResolver {
}
if (packageView != null && classDescriptor != null) {
if (DescriptorUtils.getFqName(packageView).equalsTo(DescriptorUtils.getFqName(classDescriptor))) {
if (packageView.getFqName().equalsTo(DescriptorUtils.getFqName(classDescriptor))) {
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classDescriptor);
trace.record(BindingContext.RESOLUTION_SCOPE, referenceExpression, resolutionScope);
checkVisibility(classDescriptor, trace, referenceExpression, scopeToCheckVisibility);
@@ -47,7 +47,7 @@ public class LazyPackageMemberScope extends AbstractLazyMemberScope<PackageFragm
@Override
public ClassifierDescriptor getClassifier(@NotNull Name name) {
// TODO: creating an FqName every time may be a performance problem
Name actualName = resolveSession.resolveClassifierAlias(DescriptorUtils.getFqName(thisDescriptor).toSafe(), name);
Name actualName = resolveSession.resolveClassifierAlias(DescriptorUtils.getFqNameSafe(thisDescriptor), name);
return super.getClassifier(actualName);
}
@@ -188,7 +188,7 @@ public class JdkAnnotationsValidityTest extends UsefulTestCase {
@Override
public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
// skip java.util.Collection, etc.
if (!JavaToKotlinClassMap.getInstance().mapPlatformClass(DescriptorUtils.getFqName(descriptor).toSafe()).isEmpty()) {
if (!JavaToKotlinClassMap.getInstance().mapPlatformClass(DescriptorUtils.getFqNameSafe(descriptor)).isEmpty()) {
return null;
}
@@ -38,7 +38,7 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
import java.util.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqNameSafe;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isEnumClassObject;
public final class DescriptorResolverUtils {
@@ -338,7 +338,7 @@ public final class DescriptorResolverUtils {
"java class " + javaClass + " is under non-java fragment: " + packageFragment;
JavaPackageFragmentProvider provider = ((JavaPackageFragmentDescriptor) packageFragment).getProvider();
return provider.getOrCreatePackage(getFqName(javaClass).toSafe());
return provider.getOrCreatePackage(getFqNameSafe(javaClass));
}
public static boolean isJavaClassVisibleAsPackage(@NotNull JavaClass javaClass) {
@@ -110,19 +110,37 @@ public class DescriptorUtils {
@NotNull
public static FqNameUnsafe getFqName(@NotNull DeclarationDescriptor descriptor) {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
FqName safe = getFqNameSafeIfPossible(descriptor);
return safe != null ? safe.toUnsafe() : getFqNameUnsafe(descriptor);
}
@NotNull
public static FqName getFqNameSafe(@NotNull DeclarationDescriptor descriptor) {
FqName safe = getFqNameSafeIfPossible(descriptor);
return safe != null ? safe : getFqNameUnsafe(descriptor).toSafe();
}
@Nullable
private static FqName getFqNameSafeIfPossible(@NotNull DeclarationDescriptor descriptor) {
if (descriptor instanceof ModuleDescriptor || ErrorUtils.isError(descriptor)) {
return FqName.ROOT.toUnsafe();
return FqName.ROOT;
}
if (descriptor instanceof PackageViewDescriptor) {
return ((PackageViewDescriptor) descriptor).getFqName().toUnsafe();
return ((PackageViewDescriptor) descriptor).getFqName();
}
else if (descriptor instanceof PackageFragmentDescriptor) {
return ((PackageFragmentDescriptor) descriptor).getFqName().toUnsafe();
return ((PackageFragmentDescriptor) descriptor).getFqName();
}
return null;
}
@NotNull
private static FqNameUnsafe getFqNameUnsafe(@NotNull DeclarationDescriptor descriptor) {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.CLASS_OBJECT) {
DeclarationDescriptor classOfClassObject = containingDeclaration.getContainingDeclaration();
assert classOfClassObject != null;
@@ -310,7 +310,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
ClassDescriptor annotationClass = (ClassDescriptor) annotation.getType().getConstructor().getDeclarationDescriptor();
assert annotationClass != null;
if (!excludedAnnotationClasses.contains(DescriptorUtils.getFqName(annotationClass).toSafe())) {
if (!excludedAnnotationClasses.contains(DescriptorUtils.getFqNameSafe(annotationClass))) {
builder.append(renderType(annotation.getType()));
if (verbose) {
builder.append("(").append(StringUtil.join(DescriptorUtils.getSortedValueArguments(annotation, this), ", ")).append(")");
@@ -228,7 +228,7 @@ public class GenerateJavaToKotlinMethodMap {
private void appendBeforeClass(@NotNull ClassDescriptor kotlinClass, @NotNull PsiClass psiClass) {
String psiFqName = psiClass.getQualifiedName();
String kotlinFqName = DescriptorUtils.getFqName(kotlinClass).toSafe().asString();
String kotlinFqName = DescriptorUtils.getFqNameSafe(kotlinClass).asString();
assert kotlinFqName.startsWith(BUILTINS_FQNAME_PREFIX);
String kotlinSubQualifiedName = kotlinFqName.substring(BUILTINS_FQNAME_PREFIX.length());
@@ -71,7 +71,7 @@ public class ReferenceToClassesShortening {
compactReferenceToClass(userType, targetClass);
}
else if (classifier == null) {
ImportInsertHelper.addImportDirectiveIfNeeded(DescriptorUtils.getFqName(targetTopLevelClass).toSafe(), file);
ImportInsertHelper.addImportDirectiveIfNeeded(DescriptorUtils.getFqNameSafe(targetTopLevelClass), file);
compactReferenceToClass(userType, targetClass);
}
else {
@@ -54,7 +54,7 @@ public class JetClassInsertHandler implements InsertHandler<LookupElement> {
DeclarationDescriptor descriptor = lookupObject.getDescriptor();
PsiElement targetElement = lookupObject.getPsiElement();
if (descriptor != null) {
FqName fqn = DescriptorUtils.getFqName(descriptor).toSafe();
FqName fqn = DescriptorUtils.getFqNameSafe(descriptor);
// TODO: Find out the way for getting psi element for JS libs
if (targetElement != null) {
@@ -177,7 +177,7 @@ public class JetFunctionInsertHandler(val caretPosition : CaretPosition, val bra
if (DescriptorUtils.isTopLevelDeclaration(functionDescriptor)) {
ApplicationManager.getApplication()?.runWriteAction {
val fqn = DescriptorUtils.getFqName(functionDescriptor).toSafe()
val fqn = DescriptorUtils.getFqNameSafe(functionDescriptor)
ImportInsertHelper.addImportDirectiveIfNeeded(fqn, file)
}
}
@@ -183,9 +183,7 @@ public class JetImportOptimizer implements ImportOptimizer {
private void addResolvedCallFqName(@Nullable ResolvedCall resolvedCall) {
if (resolvedCall != null) {
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
FqNameUnsafe name = DescriptorUtils.getFqName(resultingDescriptor);
assert name.isSafe(): "FqName for resulting descriptor should be safe " + resultingDescriptor.getName();
usedQualifiedNames.add(name.toSafe());
usedQualifiedNames.add(DescriptorUtils.getFqNameSafe(resultingDescriptor));
}
}
});
@@ -163,10 +163,8 @@ public class IdeRenderers {
stringBuilder.append(parametersToHighlight.contains(null) ? String.format(RED_TEMPLATE, ")") : ")");
stringBuilder.append(" <i>defined in</i> ");
DeclarationDescriptor containingDeclaration = funDescriptor.getContainingDeclaration();
if (containingDeclaration != null) {
FqNameUnsafe fqName = DescriptorUtils.getFqName(containingDeclaration);
stringBuilder.append(FqName.ROOT.equalsTo(fqName) ? "root package" : fqName.asString());
}
FqNameUnsafe fqName = DescriptorUtils.getFqName(containingDeclaration);
stringBuilder.append(FqName.ROOT.equalsTo(fqName) ? "root package" : fqName.asString());
stringBuilder.append("</li>");
}
return stringBuilder.toString();
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
import java.util.Set;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqNameSafe;
public final class DecompiledNavigationUtils {
@@ -120,7 +121,7 @@ public final class DecompiledNavigationUtils {
if (classKind == ClassKind.CLASS_OBJECT || classKind == ClassKind.ENUM_ENTRY) {
return getContainerFqName(containerDescriptor.getContainingDeclaration());
}
return getFqName(containerDescriptor).toSafe();
return getFqNameSafe(containerDescriptor);
}
return null;
}
@@ -125,7 +125,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
@Override
public FqName apply(@Nullable DeclarationDescriptor declarationDescriptor) {
assert declarationDescriptor != null;
return DescriptorUtils.getFqName(declarationDescriptor).toSafe();
return DescriptorUtils.getFqNameSafe(declarationDescriptor);
}
}));
}
@@ -152,7 +152,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
@Override
public FqName apply(@Nullable DeclarationDescriptor declarationDescriptor) {
assert declarationDescriptor != null;
return DescriptorUtils.getFqName(declarationDescriptor).toSafe();
return DescriptorUtils.getFqNameSafe(declarationDescriptor);
}
}));
}
@@ -219,7 +219,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
return Collections2.transform(descriptors, new Function<ClassDescriptor, FqName>() {
@Override
public FqName apply(ClassDescriptor descriptor) {
return DescriptorUtils.getFqName(descriptor).toSafe();
return DescriptorUtils.getFqNameSafe(descriptor);
}
});
}
@@ -138,7 +138,7 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
return ((ClassDescriptor) currentParent).getClassObjectDescriptor();
}
else {
return bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFqName(originalDescriptor).toSafe());
return bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFqNameSafe(originalDescriptor));
}
}
@@ -41,7 +41,7 @@ import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName;
public final class JsDescriptorUtils {
// TODO: maybe we should use external annotations or something else.
private static final Set<String> FAKE_CLASSES = ContainerUtil.immutableSet(
getFqName(KotlinBuiltIns.getInstance().getAny()).toSafe().asString(),
getFqNameSafe(KotlinBuiltIns.getInstance().getAny()).asString(),
"jet.Iterable"
);
@@ -82,7 +82,7 @@ public final class JsDescriptorUtils {
@Override
public boolean value(JetType type) {
ClassDescriptor classDescriptor = getClassDescriptorForType(type);
return !FAKE_CLASSES.contains(getFqName(classDescriptor).toSafe().asString());
return !FAKE_CLASSES.contains(getFqNameSafe(classDescriptor).asString());
}
});
}