diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt b/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt index 8f008d131f0..9a0d57bdd8c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/reflect/ReflectionTypes.kt @@ -25,7 +25,7 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.lang.descriptors.annotations.Annotations import org.jetbrains.jet.lang.types.JetType import org.jetbrains.jet.lang.types.JetTypeImpl -import org.jetbrains.jet.lang.types.error.ErrorClassDescriptor +import org.jetbrains.jet.lang.types.ErrorUtils private val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect") @@ -37,7 +37,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { fun find(className: String): ClassDescriptor { val name = Name.identifier(className) return kotlinReflectScope?.getClassifier(name) as? ClassDescriptor - ?: ErrorClassDescriptor(KOTLIN_REFLECT_FQ_NAME.child(name).asString()) + ?: ErrorUtils.createErrorClass(KOTLIN_REFLECT_FQ_NAME.child(name).asString()) } public fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n") @@ -54,7 +54,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) { val arguments = KotlinBuiltIns.getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType) val classDescriptor = correspondingKFunctionClass(receiverType, extensionFunction, parameterTypes.size) - return if (classDescriptor is ErrorClassDescriptor) + return if (ErrorUtils.isError(classDescriptor)) classDescriptor.getDefaultType() else JetTypeImpl(annotations, classDescriptor.getTypeConstructor(), false, arguments, classDescriptor.getMemberScope(arguments)) 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 0cec17e8766..d7d0c547e04 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.error.ErrorClassDescriptor; +import org.jetbrains.jet.lang.types.ErrorUtils; 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 : new ErrorClassDescriptor(className.getInternalName()); + return annotationClass != null ? annotationClass : ErrorUtils.createErrorClass(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 0cfa8147a3d..247cad592c8 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -22,12 +22,13 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.Annotations; +import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl; +import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl; import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl; import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl; import org.jetbrains.jet.lang.resolve.ImportPath; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.types.error.ErrorClassDescriptor; import org.jetbrains.jet.lang.types.error.ErrorSimpleFunctionDescriptorImpl; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.utils.Printer; @@ -82,7 +83,7 @@ public class ErrorUtils { @Override public ClassifierDescriptor getClassifier(@NotNull Name name) { - return new ErrorClassDescriptor(name.asString()); + return createErrorClass(name.asString()); } @NotNull @@ -228,6 +229,53 @@ public class ErrorUtils { private static final ErrorClassDescriptor ERROR_CLASS = new ErrorClassDescriptor(null); + private static class ErrorClassDescriptor extends ClassDescriptorImpl { + public ErrorClassDescriptor(@Nullable String name) { + super(getErrorModule(), Name.special(name == null ? "" : ""), + Modality.OPEN, Collections.emptyList()); + + ConstructorDescriptorImpl errorConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true); + errorConstructor.initialize(Collections.emptyList(), Collections.emptyList(), + Visibilities.INTERNAL, false); + JetScope memberScope = createErrorScope(getName().asString()); + errorConstructor.setReturnType( + new ErrorTypeImpl( + TypeConstructorImpl.createForClass( + this, Annotations.EMPTY, false, + getName().asString(), + Collections.emptyList(), + Collections.singleton(KotlinBuiltIns.getInstance().getAnyType()) + ), + memberScope + ) + ); + + initialize(memberScope, Collections.singleton(errorConstructor), errorConstructor); + } + + @NotNull + @Override + public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) { + return this; + } + + @Override + public String toString() { + return getName().asString(); + } + + @NotNull + @Override + public JetScope getMemberScope(@NotNull List typeArguments) { + return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeArguments); + } + } + + @NotNull + public static ClassDescriptor createErrorClass(@NotNull String debugMessage) { + return new ErrorClassDescriptor(debugMessage); + } + @NotNull public static JetScope createErrorScope(@NotNull String debugMessage) { return createErrorScope(debugMessage, 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 deleted file mode 100644 index ba49131d8f6..00000000000 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.lang.types.error; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.descriptors.annotations.Annotations; -import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl; -import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl; -import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.types.JetType; -import org.jetbrains.jet.lang.types.TypeProjection; -import org.jetbrains.jet.lang.types.TypeSubstitutor; - -import java.util.Collections; -import java.util.List; - -import static org.jetbrains.jet.lang.types.ErrorUtils.*; - -public class ErrorClassDescriptor extends ClassDescriptorImpl { - public ErrorClassDescriptor(@Nullable String name) { - super(getErrorModule(), Name.special(name == null ? "" : ""), - Modality.OPEN, Collections.emptyList()); - - ConstructorDescriptorImpl errorConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true); - errorConstructor.initialize(Collections.emptyList(), Collections.emptyList(), - Visibilities.INTERNAL, false); - errorConstructor.setReturnType(createErrorType("")); - - initialize(createErrorScope(getName().asString()), Collections.singleton(errorConstructor), errorConstructor); - } - - @NotNull - @Override - public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) { - return this; - } - - @Override - public String toString() { - return getName().asString(); - } - - @NotNull - @Override - public JetScope getMemberScope(@NotNull List typeArguments) { - return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeArguments); - } -}