ErrorClassDescriptor moved to ErrorUtils

This commit is contained in:
Andrey Breslav
2014-05-21 18:46:17 +04:00
parent e2efae3f46
commit f714382bd8
4 changed files with 55 additions and 72 deletions
@@ -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))
@@ -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
@@ -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 ? "<ERROR CLASS>" : "<ERROR CLASS: " + name + ">"),
Modality.OPEN, Collections.<JetType>emptyList());
ConstructorDescriptorImpl errorConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true);
errorConstructor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
Visibilities.INTERNAL, false);
JetScope memberScope = createErrorScope(getName().asString());
errorConstructor.setReturnType(
new ErrorTypeImpl(
TypeConstructorImpl.createForClass(
this, Annotations.EMPTY, false,
getName().asString(),
Collections.<TypeParameterDescriptorImpl>emptyList(),
Collections.singleton(KotlinBuiltIns.getInstance().getAnyType())
),
memberScope
)
);
initialize(memberScope, Collections.<ConstructorDescriptor>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<? extends TypeProjection> 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);
@@ -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 ? "<ERROR CLASS>" : "<ERROR CLASS: " + name + ">"),
Modality.OPEN, Collections.<JetType>emptyList());
ConstructorDescriptorImpl errorConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true);
errorConstructor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
Visibilities.INTERNAL, false);
errorConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"));
initialize(createErrorScope(getName().asString()), Collections.<ConstructorDescriptor>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<? extends TypeProjection> typeArguments) {
return createErrorScope("Error scope for class " + getName() + " with arguments: " + typeArguments);
}
}