From a7eb137b2fc28bc38b7383dd45f7f9d633e81d9f Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sat, 4 Feb 2012 03:41:21 +0400 Subject: [PATCH] error descriptions in error objects --- .../jetbrains/jet/lang/types/ErrorUtils.java | 41 ++++++++----------- .../NamedFunctionDescriptorErrorImpl.java | 24 +++++++++++ 2 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/types/error/NamedFunctionDescriptorErrorImpl.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 ae8f5cdd0d3..213bed1238e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -6,6 +6,7 @@ import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; +import org.jetbrains.jet.lang.types.error.NamedFunctionDescriptorErrorImpl; import java.util.*; @@ -17,11 +18,13 @@ public class ErrorUtils { private static final ModuleDescriptor ERROR_MODULE = new ModuleDescriptor(""); - private static final JetScope ERROR_SCOPE = new ErrorScope(); - public static class ErrorScope implements JetScope { - private ErrorScope() {} + private final String debugMessage; + + private ErrorScope(String debugMessage) { + this.debugMessage = debugMessage; + } @Override public ClassifierDescriptor getClassifier(@NotNull String name) { @@ -68,7 +71,7 @@ public class ErrorUtils { @NotNull @Override public Set getFunctions(@NotNull String name) { - return ERROR_FUNCTION_GROUP; + return Collections.singleton(createErrorFunction(this)); } @NotNull @@ -116,17 +119,16 @@ public class ErrorUtils { } }; - private static final Set ERROR_FUNCTION_GROUP = Collections.singleton(createErrorFunction(0, Collections.emptyList())); 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(), getErrorScope(), ERROR_CONSTRUCTOR_GROUP, ERROR_CONSTRUCTOR); + true, Collections.emptyList(), Collections.emptyList(), createErrorScope("ERROR_CLASS"), ERROR_CONSTRUCTOR_GROUP, ERROR_CONSTRUCTOR); } - public static JetScope getErrorScope() { - return ERROR_SCOPE; + public static JetScope createErrorScope(String debugMessage) { + return new ErrorScope(debugMessage); } private static final JetType ERROR_PROPERTY_TYPE = createErrorType(""); @@ -143,21 +145,9 @@ public class ErrorUtils { ERROR_PROPERTY_TYPE); private static final Set ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY); - private static FunctionDescriptor createErrorFunction(List typeParameters, List positionedValueArgumentTypes) { - FunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl(ERROR_CLASS, Collections.emptyList(), ""); - return functionDescriptor.initialize( - null, - ReceiverDescriptor.NO_RECEIVER, - typeParameters, - getValueParameters(functionDescriptor, positionedValueArgumentTypes), - createErrorType(""), - Modality.OPEN, - Visibility.INTERNAL - ); - } - - public static FunctionDescriptor createErrorFunction(int typeParameterCount, List positionedValueParameterTypes) { - return new NamedFunctionDescriptorImpl(ERROR_CLASS, Collections.emptyList(), "").initialize( + private static NamedFunctionDescriptor createErrorFunction(ErrorScope ownerScope) { + NamedFunctionDescriptorErrorImpl function = new NamedFunctionDescriptorErrorImpl(ownerScope); + function.initialize( null, ReceiverDescriptor.NO_RECEIVER, Collections.emptyList(), // TODO @@ -166,6 +156,7 @@ public class ErrorUtils { Modality.OPEN, Visibility.INTERNAL ); + return function; } public static ConstructorDescriptor createErrorConstructor(int typeParameterCount, List positionedValueParameterTypes) { @@ -199,7 +190,7 @@ public class ErrorUtils { @NotNull public static JetType createErrorType(String debugMessage) { - return createErrorType(debugMessage, ERROR_SCOPE); + return createErrorType(debugMessage, createErrorScope(debugMessage)); } private static JetType createErrorType(String debugMessage, JetScope memberScope) { @@ -208,7 +199,7 @@ public class ErrorUtils { @NotNull public static JetType createErrorTypeWithCustomDebugName(String debugName) { - return createErrorTypeWithCustomDebugName(ERROR_SCOPE, debugName); + return createErrorTypeWithCustomDebugName(createErrorScope(debugName), debugName); } private static JetType createErrorTypeWithCustomDebugName(JetScope memberScope, String debugName) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/error/NamedFunctionDescriptorErrorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/error/NamedFunctionDescriptorErrorImpl.java new file mode 100644 index 00000000000..01120473195 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/error/NamedFunctionDescriptorErrorImpl.java @@ -0,0 +1,24 @@ +package org.jetbrains.jet.lang.types.error; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptorImpl; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.types.ErrorUtils; + +import java.util.Collections; +import java.util.List; + +/** + * @author Stepan Koltsov + */ +public class NamedFunctionDescriptorErrorImpl extends NamedFunctionDescriptorImpl { + // used for diagnostic only + @NotNull + private final ErrorUtils.ErrorScope ownerScope; + + public NamedFunctionDescriptorErrorImpl(ErrorUtils.ErrorScope ownerScope) { + super(ErrorUtils.getErrorClass(), Collections.emptyList(), ""); + this.ownerScope = ownerScope; + } +}