ErrorHandlers removed

This commit is contained in:
Andrey Breslav
2011-09-14 21:10:09 +04:00
parent 84af6a512a
commit 3118b5bbfa
20 changed files with 68 additions and 478 deletions
@@ -8,8 +8,8 @@ import gnu.trove.THashSet;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod;
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.ErrorHandlerUtils;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
@@ -237,11 +237,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
DeclarationDescriptor hasNextDescriptor = bindingContext.get(BindingContext.LOOP_RANGE_HAS_NEXT, loopRange);
if(iteratorDescriptor == null)
throw new IllegalStateException("No iterator() method " + ErrorHandler.atLocation(loopRange));
throw new IllegalStateException("No iterator() method " + ErrorHandlerUtils.atLocation(loopRange));
if(nextDescriptor == null)
throw new IllegalStateException("No next() method " + ErrorHandler.atLocation(loopRange));
throw new IllegalStateException("No next() method " + ErrorHandlerUtils.atLocation(loopRange));
if(hasNextDescriptor == null)
throw new IllegalStateException("No iterator() method " + ErrorHandler.atLocation(loopRange));
throw new IllegalStateException("No iterator() method " + ErrorHandlerUtils.atLocation(loopRange));
final JetParameter loopParameter = expression.getLoopParameter();
final VariableDescriptor parameterDescriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, loopParameter);
@@ -7,7 +7,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.Stack;
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.psi.*;
@@ -91,7 +90,8 @@ public class GenerationState {
bindingContexts.push(bindingContext);
typeMapper = new JetTypeMapper(standardLibrary, bindingContext);
try {
ErrorHandler.applyHandler(ErrorHandler.THROW_EXCEPTION, bindingContext);
AnalyzingUtils.throwExceptionOnErrors(bindingContext);
codegen.generate(namespace);
}
finally {
@@ -1,55 +0,0 @@
package org.jetbrains.jet.lang.diagnostics;
import com.google.common.collect.Lists;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.types.JetType;
import java.util.List;
/**
* @author abreslav
*/
public class CollectingErrorHandler extends ErrorHandler {
private final List<JetDiagnostic> diagnostics;
public CollectingErrorHandler() {
this(Lists.<JetDiagnostic>newArrayList());
}
public CollectingErrorHandler(List<JetDiagnostic> diagnostics) {
this.diagnostics = diagnostics;
}
public List<JetDiagnostic> getDiagnostics() {
return diagnostics;
}
@Override
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
diagnostics.add(new JetDiagnostic.UnresolvedReferenceError(referenceExpression));
}
@Override
public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) {
diagnostics.add(new JetDiagnostic.TypeMismatchError(expression, expectedType, actualType));
}
@Override
public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) {
diagnostics.add(new JetDiagnostic.RedeclarationError(existingDescriptor, redeclaredDescriptor));
}
@Override
public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) {
diagnostics.add(new JetDiagnostic.GenericError(node, errorMessage));
}
@Override
public void genericWarning(@NotNull ASTNode node, @NotNull String message) {
diagnostics.add(new JetDiagnostic.GenericWarning(node, message));
}
}
@@ -1,54 +0,0 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class CompositeErrorHandler extends ErrorHandler {
private final ErrorHandler[] handlers;
public CompositeErrorHandler(ErrorHandler... handlers) {
this.handlers = handlers;
}
@Override
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
for (ErrorHandler handler : handlers) {
handler.unresolvedReference(referenceExpression);
}
}
@Override
public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) {
for (ErrorHandler handler : handlers) {
handler.typeMismatch(expression, expectedType, actualType);
}
}
@Override
public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) {
for (ErrorHandler handler : handlers) {
handler.redeclaration(existingDescriptor, redeclaredDescriptor);
}
}
@Override
public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) {
for (ErrorHandler handler : handlers) {
handler.genericError(node, errorMessage);
}
}
@Override
public void genericWarning(@NotNull ASTNode node, @NotNull String message) {
for (ErrorHandler handler : handlers) {
handler.genericWarning(node, message);
}
}
}
@@ -1,111 +0,0 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collection;
/**
* @author abreslav
*/
public class ErrorHandler {
public static final ErrorHandler DO_NOTHING = new ErrorHandler();
public static final ErrorHandler THROW_EXCEPTION = new ErrorHandler() {
@Override
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
throw new IllegalStateException("Unresolved reference: " + referenceExpression.getText() +
atLocation(referenceExpression));
}
@Override
public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) {
throw new IllegalStateException(errorMessage + " at " + node.getText() + atLocation(node));
}
@Override
public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) {
throw new IllegalStateException("Type mismatch " + atLocation(expression) + ": inferred type is " + actualType + " but " + expectedType + " was expected");
}
@Override
public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) {
throw new IllegalStateException("Redeclaration: " + existingDescriptor.getName());
}
};
public static String atLocation(@NotNull PsiElement element) {
return atLocation(element.getNode());
}
public static String atLocation(@NotNull ASTNode node) {
while (node.getPsi() == null) {
node = node.getTreeParent();
}
PsiElement element = node.getPsi();
Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(element.getContainingFile());
int offset = element.getTextRange().getStartOffset();
if (document != null) {
int lineNumber = document.getLineNumber(offset);
int lineStartOffset = document.getLineStartOffset(lineNumber);
int column = offset - lineStartOffset;
return "' at line " + (lineNumber+1) + ":" + column;
}
else {
return "' at offset " + offset + " (line unknown)";
}
}
public static void applyHandler(@NotNull ErrorHandler errorHandler, @NotNull BindingContext bindingContext) {
Collection<JetDiagnostic> diagnostics = bindingContext.getOld_Diagnostics();
old_applyHandler(errorHandler, diagnostics);
applyHandler(errorHandler, bindingContext.getDiagnostics());
}
public static void applyHandler(@NotNull ErrorHandler errorHandler, @NotNull Collection<Diagnostic> diagnostics) {
for (Diagnostic diagnostic : diagnostics) {
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.WARNING) {
}
}
}
}
public static void old_applyHandler(@NotNull ErrorHandler errorHandler, @NotNull Collection<JetDiagnostic> diagnostics) {
for (JetDiagnostic jetDiagnostic : diagnostics) {
jetDiagnostic.acceptHandler(errorHandler);
}
}
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
}
public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) {
}
public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) {
}
public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) {
}
public void genericWarning(@NotNull ASTNode node, @NotNull String message) {
}
}
@@ -1,44 +0,0 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class ErrorHandlerAdapter extends ErrorHandler {
protected ErrorHandler worker;
public ErrorHandlerAdapter(ErrorHandler worker) {
this.worker = worker;
}
@Override
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
worker.unresolvedReference(referenceExpression);
}
@Override
public void typeMismatch(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) {
worker.typeMismatch(expression, expectedType, actualType);
}
@Override
public void redeclaration(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) {
worker.redeclaration(existingDescriptor, redeclaredDescriptor);
}
@Override
public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) {
worker.genericError(node, errorMessage);
}
@Override
public void genericWarning(@NotNull ASTNode node, @NotNull String message) {
worker.genericWarning(node, message);
}
}
@@ -0,0 +1,35 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public class ErrorHandlerUtils {
public static String atLocation(@NotNull PsiElement element) {
return atLocation(element.getNode());
}
public static String atLocation(@NotNull ASTNode node) {
while (node.getPsi() == null) {
node = node.getTreeParent();
}
PsiElement element = node.getPsi();
Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(element.getContainingFile());
int offset = element.getTextRange().getStartOffset();
if (document != null) {
int lineNumber = document.getLineNumber(offset);
int lineStartOffset = document.getLineStartOffset(lineNumber);
int column = offset - lineStartOffset;
return "' at line " + (lineNumber+1) + ":" + column;
}
else {
return "' at offset " + offset + " (line unknown)";
}
}
}
@@ -236,6 +236,7 @@ public interface Errors {
SimpleDiagnosticFactory MANY_FUNCTION_LITERAL_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Only one function literal is allowed outside a parenthesized argument list");
SimpleDiagnosticFactory PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = SimpleDiagnosticFactory.create(ERROR, "This property must either have a type annotation or be initialized");
SimpleDiagnosticFactory FUNCTION_WITH_NO_TYPE_NO_BODY = SimpleDiagnosticFactory.create(ERROR, "This function must either declare a return type or have a body element");
SimpleDiagnosticFactory ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimpleDiagnosticFactory.create(ERROR, "This property cannot be declared abstract");
SimpleDiagnosticFactory ABSTRACT_PROPERTY_NOT_IN_CLASS = SimpleDiagnosticFactory.create(ERROR, "A property may be abstract only when defined in a class or trait");
@@ -1,111 +0,0 @@
package org.jetbrains.jet.lang.diagnostics;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public abstract class JetDiagnostic {
public static class UnresolvedReferenceError extends JetDiagnostic {
private final JetReferenceExpression referenceExpression;
public UnresolvedReferenceError(@NotNull JetReferenceExpression referenceExpression) {
this.referenceExpression = referenceExpression;
}
@Override
public void acceptHandler(@NotNull ErrorHandler handler) {
handler.unresolvedReference(referenceExpression);
}
@NotNull
public JetReferenceExpression getReferenceExpression() {
return referenceExpression;
}
}
public static class GenericError extends JetDiagnostic {
private final ASTNode node;
private final String message;
public GenericError(@NotNull ASTNode node, @NotNull String message) {
this.node = node;
this.message = message;
}
@Override
public void acceptHandler(@NotNull ErrorHandler handler) {
handler.genericError(node, message);
}
}
public static class TypeMismatchError extends JetDiagnostic {
private final JetExpression expression;
private final JetType expectedType;
private final JetType actualType;
public TypeMismatchError(@NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull JetType actualType) {
this.expression = expression;
this.expectedType = expectedType;
this.actualType = actualType;
}
@Override
public void acceptHandler(@NotNull ErrorHandler handler) {
handler.typeMismatch(expression, expectedType, actualType);
}
}
public static class RedeclarationError extends JetDiagnostic {
private final DeclarationDescriptor existingDescriptor;
private final DeclarationDescriptor redeclaredDescriptor;
public RedeclarationError(@NotNull DeclarationDescriptor existingDescriptor, @NotNull DeclarationDescriptor redeclaredDescriptor) {
this.existingDescriptor = existingDescriptor;
this.redeclaredDescriptor = redeclaredDescriptor;
}
@Override
public void acceptHandler(@NotNull ErrorHandler handler) {
handler.redeclaration(existingDescriptor, redeclaredDescriptor);
}
}
public static class GenericWarning extends JetDiagnostic {
private final ASTNode node;
private final String message;
public GenericWarning(@NotNull ASTNode node, @NotNull String message) {
this.message = message;
this.node = node;
}
@Override
public void acceptHandler(@NotNull ErrorHandler handler) {
handler.genericWarning(node, message);
}
}
// private final StackTraceElement[] stackTrace;
//
// protected JetDiagnostic() {
// stackTrace = Thread.currentThread().getStackTrace();
// }
//
// public StackTraceElement[] getStackTrace() {
// return stackTrace;
// }
public abstract void acceptHandler(@NotNull ErrorHandler handler);
}
@@ -14,8 +14,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.diagnostics.*;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamespace;
@@ -45,11 +44,17 @@ public class AnalyzingUtils {
@Override
public void visitErrorElement(PsiErrorElement element) {
throw new IllegalArgumentException(element.getErrorDescription() + "; looking at " + element.getNode().getElementType() + " '" + element.getText() + ErrorHandler.atLocation(element));
throw new IllegalArgumentException(element.getErrorDescription() + "; looking at " + element.getNode().getElementType() + " '" + element.getText() + ErrorHandlerUtils.atLocation(element));
}
});
}
public static void throwExceptionOnErrors(BindingContext bindingContext) {
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
DiagnosticHolder.THROW_EXCEPTION.report(diagnostic);
}
}
private final ImportingStrategy importingStrategy;
private AnalyzingUtils(ImportingStrategy importingStrategy) {
@@ -2,10 +2,9 @@ package org.jetbrains.jet.lang.resolve;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.JetDiagnostic;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
@@ -112,7 +111,6 @@ public interface BindingContext {
WritableSlice<JetReferenceExpression, PsiElement> LABEL_TARGET = Slices.<JetReferenceExpression, PsiElement>sliceBuilder("LABEL_TARGET").build();
WritableSlice<JetParameter, PropertyDescriptor> VALUE_PARAMETER_AS_PROPERTY = Slices.<JetParameter, PropertyDescriptor>sliceBuilder("VALUE_PARAMETER_AS_PROPERTY").build();
Collection<JetDiagnostic> getOld_Diagnostics();
Collection<Diagnostic> getDiagnostics();
@Nullable
@@ -1,9 +1,7 @@
package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
@@ -12,9 +10,6 @@ import org.jetbrains.jet.util.slicedmap.WritableSlice;
*/
public interface BindingTrace extends DiagnosticHolder {
@NotNull
ErrorHandler getErrorHandler();
BindingContext getBindingContext();
<K, V> void record(WritableSlice<K, V> slice, K key, V value);
@@ -3,7 +3,6 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
@@ -29,12 +28,6 @@ public class BindingTraceAdapter implements BindingTrace {
originalTrace.report(diagnostic);
}
@Override
@NotNull
public ErrorHandler getErrorHandler() {
return originalTrace.getErrorHandler();
}
@Override
public BindingContext getBindingContext() {
return originalTrace.getBindingContext();
@@ -2,10 +2,7 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.CollectingErrorHandler;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.lang.diagnostics.JetDiagnostic;
import org.jetbrains.jet.util.slicedmap.MutableSlicedMap;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import org.jetbrains.jet.util.slicedmap.SlicedMapImpl;
@@ -19,16 +16,10 @@ import java.util.List;
*/
public class BindingTraceContext implements BindingTrace {
private final List<Diagnostic> diagnostics = Lists.newArrayList();
private final List<JetDiagnostic> old_diagnostics = Lists.newArrayList();
private final ErrorHandler errorHandler = new CollectingErrorHandler(old_diagnostics);
private final MutableSlicedMap map = SlicedMapImpl.create();
private final BindingContext bindingContext = new BindingContext() {
@Override
public Collection<JetDiagnostic> getOld_Diagnostics() {
return old_diagnostics;
}
@Override
public Collection<Diagnostic> getDiagnostics() {
@@ -46,12 +37,6 @@ public class BindingTraceContext implements BindingTrace {
diagnostics.add(diagnostic);
}
@NotNull
@Override
public ErrorHandler getErrorHandler() {
return errorHandler;
}
@Override
public BindingContext getBindingContext() {
return bindingContext;
@@ -180,7 +180,8 @@ public class ClassDescriptorResolver {
});
}
else {
trace.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
// trace.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
trace.report(FUNCTION_WITH_NO_TYPE_NO_BODY.on(function.asElement()));
returnType = ErrorUtils.createErrorType("No type, no body");
}
}
@@ -2,10 +2,7 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.CollectingErrorHandler;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.lang.diagnostics.JetDiagnostic;
import org.jetbrains.jet.util.slicedmap.*;
import java.util.Collection;
@@ -18,16 +15,9 @@ import java.util.Map;
public class DelegatingBindingTrace implements BindingTrace {
private final BindingContext parentContext;
private final MutableSlicedMap map = SlicedMapImpl.create();
private final List<JetDiagnostic> old_diagnostics = Lists.newArrayList();
private final List<Diagnostic> diagnostics = Lists.newArrayList();
private final ErrorHandler errorHandler = new CollectingErrorHandler(old_diagnostics);
private final BindingContext bindingContext = new BindingContext() {
@Override
public Collection<JetDiagnostic> getOld_Diagnostics() {
throw new UnsupportedOperationException(); // TODO
}
@Override
public Collection<Diagnostic> getDiagnostics() {
throw new UnsupportedOperationException(); // TODO
@@ -43,12 +33,6 @@ public class DelegatingBindingTrace implements BindingTrace {
this.parentContext = parentContext;
}
@Override
@NotNull
public ErrorHandler getErrorHandler() {
return errorHandler;
}
@Override
public BindingContext getBindingContext() {
return bindingContext;
@@ -81,8 +65,6 @@ public class DelegatingBindingTrace implements BindingTrace {
trace.record(slicedMapKey.getSlice(), slicedMapKey.getKey(), value);
}
ErrorHandler.old_applyHandler(trace.getErrorHandler(), old_diagnostics);
for (Diagnostic diagnostic : diagnostics) {
trace.report(diagnostic);
}
@@ -4,11 +4,12 @@ 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.*;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionGroup;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.plugin.JetFileType;
@@ -103,7 +104,8 @@ public class JetStandardLibrary {
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
ErrorHandler.applyHandler(ErrorHandler.THROW_EXCEPTION, bindingTraceContext.getBindingContext());
AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());
this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte");
this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char");
@@ -15,9 +15,7 @@ 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.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.*;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
@@ -470,18 +468,6 @@ 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;
}
}
});
}
@Override
public void report(@NotNull Diagnostic diagnostic) {
@@ -2,10 +2,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;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
@@ -19,27 +16,11 @@ import java.util.Collection;
public class JetTestUtils {
public static final BindingTrace DUMMY_TRACE = new BindingTrace() {
@NotNull
@Override
public ErrorHandler getErrorHandler() {
return new ErrorHandler() {
@Override
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
throw new IllegalStateException("Unresolved: " + referenceExpression.getText());
}
};
}
@Override
public BindingContext getBindingContext() {
return new BindingContext() {
@Override
public Collection<JetDiagnostic> getOld_Diagnostics() {
throw new UnsupportedOperationException(); // TODO
}
@Override
public Collection<Diagnostic> getDiagnostics() {
throw new UnsupportedOperationException(); // TODO
@@ -4,11 +4,12 @@ import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.ErrorHandler;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.ErrorHandlerUtils;
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.resolve.BindingContextUtils;
@@ -96,12 +97,12 @@ public class ExpectedResolveData {
JetStandardLibrary lib = semanticServices.getStandardLibrary();
BindingContext bindingContext = AnalyzerFacade.analyzeNamespace(file.getRootNamespace(), JetControlFlowDataTraceFactory.EMPTY);
ErrorHandler.applyHandler(new ErrorHandler() {
@Override
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
unresolvedReferences.add(referenceExpression);
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
if (diagnostic instanceof Errors.UnresolvedReferenceDiagnostic) {
Errors.UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (Errors.UnresolvedReferenceDiagnostic) diagnostic;
unresolvedReferences.add(unresolvedReferenceDiagnostic.getReference());
}
}, bindingContext);
}
Map<String, JetDeclaration> nameToDeclaration = new HashMap<String, JetDeclaration>();
@@ -277,7 +278,7 @@ public class ExpectedResolveData {
return referenceExpression.getText() + " at " + ErrorHandler.atLocation(referenceExpression) +
return referenceExpression.getText() + " at " + ErrorHandlerUtils.atLocation(referenceExpression) +
" in " + statement.getText() + (declaration == null ? "" : " in " + declaration.getText());
}