Introduce ErrorClassDescriptor
Add utility which allows to create error class descriptors with debug message
This commit is contained in:
@@ -22,11 +22,15 @@ import org.jetbrains.jet.lang.ModuleConfiguration;
|
|||||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
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.ImportPath;
|
||||||
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
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.error.ErrorSimpleFunctionDescriptorImpl;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
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.<AnnotationDescriptor>emptyList(), Modality.OPEN, Name.special("<ERROR CLASS>")) {
|
private static final ErrorClassDescriptor ERROR_CLASS = new ErrorClassDescriptor("");
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<ConstructorDescriptor> 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 class ErrorTypeConstructor extends TypeConstructorImpl {
|
private static final class ErrorTypeConstructor extends TypeConstructorImpl {
|
||||||
private ErrorTypeConstructor(
|
private ErrorTypeConstructor(
|
||||||
@@ -284,12 +270,19 @@ public class ErrorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<ConstructorDescriptor> ERROR_CONSTRUCTOR_GROUP = Collections.singleton(createErrorConstructor(0, Collections.<JetType>emptyList()));
|
private static final Set<ConstructorDescriptor> ERROR_CONSTRUCTOR_GROUP = Collections.singleton(createErrorConstructor(0, Collections.<JetType>emptyList()));
|
||||||
|
|
||||||
private static final ConstructorDescriptor ERROR_CONSTRUCTOR = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), true);
|
private static final ConstructorDescriptor ERROR_CONSTRUCTOR = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ERROR_CLASS.initialize(
|
ERROR_CLASS.initializeErrorClass();
|
||||||
true, Collections.<TypeParameterDescriptor>emptyList(), Collections.<JetType>emptyList(), createErrorScope("ERROR_CLASS"), ERROR_CONSTRUCTOR_GROUP,
|
}
|
||||||
ERROR_CONSTRUCTOR, false);
|
@NotNull
|
||||||
|
public static Set<ConstructorDescriptor> getErrorConstructorGroup() {
|
||||||
|
return ERROR_CONSTRUCTOR_GROUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConstructorDescriptor getErrorConstructor() {
|
||||||
|
return ERROR_CONSTRUCTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetScope createErrorScope(String debugMessage) {
|
public static JetScope createErrorScope(String debugMessage) {
|
||||||
@@ -415,7 +408,18 @@ public class ErrorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isError(@NotNull DeclarationDescriptor candidate) {
|
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 {
|
private static class ErrorTypeImpl implements JetType {
|
||||||
|
|||||||
@@ -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.<AnnotationDescriptor>emptyList(), Modality.OPEN,
|
||||||
|
Name.special("<ERROR CLASS: " + debugMessage + ">"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<ConstructorDescriptor> 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.<TypeParameterDescriptor>emptyList(), Collections.<JetType>emptyList(),
|
||||||
|
createErrorScope("ERROR_CLASS"), getErrorConstructorGroup(), getErrorConstructor(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user