Internal compiler errors are reported as warnings, and individually namespace-by-namespace. To make it easier to work even in the presence of some bug-triggering code in the current project

This commit is contained in:
Andrey Breslav
2011-11-12 18:13:11 +04:00
parent 3193b7d2c4
commit 5bb226627f
3 changed files with 33 additions and 2 deletions
@@ -0,0 +1,16 @@
package org.jetbrains.jet.codegen;
/**
* @author abreslav
*/
public interface CompilationErrorHandler {
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
@Override
public void reportError(String message, String fileUrl) {
throw new IllegalStateException(message);
}
};
void reportError(String message, String fileUrl);
}
@@ -100,11 +100,20 @@ public class GenerationState {
} }
public void compileCorrectNamespaces(BindingContext bindingContext, List<JetNamespace> namespaces) { public void compileCorrectNamespaces(BindingContext bindingContext, List<JetNamespace> namespaces) {
compileCorrectNamespaces(bindingContext, namespaces, CompilationErrorHandler.THROW_EXCEPTION);
}
public void compileCorrectNamespaces(BindingContext bindingContext, List<JetNamespace> namespaces, CompilationErrorHandler errorHandler) {
typeMapper = new JetTypeMapper(standardLibrary, bindingContext); typeMapper = new JetTypeMapper(standardLibrary, bindingContext);
bindingContexts.push(bindingContext); bindingContexts.push(bindingContext);
try { try {
for (JetNamespace namespace : namespaces) { for (JetNamespace namespace : namespaces) {
generateNamespace(namespace); try {
generateNamespace(namespace);
}
catch (Throwable e) {
errorHandler.reportError("Exception: " + e.getClass().getCanonicalName() + ": " + e.getMessage(), namespace.getContainingFile().getVirtualFile().getUrl());
}
} }
} }
finally { finally {
@@ -18,6 +18,7 @@ import com.intellij.util.Chunk;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.ClassBuilderFactory; import org.jetbrains.jet.codegen.ClassBuilderFactory;
import org.jetbrains.jet.codegen.ClassFileFactory; import org.jetbrains.jet.codegen.ClassFileFactory;
import org.jetbrains.jet.codegen.CompilationErrorHandler;
import org.jetbrains.jet.codegen.GenerationState; import org.jetbrains.jet.codegen.GenerationState;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Diagnostic;
@@ -101,7 +102,12 @@ public class JetCompiler implements TranslatingCompiler {
} }
if (!errors) { if (!errors) {
generationState.compileCorrectNamespaces(bindingContext, namespaces); generationState.compileCorrectNamespaces(bindingContext, namespaces, new CompilationErrorHandler() {
@Override
public void reportError(String message, String fileUrl) {
compileContext.addMessage(CompilerMessageCategory.WARNING, message, fileUrl, 0, 0);
}
});
/////////// ///////////
// GenerationState generationState2 = new GenerationState(compileContext.getProject(), ClassBuilderFactory.TEXT); // GenerationState generationState2 = new GenerationState(compileContext.getProject(), ClassBuilderFactory.TEXT);
// generationState2.compileCorrectNamespaces(bindingContext, namespaces); // generationState2.compileCorrectNamespaces(bindingContext, namespaces);