Added centralized positioning for front-end exceptions

This commit is contained in:
Andrey Breslav
2014-12-23 17:52:29 +03:00
parent e4ce723eae
commit 93326d8643
2 changed files with 60 additions and 24 deletions
@@ -16,8 +16,10 @@
package org.jetbrains.jet.lang.types.expressions; package org.jetbrains.jet.lang.types.expressions;
import com.intellij.openapi.progress.ProcessCanceledException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
@@ -26,6 +28,7 @@ import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetTypeInfo; import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.util.ReenteringLazyValueComputationException; import org.jetbrains.jet.util.ReenteringLazyValueComputationException;
import org.jetbrains.jet.utils.KotlinFrontEndException;
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM; import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo; import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo;
@@ -123,35 +126,49 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
@NotNull @NotNull
private JetTypeInfo getTypeInfo(@NotNull JetExpression expression, ExpressionTypingContext context, JetVisitor<JetTypeInfo, ExpressionTypingContext> visitor) { private JetTypeInfo getTypeInfo(@NotNull JetExpression expression, ExpressionTypingContext context, JetVisitor<JetTypeInfo, ExpressionTypingContext> visitor) {
JetTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
if (recordedTypeInfo != null) {
return recordedTypeInfo;
}
JetTypeInfo result;
try { try {
result = expression.accept(visitor, context); JetTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
// Some recursive definitions (object expressions) must put their types in the cache manually: if (recordedTypeInfo != null) {
if (context.trace.get(BindingContext.PROCESSED, expression)) { return recordedTypeInfo;
return JetTypeInfo.create(context.trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression), }
result.getDataFlowInfo()); JetTypeInfo result;
} try {
result = expression.accept(visitor, context);
if (result.getType() instanceof DeferredType) { // Some recursive definitions (object expressions) must put their types in the cache manually:
result = JetTypeInfo.create(((DeferredType) result.getType()).getDelegate(), result.getDataFlowInfo()); if (context.trace.get(BindingContext.PROCESSED, expression)) {
} return JetTypeInfo.create(context.trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression),
if (result.getType() != null) { result.getDataFlowInfo());
context.trace.record(BindingContext.EXPRESSION_TYPE, expression, result.getType()); }
if (result.getType() instanceof DeferredType) {
result = JetTypeInfo.create(((DeferredType) result.getType()).getDelegate(), result.getDataFlowInfo());
}
if (result.getType() != null) {
context.trace.record(BindingContext.EXPRESSION_TYPE, expression, result.getType());
}
}
catch (ReenteringLazyValueComputationException e) {
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
result = JetTypeInfo.create(null, context.dataFlowInfo);
} }
context.trace.record(BindingContext.PROCESSED, expression);
recordScopeAndDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression);
return result;
} }
catch (ReenteringLazyValueComputationException e) { catch (ProcessCanceledException e) {
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression)); throw e;
result = JetTypeInfo.create(null, context.dataFlowInfo); }
catch (KotlinFrontEndException e) {
throw e;
}
catch (Throwable e) {
throw new KotlinFrontEndException(
"Exception while analyzing expression at " + DiagnosticUtils.atLocation(expression) + ":\n" + expression.getText() + "\n",
e
);
} }
context.trace.record(BindingContext.PROCESSED, expression);
recordScopeAndDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression);
return result;
} }
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2014 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.utils
public class KotlinFrontEndException(message: String, cause: Throwable) : RuntimeException(message, cause)