diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java index 1fa41b06c43..5b2281ea730 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorUtil.java @@ -97,7 +97,7 @@ public class FunctionDescriptorUtil { @NotNull public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) { - WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, trace.getErrorHandler()).setDebugName("Function inner scope"); + WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, trace).setDebugName("Function inner scope"); JetType receiverType = descriptor.getReceiverType(); if (receiverType != null) { parameterScope.setThisType(receiverType); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java index 6168cd1bb91..dd6ef1366fb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java @@ -40,9 +40,9 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) { super(containingDeclaration); - this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, trace.getErrorHandler()).setDebugName("MemberLookup"); - this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, trace.getErrorHandler()).setDebugName("SupertypeResolution"); - this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, trace.getErrorHandler()).setDebugName("MemberResolution"); + this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, trace).setDebugName("MemberLookup"); + this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, trace).setDebugName("SupertypeResolution"); + this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, trace).setDebugName("MemberResolution"); this.kind = kind; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java index 82e58183371..54b901f59dd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticHolder.java @@ -6,5 +6,19 @@ import org.jetbrains.annotations.NotNull; * @author abreslav */ public interface DiagnosticHolder { + DiagnosticHolder DO_NOTHING = new DiagnosticHolder() { + @Override + public void report(@NotNull Diagnostic diagnostic) { + } + }; + DiagnosticHolder THROW_EXCEPTION = new DiagnosticHolder() { + @Override + public void report(@NotNull Diagnostic diagnostic) { + if (diagnostic.getSeverity() == Severity.ERROR) { + throw new IllegalStateException(diagnostic.getMessage()); + } + } + }; + void report(@NotNull Diagnostic diagnostic); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ErrorHandler.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ErrorHandler.java index 7c121afe51d..875d2248e52 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ErrorHandler.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ErrorHandler.java @@ -72,15 +72,18 @@ public class ErrorHandler { public static void applyHandler(@NotNull ErrorHandler errorHandler, @NotNull Collection diagnostics) { for (Diagnostic diagnostic : diagnostics) { - if (diagnostic instanceof Errors.UnresolvedReferenceDiagnosticFactory.UnresolvedReferenceDiagnostic) { - Errors.UnresolvedReferenceDiagnosticFactory.UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (Errors.UnresolvedReferenceDiagnosticFactory.UnresolvedReferenceDiagnostic) diagnostic; + if (diagnostic instanceof Errors.UnresolvedReferenceDiagnostic) { + Errors.UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (Errors.UnresolvedReferenceDiagnostic) diagnostic; errorHandler.unresolvedReference(unresolvedReferenceDiagnostic.getReference()); } -// else { -// if (diagnostic.getSeverity() == Severity.ERROR) { -// -// } -// } + else { + if (diagnostic.getSeverity() == Severity.ERROR) { + + } + else if (diagnostic.getSeverity() == Severity.WARNING) { + + } + } } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 9b7a477a590..2c65561690f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -9,6 +9,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.resolve.DescriptorRenderer; +import java.text.MessageFormat; import java.util.Collection; import java.util.Iterator; @@ -21,12 +22,12 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; public interface Errors { public class AbstractDiagnosticFactory implements DiagnosticFactory { - protected final String message; + protected final MessageFormat messageFormat; protected final Severity severity; public AbstractDiagnosticFactory(Severity severity, String message) { this.severity = severity; - this.message = message; + this.messageFormat = new MessageFormat(message); } @NotNull @@ -36,14 +37,18 @@ public interface Errors { } } - public class SimpleDiagnosticFactory extends AbstractDiagnosticFactory { + public class SimpleDiagnosticFactory implements DiagnosticFactory { public static SimpleDiagnosticFactory create(Severity severity, String message) { return new SimpleDiagnosticFactory(severity, message); } - protected SimpleDiagnosticFactory(Severity severity, String message) { - super(severity, message); + protected final String message; + protected final Severity severity; + + public SimpleDiagnosticFactory(Severity severity, String message) { + this.message = message; + this.severity = severity; } @NotNull @@ -61,6 +66,11 @@ public interface Errors { return on(element.getTextRange()); } + @NotNull + @Override + public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) { + return ((DiagnosticWithTextRange) diagnostic).getTextRange(); + } } public class ParameterizedDiagnosticFactory1 extends AbstractDiagnosticFactory { @@ -72,10 +82,14 @@ public interface Errors { super(severity, messageStub); } - protected String makeMessage(@NotNull T argument) { - return String.format(message, argument); - } - + private String makeMessage(@NotNull T argument) { + return messageFormat.format(new Object[]{makeMessageFor(argument)}); + } + + protected String makeMessageFor(T argument) { + return argument.toString(); + } + @NotNull public Diagnostic on(@NotNull TextRange range, @NotNull T argument) { return new GenericDiagnostic(this, severity, makeMessage(argument), range); @@ -102,7 +116,7 @@ public interface Errors { } protected String makeMessage(@NotNull A a, @NotNull B b) { - return String.format(message, makeMessageForA(a), makeMessageForB(b)); + return messageFormat.format(new Object[] {makeMessageForA(a), makeMessageForB(b)}); } protected String makeMessageForA(@NotNull A a) { @@ -139,7 +153,7 @@ public interface Errors { } protected String makeMessage(@NotNull A a, @NotNull B b, @NotNull C c) { - return String.format(message, makeMessageForA(a), makeMessageForB(b), makeMessageForC(c)); + return messageFormat.format(new Object[]{makeMessageForA(a), makeMessageForB(b), makeMessageForC(c)}); } protected String makeMessageForA(@NotNull A a) { @@ -183,20 +197,6 @@ public interface Errors { return ((UnresolvedReferenceDiagnostic) diagnostic).getTextRange(); } - public class UnresolvedReferenceDiagnostic extends GenericDiagnostic { - - private final JetReferenceExpression reference; - - public UnresolvedReferenceDiagnostic(JetReferenceExpression referenceExpression) { - super(UnresolvedReferenceDiagnosticFactory.this, ERROR, "Unresolved reference", referenceExpression.getTextRange()); - this.reference = referenceExpression; - } - - @NotNull - public JetReferenceExpression getReference() { - return reference; - } - } } public class AmbiguousDescriptorDiagnosticFactory extends ParameterizedDiagnosticFactory1> { @@ -209,7 +209,7 @@ public interface Errors { } @Override - protected String makeMessage(@NotNull Collection argument) { + protected String makeMessageFor(@NotNull Collection argument) { StringBuilder stringBuilder = new StringBuilder("\n"); for (CallableDescriptor descriptor : argument) { stringBuilder.append(DescriptorRenderer.TEXT.render(descriptor)).append("\n"); @@ -254,7 +254,7 @@ public interface Errors { ParameterizedDiagnosticFactory1 ABSTRACT_FUNCTION_WITH_BODY = ParameterizedDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract"); ParameterizedDiagnosticFactory1 NON_ABSTRACT_FUNCTION_WITH_NO_BODY = ParameterizedDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract"); ParameterizedDiagnosticFactory1 NON_MEMBER_ABSTRACT_FUNCTION = ParameterizedDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract"); - ParameterizedDiagnosticFactory1 NON_MEMBER_ABSTRACT_ACCESSOR = ParameterizedDiagnosticFactory1.create(ERROR, "Property {0} is not a class or trait member and thus cannot have be abstract accessors"); + SimpleDiagnosticFactory NON_MEMBER_ABSTRACT_ACCESSOR = SimpleDiagnosticFactory.create(ERROR, "This property is not a class or trait member and thus cannot have abstract accessors"); // TODO : Better message ParameterizedDiagnosticFactory1 NON_MEMBER_FUNCTION_NO_BODY = ParameterizedDiagnosticFactory1.create(ERROR, "Function {0} must have a body"); SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning @@ -269,13 +269,13 @@ public interface Errors { ParameterizedDiagnosticFactory1 PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY = ParameterizedDiagnosticFactory1.create(ERROR, "This class must have a primary constructor, because property {0} has a backing field"); ParameterizedDiagnosticFactory1 PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL = new ParameterizedDiagnosticFactory1(ERROR, "Class {0} must have a constructor in order to be able to initialize supertypes") { @Override - protected String makeMessage(@NotNull JetClassOrObject argument) { + protected String makeMessageFor(@NotNull JetClassOrObject argument) { return JetPsiUtil.safeName(argument.getName()); } }; ParameterizedDiagnosticFactory1 EXCEPTION_WHILE_ANALYZING = new ParameterizedDiagnosticFactory1(ERROR, "{0}") { @Override - protected String makeMessage(@NotNull Throwable e) { + protected String makeMessageFor(@NotNull Throwable e) { return e.getClass().getSimpleName() + ": " + e.getMessage(); } }; @@ -312,7 +312,7 @@ public interface Errors { ParameterizedDiagnosticFactory1 WRONG_GETTER_RETURN_TYPE = ParameterizedDiagnosticFactory1.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}"); ParameterizedDiagnosticFactory1 NO_CLASS_OBJECT = new ParameterizedDiagnosticFactory1(ERROR, "Classifier {0} does not have a class object") { @Override - protected String makeMessage(@NotNull ClassifierDescriptor argument) { + protected String makeMessageFor(@NotNull ClassifierDescriptor argument) { return argument.getName(); } }; @@ -342,13 +342,13 @@ public interface Errors { ParameterizedDiagnosticFactory1 USELESS_ELVIS = ParameterizedDiagnosticFactory1.create(WARNING, "Elvis operator (?:) always returns the left operand of non-nullable type {0}"); ParameterizedDiagnosticFactory1 CONFLICTING_UPPER_BOUNDS = new ParameterizedDiagnosticFactory1(ERROR, "Upper bounds of {0} have empty intersection") { @Override - protected String makeMessage(@NotNull TypeParameterDescriptor argument) { + protected String makeMessageFor(@NotNull TypeParameterDescriptor argument) { return argument.getName(); } }; ParameterizedDiagnosticFactory1 CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS = new ParameterizedDiagnosticFactory1(ERROR, "Class object upper bounds of {0} have empty intersection") { @Override - protected String makeMessage(@NotNull TypeParameterDescriptor argument) { + protected String makeMessageFor(@NotNull TypeParameterDescriptor argument) { return argument.getName(); } }; @@ -376,7 +376,7 @@ public interface Errors { ParameterizedDiagnosticFactory1 UNSAFE_CALL = ParameterizedDiagnosticFactory1.create(ERROR, "Only safe calls (?.) are allowed on a nullable receiver of type {0}"); SimpleDiagnosticFactory AMBIGUOUS_LABEL = SimpleDiagnosticFactory.create(ERROR, "Ambiguous label"); ParameterizedDiagnosticFactory1 UNSUPPORTED = ParameterizedDiagnosticFactory1.create(ERROR, "Unsupported [{0}]"); - ParameterizedDiagnosticFactory1 UNNECESSARY_SAFE_CALL = ParameterizedDiagnosticFactory1.create(ERROR, "Unnecessary safe call on a non-null receiver of type {0}"); + ParameterizedDiagnosticFactory1 UNNECESSARY_SAFE_CALL = ParameterizedDiagnosticFactory1.create(WARNING, "Unnecessary safe call on a non-null receiver of type {0}"); ParameterizedDiagnosticFactory2 NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER = new ParameterizedDiagnosticFactory2(ERROR, "{0} does not refer to a type parameter of {1}") { @Override protected String makeMessageForA(@NotNull JetTypeConstraint jetTypeConstraint) { @@ -399,7 +399,7 @@ public interface Errors { ParameterizedDiagnosticFactory1 TYPE_MISMATCH_IN_CONDITION = ParameterizedDiagnosticFactory1.create(ERROR, "Condition must be of type Boolean, but was of type {0}"); ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_TUPLE_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}"); // TODO: message ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_BINDING_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}"); - ParameterizedDiagnosticFactory2 TYPE_MISMATCH = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {0} but {1} was expected"); + ParameterizedDiagnosticFactory2 TYPE_MISMATCH = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected"); ParameterizedDiagnosticFactory2 INCOMPATIBLE_TYPES = ParameterizedDiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}"); ParameterizedDiagnosticFactory3> INCONSISTENT_TYPE_PARAMETER_VALUES = new ParameterizedDiagnosticFactory3>(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}") { @@ -474,8 +474,80 @@ public interface Errors { SimpleDiagnosticFactory TYPE_INFERENCE_FAILED = SimpleDiagnosticFactory.create(ERROR, "Type inference failed"); ParameterizedDiagnosticFactory1 WRONG_NUMBER_OF_TYPE_ARGUMENTS = new ParameterizedDiagnosticFactory1(ERROR, "{0} type arguments expected") { @Override - protected String makeMessage(@NotNull Integer argument) { + protected String makeMessageFor(@NotNull Integer argument) { return argument == 0 ? "No" : argument.toString(); } }; + + + class RedeclarationDiagnosticFactory implements DiagnosticFactory { + + public static final RedeclarationDiagnosticFactory INSTANCE = new RedeclarationDiagnosticFactory(); + + private RedeclarationDiagnosticFactory() {} + + public RedeclarationDiagnostic on(DeclarationDescriptor a, DeclarationDescriptor b) { + return new RedeclarationDiagnostic(a, b); + } + + @NotNull + @Override + public TextRange getMarkerPosition(@NotNull Diagnostic diagnostic) { + throw new UnsupportedOperationException(); // TODO + } + } + + class RedeclarationDiagnostic implements Diagnostic { + + private final DeclarationDescriptor a; + private final DeclarationDescriptor b; + + public RedeclarationDiagnostic(DeclarationDescriptor a, DeclarationDescriptor b) { + this.a = a; + this.b = b; + } + + public DeclarationDescriptor getA() { + return a; + } + + public DeclarationDescriptor getB() { + return b; + } + + @NotNull + @Override + public DiagnosticFactory getFactory() { + return RedeclarationDiagnosticFactory.INSTANCE; + } + + @NotNull + @Override + public String getMessage() { + return "Redeclaration"; + } + + @NotNull + @Override + public Severity getSeverity() { + return ERROR; + } + } + + RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.INSTANCE; + + public class UnresolvedReferenceDiagnostic extends GenericDiagnostic { + + private final JetReferenceExpression reference; + + public UnresolvedReferenceDiagnostic(JetReferenceExpression referenceExpression) { + super(UNRESOLVED_REFERENCE, ERROR, "Unresolved reference", referenceExpression.getTextRange()); + this.reference = referenceExpression; + } + + @NotNull + public JetReferenceExpression getReference() { + return reference; + } + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java index 4086d581966..1b624f6d4fa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java @@ -64,7 +64,7 @@ public class AnalyzingUtils { JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope(); ModuleDescriptor owner = new ModuleDescriptor(""); - final WritableScope scope = new WritableScopeImpl(libraryScope, owner, bindingTraceContext.getErrorHandler()).setDebugName("Root scope in analyzeNamespace"); + final WritableScope scope = new WritableScopeImpl(libraryScope, owner, bindingTraceContext).setDebugName("Root scope in analyzeNamespace"); importingStrategy.addImports(project, semanticServices, bindingTraceContext, scope); TopDownAnalyzer.process(semanticServices, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java index 9222fff323e..900e06fffef 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java @@ -430,13 +430,13 @@ public class BodyResolver { assert containingClass != null : "This must be guaranteed by the parser"; if (!containingClass.hasPrimaryConstructor()) { // context.getTrace().getErrorHandler().genericError(declaration.getNameNode(), "A secondary constructor may appear only in a class that has a primary constructor"); - context.getTrace().report(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY.on(declaration)); + context.getTrace().report(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY.on(declaration.getNameNode())); } else { List initializers = declaration.getInitializers(); if (initializers.isEmpty()) { // context.getTrace().getErrorHandler().genericError(declaration.getNameNode(), "Secondary constructors must have an initializer list"); - context.getTrace().report(SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST.on(declaration)); + context.getTrace().report(SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST.on(declaration.getNameNode())); } else { initializers.get(0).accept(new JetVisitorVoid() { @@ -500,7 +500,7 @@ public class BodyResolver { @NotNull private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope, boolean primary) { - WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), context.getTrace().getErrorHandler()).setDebugName("Inner scope for constructor"); + WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), context.getTrace()).setDebugName("Inner scope for constructor"); for (PropertyDescriptor propertyDescriptor : ((MutableClassDescriptor) descriptor.getContainingDeclaration()).getProperties()) { constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor); } @@ -567,7 +567,7 @@ public class BodyResolver { } private JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull PropertyDescriptor propertyDescriptor) { - WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, context.getTrace().getErrorHandler()).setDebugName("Property declaration inner scope"); + WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, context.getTrace()).setDebugName("Property declaration inner scope"); for (TypeParameterDescriptor typeParameterDescriptor : propertyDescriptor.getTypeParameters()) { result.addTypeParameterDescriptor(typeParameterDescriptor); } @@ -581,7 +581,7 @@ public class BodyResolver { private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, JetScope declaringScope) { BindingTraceAdapter fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor); - WritableScope accessorScope = new WritableScopeImpl(getPropertyDeclarationInnerScope(declaringScope, propertyDescriptor), declaringScope.getContainingDeclaration(), context.getTrace().getErrorHandler()).setDebugName("Accessor scope"); + WritableScope accessorScope = new WritableScopeImpl(getPropertyDeclarationInnerScope(declaringScope, propertyDescriptor), declaringScope.getContainingDeclaration(), context.getTrace()).setDebugName("Accessor scope"); accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor); JetPropertyAccessor getter = property.getGetter(); @@ -818,7 +818,7 @@ public class BodyResolver { } else { // context.getTrace().getErrorHandler().genericError(abstractNode, "Property {0} is not a class or trait member and thus cannot have be abstract accessors"); - context.getTrace().report(NON_MEMBER_ABSTRACT_ACCESSOR.on(abstractNode, (PropertyDescriptor) functionDescriptor.getContainingDeclaration())); + context.getTrace().report(NON_MEMBER_ABSTRACT_ACCESSOR.on(abstractNode)); } } if (function.getBodyExpression() == null && !hasAbstractModifier && nameIdentifier != null && !isPropertyAccessor) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java index 0ead0487866..d49fae29d10 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java @@ -123,7 +123,7 @@ public class ClassDescriptorResolver { for (JetTypeProjection typeArgument : typeArguments) { if (typeArgument.getProjectionKind() != JetProjectionKind.NONE) { // trace.getErrorHandler().genericError(typeArgument.getProjectionNode(), "Projections are not allowed for immediate arguments of a supertype"); - trace.report(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE.on(typeArgument)); + trace.report(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE.on(typeArgument.getProjectionNode())); } } } @@ -142,7 +142,7 @@ public class ClassDescriptorResolver { annotationResolver.resolveAnnotations(scope, function.getModifierList()), JetPsiUtil.safeName(function.getName()) ); - WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, trace.getErrorHandler()).setDebugName("Function descriptor header scope"); + WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, trace).setDebugName("Function descriptor header scope"); innerScope.addLabeledDeclaration(functionDescriptor); List typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters()); @@ -450,7 +450,7 @@ public class ClassDescriptorResolver { typeParameterDescriptors = Collections.emptyList(); } else { - WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, trace.getErrorHandler()).setDebugName("Scope with type parameters of a property"); + WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, trace).setDebugName("Scope with type parameters of a property"); typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters); resolveGenericBounds(property, writableScope, typeParameterDescriptors); scopeWithTypeParameters = writableScope; @@ -658,7 +658,7 @@ public class ClassDescriptorResolver { typeParameters, resolveValueParameters( constructorDescriptor, - new WritableScopeImpl(scope, classDescriptor, trace.getErrorHandler()).setDebugName("Scope with value parameters of a constructor"), + new WritableScopeImpl(scope, classDescriptor, trace).setDebugName("Scope with value parameters of a constructor"), valueParameters), Modality.FINAL); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java index 5e097c990ba..48e6a50b829 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java @@ -71,13 +71,13 @@ public class TypeHierarchyResolver { Collections.emptyList(), // TODO: annotations name ); - namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, context.getTrace().getErrorHandler()).setDebugName("Namespace member scope")); + namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, context.getTrace()).setDebugName("Namespace member scope")); owner.addNamespace(namespaceDescriptor); context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor); } context.getNamespaceDescriptors().put(namespace, namespaceDescriptor); - WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), context.getTrace().getErrorHandler()); + WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), context.getTrace()); context.getNamespaceScopes().put(namespace, namespaceScope); processImports(namespace, namespaceScope, outerScope); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java index ff2b24df2d3..ec7da04365a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java @@ -107,7 +107,7 @@ public class TypeResolver { trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type, expectedArgumentCount)); } else { // trace.getErrorHandler().genericError(type.getTypeArgumentList().getNode(), errorMessage); - trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type, expectedArgumentCount)); + trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type.getTypeArgumentList(), expectedArgumentCount)); } } else { result[0] = new JetTypeImpl( diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeImpl.java index 35609367fd7..6d6065cc7c0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeImpl.java @@ -5,12 +5,14 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.diagnostics.ErrorHandler; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.types.*; +import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder; +import org.jetbrains.jet.lang.types.JetType; import java.util.*; +import static org.jetbrains.jet.lang.diagnostics.Errors.REDECLARATION; + /** * @author abreslav */ @@ -38,8 +40,8 @@ public class WritableScopeImpl extends WritableScopeWithImports { private List variableDescriptors; - public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull ErrorHandler errorHandler) { - super(scope, errorHandler); + public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull DiagnosticHolder diagnosticHolder) { + super(scope, diagnosticHolder); this.ownerDeclarationDescriptor = owner; } @@ -137,7 +139,7 @@ public class WritableScopeImpl extends WritableScopeWithImports { Map variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors(); DeclarationDescriptor existingDescriptor = variableClassOrNamespaceDescriptors.get(variableDescriptor.getName()); if (existingDescriptor != null) { - errorHandler.redeclaration(existingDescriptor, variableDescriptor); + diagnosticHolder.report(REDECLARATION.on(existingDescriptor, variableDescriptor)); } // TODO : Should this always happen? variableClassOrNamespaceDescriptors.put(variableDescriptor.getName(), variableDescriptor); @@ -228,7 +230,7 @@ public class WritableScopeImpl extends WritableScopeWithImports { Map variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors(); DeclarationDescriptor originalDescriptor = variableClassOrNamespaceDescriptors.get(name); if (originalDescriptor != null) { - errorHandler.redeclaration(originalDescriptor, classifierDescriptor); + diagnosticHolder.report(REDECLARATION.on(originalDescriptor, classifierDescriptor)); } variableClassOrNamespaceDescriptors.put(name, classifierDescriptor); allDescriptors.add(classifierDescriptor); @@ -260,7 +262,7 @@ public class WritableScopeImpl extends WritableScopeWithImports { Map variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors(); DeclarationDescriptor oldValue = variableClassOrNamespaceDescriptors.put(namespaceDescriptor.getName(), namespaceDescriptor); if (oldValue != null) { - errorHandler.redeclaration(oldValue, namespaceDescriptor); + diagnosticHolder.report(REDECLARATION.on(oldValue, namespaceDescriptor)); } allDescriptors.add(namespaceDescriptor); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeWithImports.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeWithImports.java index ad007816ddb..6151d0f708a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeWithImports.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WritableScopeWithImports.java @@ -2,8 +2,8 @@ package org.jetbrains.jet.lang.resolve; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.diagnostics.ErrorHandler; import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder; import java.util.ArrayList; import java.util.List; @@ -18,11 +18,11 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement @Nullable private List imports; private WritableScope currentIndividualImportScope; - protected final ErrorHandler errorHandler; + protected final DiagnosticHolder diagnosticHolder; - public WritableScopeWithImports(@NotNull JetScope scope, @NotNull ErrorHandler errorHandler) { + public WritableScopeWithImports(@NotNull JetScope scope, @NotNull DiagnosticHolder diagnosticHolder) { super(scope); - this.errorHandler = errorHandler; + this.diagnosticHolder = diagnosticHolder; } public WritableScopeWithImports setDebugName(@NotNull String debugName) { @@ -97,7 +97,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) { if (currentIndividualImportScope == null) { - WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, getContainingDeclaration(), ErrorHandler.DO_NOTHING).setDebugName("Individual import scope"); + WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, getContainingDeclaration(), DiagnosticHolder.DO_NOTHING).setDebugName("Individual import scope"); importScope(writableScope); currentIndividualImportScope = writableScope; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WriteThroughScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WriteThroughScope.java index 1adaa32ea78..3018808e29e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WriteThroughScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/WriteThroughScope.java @@ -3,9 +3,9 @@ package org.jetbrains.jet.lang.resolve; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.diagnostics.ErrorHandler; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.types.*; +import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder; +import org.jetbrains.jet.lang.types.JetType; import java.util.Collection; @@ -16,8 +16,8 @@ public class WriteThroughScope extends WritableScopeWithImports { private final WritableScope writableWorker; private Collection allDescriptors; - public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull ErrorHandler errorHandler) { - super(outerScope, errorHandler); + public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull DiagnosticHolder diagnosticHolder) { + super(outerScope, diagnosticHolder); this.writableWorker = scope; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardClasses.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardClasses.java index 73504915eeb..f307299eb96 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardClasses.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardClasses.java @@ -4,9 +4,9 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.diagnostics.ErrorHandler; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder; import org.jetbrains.jet.lang.resolve.JetScope; import org.jetbrains.jet.lang.resolve.JetScopeImpl; import org.jetbrains.jet.lang.resolve.WritableScope; @@ -198,7 +198,7 @@ public class JetStandardClasses { /*package*/ static final JetScope STANDARD_CLASSES; static { - WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, ErrorHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES"); + WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, DiagnosticHolder.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES"); STANDARD_CLASSES = writableScope; writableScope.addClassifierAlias("Unit", getTuple(0)); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index a1f53ad71ef..581f4125f95 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -4,6 +4,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.PsiFileFactory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder; import org.jetbrains.jet.lang.diagnostics.ErrorHandler; import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.descriptors.*; @@ -97,7 +98,7 @@ public class JetStandardLibrary { JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this); BindingTraceContext bindingTraceContext = new BindingTraceContext(); - WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, ErrorHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope"); + WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, DiagnosticHolder.THROW_EXCEPTION).setDebugName("Root bootstrap scope"); // this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations()); // bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations()); TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace()); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index 2f02f2fe245..797e471a8f8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -16,6 +16,7 @@ import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.diagnostics.CompositeErrorHandler; +import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.ErrorHandler; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; @@ -367,7 +368,7 @@ public class JetTypeInferrer { } DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration(); - WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, context.trace.getErrorHandler()).setDebugName("getBlockReturnedType"); + WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, context.trace).setDebugName("getBlockReturnedType"); return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context); } @@ -469,19 +470,26 @@ public class JetTypeInferrer { private BindingTraceAdapter makeTraceInterceptingTypeMismatch(final BindingTrace trace, final JetExpression expressionToWatch, final boolean[] mismatchFound) { return new BindingTraceAdapter(trace) { - @NotNull - @Override - public ErrorHandler getErrorHandler() { - return new CompositeErrorHandler(super.getErrorHandler(), new ErrorHandler() { - @Override - public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) { - if (expression == expressionToWatch) { - mismatchFound[0] = true; - } - } - }); - } - }; + @NotNull + @Override + public ErrorHandler getErrorHandler() { + return new CompositeErrorHandler(super.getErrorHandler(), new ErrorHandler() { + @Override + public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) { + if (expression == expressionToWatch) { + mismatchFound[0] = true; + } + } + }); + } + + @Override + public void report(@NotNull Diagnostic diagnostic) { + if (diagnostic.getFactory() == TYPE_MISMATCH) { + mismatchFound[0] = true; + } + } + }; } //TODO @@ -1818,7 +1826,7 @@ public class JetTypeInferrer { } protected WritableScopeImpl newWritableScopeImpl(JetScope scope, BindingTrace trace) { - return new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler()); + return new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace); } @Override diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java b/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java index ca49e5d995d..db6567c8d9b 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java @@ -10,8 +10,9 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetNodeTypes; -import org.jetbrains.jet.lang.diagnostics.JetDiagnostic; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.diagnostics.Diagnostic; +import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.ErrorUtils; @@ -54,10 +55,9 @@ public class DebugInfoAnnotator implements Annotator { final BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(file); final Set unresolvedReferences = Sets.newHashSet(); - for (JetDiagnostic diagnostic : bindingContext.getOld_Diagnostics()) { - if (diagnostic instanceof JetDiagnostic.UnresolvedReferenceError) { - JetDiagnostic.UnresolvedReferenceError error = (JetDiagnostic.UnresolvedReferenceError) diagnostic; - unresolvedReferences.add(error.getReferenceExpression()); + for (Diagnostic diagnostic : bindingContext.getDiagnostics()) { + if (diagnostic instanceof Errors.UnresolvedReferenceDiagnostic) { + unresolvedReferences.add(((Errors.UnresolvedReferenceDiagnostic) diagnostic).getReference()); } } diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java index 08bb6ebc8cf..6d7bce3ca49 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java @@ -1,7 +1,6 @@ package org.jetbrains.jet.plugin.annotations; import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.lang.ASTNode; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; import com.intellij.openapi.progress.ProcessCanceledException; @@ -10,16 +9,19 @@ import com.intellij.psi.MultiRangeReference; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.diagnostics.ErrorHandler; +import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; +import org.jetbrains.jet.lang.diagnostics.Errors; +import org.jetbrains.jet.lang.diagnostics.Severity; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.plugin.AnalyzerFacade; import org.jetbrains.jet.plugin.JetHighlighter; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -45,61 +47,92 @@ public class JetPsiChecker implements Annotator { try { final BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(file); - ErrorHandler errorHandler = new ErrorHandler() { - private final Set redeclarations = new HashSet(); - - @Override - public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) { - PsiReference reference = referenceExpression.getReference(); - if (reference instanceof MultiRangeReference) { - MultiRangeReference mrr = (MultiRangeReference) reference; - for (TextRange range : mrr.getRanges()) { - holder.createErrorAnnotation(range.shiftRight(referenceExpression.getTextOffset()), "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); - } - } - else { - holder.createErrorAnnotation(referenceExpression, "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); - } - } - - @Override - public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) { - holder.createErrorAnnotation(expression, "Type mismatch: inferred type is " + actualType + " but " + expectedType + " was expected"); - } - - @Override - public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) { - markRedeclaration(existingDescriptor); - markRedeclaration(redeclaredDescriptor); - } - - private void markRedeclaration(DeclarationDescriptor redeclaration) { - if (!redeclarations.add(redeclaration)) return; - PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, redeclaration); - if (declarationPsiElement instanceof JetNamedDeclaration) { - PsiElement nameIdentifier = ((JetNamedDeclaration) declarationPsiElement).getNameIdentifier(); - if (nameIdentifier != null) { - holder.createErrorAnnotation(nameIdentifier, "Redeclaration"); - } - } - else if (declarationPsiElement != null) { - holder.createErrorAnnotation(declarationPsiElement, "Redeclaration"); - } - } - - @Override - public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) { - holder.createErrorAnnotation(node, errorMessage); - } - - @Override - public void genericWarning(@NotNull ASTNode node, @NotNull String message) { - holder.createWarningAnnotation(node, message); - } - }; +// ErrorHandler errorHandler = new ErrorHandler() { +// private final Set redeclarations = new HashSet(); +// +// @Override +// public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) { +// PsiReference reference = referenceExpression.getReference(); +// if (reference instanceof MultiRangeReference) { +// MultiRangeReference mrr = (MultiRangeReference) reference; +// for (TextRange range : mrr.getRanges()) { +// holder.createErrorAnnotation(range.shiftRight(referenceExpression.getTextOffset()), "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); +// } +// } +// else { +// holder.createErrorAnnotation(referenceExpression, "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); +// } +// } +// +// @Override +// public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) { +// holder.createErrorAnnotation(expression, "Type mismatch: inferred type is " + actualType + " but " + expectedType + " was expected"); +// } +// +// @Override +// public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) { +// markRedeclaration(existingDescriptor); +// markRedeclaration(redeclaredDescriptor); +// } +// +// private void markRedeclaration(DeclarationDescriptor redeclaration) { +// if (!redeclarations.add(redeclaration)) return; +// PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, redeclaration); +// if (declarationPsiElement instanceof JetNamedDeclaration) { +// PsiElement nameIdentifier = ((JetNamedDeclaration) declarationPsiElement).getNameIdentifier(); +// if (nameIdentifier != null) { +// holder.createErrorAnnotation(nameIdentifier, "Redeclaration"); +// } +// } +// else if (declarationPsiElement != null) { +// holder.createErrorAnnotation(declarationPsiElement, "Redeclaration"); +// } +// } +// +// @Override +// public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) { +// holder.createErrorAnnotation(node, errorMessage); +// } +// +// @Override +// public void genericWarning(@NotNull ASTNode node, @NotNull String message) { +// holder.createWarningAnnotation(node, message); +// } +// }; if (errorReportingEnabled) { - ErrorHandler.applyHandler(errorHandler, bindingContext); +// ErrorHandler.applyHandler(errorHandler, bindingContext); + Collection diagnostics = bindingContext.getDiagnostics(); + Set redeclarations = new HashSet(); + for (Diagnostic diagnostic : diagnostics) { + if (diagnostic.getSeverity() == Severity.ERROR) { + if (diagnostic instanceof Errors.UnresolvedReferenceDiagnostic) { + Errors.UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (Errors.UnresolvedReferenceDiagnostic) diagnostic; + JetReferenceExpression referenceExpression = unresolvedReferenceDiagnostic.getReference(); + PsiReference reference = referenceExpression.getReference(); + if (reference instanceof MultiRangeReference) { + MultiRangeReference mrr = (MultiRangeReference) reference; + for (TextRange range : mrr.getRanges()) { + holder.createErrorAnnotation(range.shiftRight(referenceExpression.getTextOffset()), "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); + } + } + else { + holder.createErrorAnnotation(referenceExpression, "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); + } + } + else if (diagnostic instanceof Errors.RedeclarationDiagnostic) { + Errors.RedeclarationDiagnostic redeclarationDiagnostic = (Errors.RedeclarationDiagnostic) diagnostic; + markRedeclaration(redeclarations, redeclarationDiagnostic.getA(), bindingContext, holder); + markRedeclaration(redeclarations, redeclarationDiagnostic.getB(), bindingContext, holder); + } + else { + holder.createErrorAnnotation(diagnostic.getFactory().getMarkerPosition(diagnostic), diagnostic.getMessage()); + } + } + else if (diagnostic.getSeverity() == Severity.WARNING) { + holder.createWarningAnnotation(diagnostic.getFactory().getMarkerPosition(diagnostic), diagnostic.getMessage()); + } + } } highlightBackingFields(holder, file, bindingContext); @@ -130,6 +163,20 @@ public class JetPsiChecker implements Annotator { } } } + + private void markRedeclaration(Set redeclarations, DeclarationDescriptor redeclaration, BindingContext bindingContext, AnnotationHolder holder) { + if (!redeclarations.add(redeclaration)) return; + PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, redeclaration); + if (declarationPsiElement instanceof JetNamedDeclaration) { + PsiElement nameIdentifier = ((JetNamedDeclaration) declarationPsiElement).getNameIdentifier(); + if (nameIdentifier != null) { + holder.createErrorAnnotation(nameIdentifier, "Redeclaration"); + } + } + else if (declarationPsiElement != null) { + holder.createErrorAnnotation(declarationPsiElement, "Redeclaration"); + } + } private void highlightBackingFields(final AnnotationHolder holder, JetFile file, final BindingContext bindingContext) { diff --git a/idea/tests/org/jetbrains/jet/JetTestUtils.java b/idea/tests/org/jetbrains/jet/JetTestUtils.java index f3466d5c5db..a4c18e8740e 100644 --- a/idea/tests/org/jetbrains/jet/JetTestUtils.java +++ b/idea/tests/org/jetbrains/jet/JetTestUtils.java @@ -3,6 +3,7 @@ package org.jetbrains.jet; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.ErrorHandler; +import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.JetDiagnostic; import org.jetbrains.jet.lang.psi.JetReferenceExpression; import org.jetbrains.jet.lang.resolve.BindingContext; @@ -67,7 +68,10 @@ public class JetTestUtils { @Override public void report(@NotNull Diagnostic diagnostic) { - throw new UnsupportedOperationException(); // TODO + if (diagnostic instanceof Errors.UnresolvedReferenceDiagnostic) { + Errors.UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (Errors.UnresolvedReferenceDiagnostic) diagnostic; + throw new IllegalStateException("Unresolved: " + unresolvedReferenceDiagnostic.getReference().getText()); + } } }; } diff --git a/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java b/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java index c5230b3a116..60dffcf3152 100644 --- a/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java +++ b/idea/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java @@ -9,11 +9,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetTestCaseBase; import org.jetbrains.jet.JetTestUtils; -import org.jetbrains.jet.lang.diagnostics.ErrorHandler; import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.java.JavaPackageScope; @@ -527,7 +527,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase { } private WritableScopeImpl addImports(JetScope scope) { - WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), ErrorHandler.DO_NOTHING); + WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), DiagnosticHolder.DO_NOTHING); writableScope.importScope(library.getLibraryScope()); JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE); writableScope.importScope(new JavaPackageScope("", null, javaSemanticServices)); @@ -637,7 +637,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase { trace.record(BindingContext.CLASS, classElement, classDescriptor); - final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, trace.getErrorHandler()); + final WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, trace); // This call has side-effects on the parameterScope (fills it in) List typeParameters @@ -656,7 +656,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase { // } boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD); - final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, trace.getErrorHandler()); + final WritableScope memberDeclarations = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, trace); List declarations = classElement.getDeclarations(); for (JetDeclaration declaration : declarations) {