From ccead8e3372da99d091c4b1351192a2f1c9e8f55 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 16 May 2014 19:38:24 +0400 Subject: [PATCH] Replace some usages of ERROR_CLASS with new instance creation Because when some class is unresolved, we can still hold some information such as its FQ name, for debugging purposes and better error messages --- .../resolve/kotlin/AnnotationDescriptorDeserializer.java | 4 ++-- .../src/org/jetbrains/jet/lang/types/ErrorUtils.java | 9 ++------- .../jet/lang/types/error/ErrorClassDescriptor.java | 2 +- .../types/error/ErrorSimpleFunctionDescriptorImpl.java | 6 +++--- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java index 201f74d0a79..0cec17e8766 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorDeserializer.java @@ -37,7 +37,7 @@ import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils; import org.jetbrains.jet.lang.resolve.java.resolver.ErrorReporter; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.DependencyClassByQualifiedNameResolver; -import org.jetbrains.jet.lang.types.ErrorUtils; +import org.jetbrains.jet.lang.types.error.ErrorClassDescriptor; import javax.inject.Inject; import java.io.IOException; @@ -177,7 +177,7 @@ public class AnnotationDescriptorDeserializer extends BaseDescriptorDeserializer @NotNull private static ClassDescriptor resolveClass(@NotNull JvmClassName className, DependencyClassByQualifiedNameResolver classResolver) { ClassDescriptor annotationClass = classResolver.resolveClass(className.getFqNameForClassNameWithoutDollars()); - return annotationClass != null ? annotationClass : ErrorUtils.getErrorClass(); + return annotationClass != null ? annotationClass : new ErrorClassDescriptor(className.getInternalName()); } @NotNull diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java index 2d84488db70..b9c1dcca9d5 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -83,7 +83,7 @@ public class ErrorUtils { @Override public ClassifierDescriptor getClassifier(@NotNull Name name) { - return ERROR_CLASS; + return new ErrorClassDescriptor(name.asString()); } @NotNull @@ -269,7 +269,7 @@ public class ErrorUtils { @NotNull private static SimpleFunctionDescriptor createErrorFunction(@NotNull ErrorScope ownerScope) { - ErrorSimpleFunctionDescriptorImpl function = new ErrorSimpleFunctionDescriptorImpl(ownerScope); + ErrorSimpleFunctionDescriptorImpl function = new ErrorSimpleFunctionDescriptorImpl(ERROR_CLASS, ownerScope); function.initialize( null, ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER, @@ -304,11 +304,6 @@ public class ErrorUtils { Collections.singleton(KotlinBuiltIns.getInstance().getAnyType())); } - @NotNull - public static ClassDescriptor getErrorClass() { - return ERROR_CLASS; - } - public static boolean containsErrorType(@Nullable JetType type) { if (type == null) return false; if (type instanceof PackageType) return false; diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java b/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java index 1cbede08cc7..ba49131d8f6 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java @@ -43,7 +43,7 @@ public class ErrorClassDescriptor extends ClassDescriptorImpl { Visibilities.INTERNAL, false); errorConstructor.setReturnType(createErrorType("")); - initialize(createErrorScope("ERROR_CLASS"), Collections.singleton(errorConstructor), errorConstructor); + initialize(createErrorScope(getName().asString()), Collections.singleton(errorConstructor), errorConstructor); } @NotNull diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorSimpleFunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorSimpleFunctionDescriptorImpl.java index c0c44c3e279..4d589d49b9f 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorSimpleFunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorSimpleFunctionDescriptorImpl.java @@ -27,11 +27,11 @@ import org.jetbrains.jet.lang.types.ErrorUtils; public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorImpl { // used for diagnostic only - @NotNull + @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"}) private final ErrorUtils.ErrorScope ownerScope; - public ErrorSimpleFunctionDescriptorImpl(ErrorUtils.ErrorScope ownerScope) { - super(ErrorUtils.getErrorClass(), null, Annotations.EMPTY, Name.special(""), Kind.DECLARATION); + public ErrorSimpleFunctionDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ErrorUtils.ErrorScope ownerScope) { + super(containingDeclaration, null, Annotations.EMPTY, Name.special(""), Kind.DECLARATION); this.ownerScope = ownerScope; }