From 2e823d6b7bbf8f45a2af7e98e690e85460ba806f Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 2 Sep 2013 20:32:25 +0400 Subject: [PATCH] Introduce ErrorClassDescriptor Add utility which allows to create error class descriptors with debug message --- .../jetbrains/jet/lang/types/ErrorUtils.java | 52 +++++++------- .../types/error/ErrorClassDescriptor.java | 69 +++++++++++++++++++ 2 files changed, 97 insertions(+), 24 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java index 1ac18056397..b343bdb4e73 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -22,11 +22,15 @@ import org.jetbrains.jet.lang.ModuleConfiguration; import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; -import org.jetbrains.jet.lang.descriptors.impl.*; +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.descriptors.impl.ValueParameterDescriptorImpl; import org.jetbrains.jet.lang.resolve.ImportPath; import org.jetbrains.jet.lang.resolve.name.LabelName; 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; @@ -250,25 +254,7 @@ public class ErrorUtils { } } - private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.emptyList(), Modality.OPEN, Name.special("")) { - @NotNull - @Override - public Collection getConstructors() { - return ERROR_CONSTRUCTOR_GROUP; - } - - @NotNull - @Override - public Modality getModality() { - return Modality.OPEN; - } - - @NotNull - @Override - public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) { - return ERROR_CLASS; - } - }; + private static final ErrorClassDescriptor ERROR_CLASS = new ErrorClassDescriptor(""); private static final class ErrorTypeConstructor extends TypeConstructorImpl { private ErrorTypeConstructor( @@ -284,12 +270,19 @@ public class ErrorUtils { } private static final Set ERROR_CONSTRUCTOR_GROUP = Collections.singleton(createErrorConstructor(0, Collections.emptyList())); + private static final ConstructorDescriptor ERROR_CONSTRUCTOR = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.emptyList(), true); static { - ERROR_CLASS.initialize( - true, Collections.emptyList(), Collections.emptyList(), createErrorScope("ERROR_CLASS"), ERROR_CONSTRUCTOR_GROUP, - ERROR_CONSTRUCTOR, false); + ERROR_CLASS.initializeErrorClass(); + } + @NotNull + public static Set getErrorConstructorGroup() { + return ERROR_CONSTRUCTOR_GROUP; + } + + public static ConstructorDescriptor getErrorConstructor() { + return ERROR_CONSTRUCTOR; } public static JetScope createErrorScope(String debugMessage) { @@ -415,7 +408,18 @@ public class ErrorUtils { } public static boolean isError(@NotNull DeclarationDescriptor candidate) { - return candidate == getErrorClass() || candidate.getContainingDeclaration() == getErrorClass() || candidate == ERROR_MODULE; + return isErrorClass(candidate) || isErrorClass(candidate.getContainingDeclaration()) || candidate == ERROR_MODULE; + } + + private static boolean isErrorClass(@Nullable DeclarationDescriptor candidate) { + return candidate instanceof ErrorClassDescriptor; + } + + @NotNull + public static ErrorClassDescriptor createErrorClass(@NotNull String debugMessage) { + ErrorClassDescriptor result = new ErrorClassDescriptor(debugMessage); + result.initializeErrorClass(); + return result; } private static class ErrorTypeImpl implements JetType { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java new file mode 100644 index 00000000000..4fa01e93e9c --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/error/ErrorClassDescriptor.java @@ -0,0 +1,69 @@ +/* + * 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.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; +import org.jetbrains.jet.lang.descriptors.Modality; +import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl; +import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.types.ErrorUtils; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.TypeSubstitutor; + +import java.util.Collection; +import java.util.Collections; + +import static org.jetbrains.jet.lang.types.ErrorUtils.*; + +public final class ErrorClassDescriptor extends ClassDescriptorImpl { + public ErrorClassDescriptor(@NotNull String debugMessage) { + super(ErrorUtils.getErrorModule(), Collections.emptyList(), Modality.OPEN, + Name.special("")); + } + + @NotNull + @Override + public Collection getConstructors() { + return getErrorConstructorGroup(); + } + + @NotNull + @Override + public Modality getModality() { + return Modality.OPEN; + } + + @NotNull + @Override + public ClassDescriptor substitute(@NotNull TypeSubstitutor substitutor) { + return this; + } + + @Override + public String toString() { + return getName().asString(); + } + + public void initializeErrorClass() { + initialize(true, Collections.emptyList(), Collections.emptyList(), + createErrorScope("ERROR_CLASS"), getErrorConstructorGroup(), getErrorConstructor(), false); + } +}