From 12a890508fac2d7af30ebda65c3f0c2ad652dfe6 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 16 Dec 2011 12:27:40 +0400 Subject: [PATCH] Debug highlighting for error types --- .../jetbrains/jet/lang/types/ErrorUtils.java | 21 +++++++++++++++---- .../annotations/DebugInfoAnnotator.java | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) 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 2025559fc74..191e0bfba70 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -1,6 +1,7 @@ package org.jetbrains.jet.lang.types; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; @@ -196,10 +197,22 @@ public class ErrorUtils { } public static boolean isErrorType(@NotNull JetType type) { - return type != TypeUtils.NO_EXPECTED_TYPE &&( - (type instanceof DeferredType && ((DeferredType) type).getActualType() == null) || - type instanceof ErrorTypeImpl || - isError(type.getConstructor())); + return type != TypeUtils.NO_EXPECTED_TYPE && !(type instanceof NamespaceType) && + ( + (type instanceof DeferredType && ((DeferredType) type).getActualType() == null) || + type instanceof ErrorTypeImpl || + isError(type.getConstructor()) + ); + } + + public static boolean containsErrorType(@Nullable JetType type) { + if (type == null) return false; + if (type instanceof NamespaceType) return false; + if (isErrorType(type)) return true; + for (TypeProjection projection : type.getArguments()) { + if (containsErrorType(projection.getType())) return true; + } + return false; } public static boolean isError(@NotNull DeclarationDescriptor candidate) { diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java b/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java index 8d87ba88ef5..68aae0586f1 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java +++ b/idea/src/org/jetbrains/jet/plugin/annotations/DebugInfoAnnotator.java @@ -17,6 +17,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.calls.ResolvedCallImpl; import org.jetbrains.jet.lang.types.ErrorUtils; +import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.plugin.JetHighlighter; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; @@ -102,7 +103,8 @@ public class DebugInfoAnnotator implements Annotator { } boolean resolved = target != null; boolean unresolved = unresolvedReferences.contains(expression); - if (declarationDescriptor != null && !ApplicationManager.getApplication().isUnitTestMode() && ErrorUtils.isError(declarationDescriptor)) { + JetType expressionType = bindingContext.get(EXPRESSION_TYPE, expression); + if (declarationDescriptor != null && !ApplicationManager.getApplication().isUnitTestMode() && (ErrorUtils.isError(declarationDescriptor) || ErrorUtils.containsErrorType(expressionType))) { holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").setTextAttributes(JetHighlighter.JET_RESOLVED_TO_ERROR); } if (resolved && unresolved) {