fix error reporting in CodegenTestCase
This commit is contained in:
@@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
@@ -23,6 +24,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GenerationState {
|
||||
@NotNull
|
||||
private final ClassFileFactory factory;
|
||||
private final Project project;
|
||||
|
||||
@@ -38,6 +40,7 @@ public class GenerationState {
|
||||
this.intrinsics = new IntrinsicMethods(project, standardLibrary);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassFileFactory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
@@ -107,6 +108,7 @@ public class CompileSession {
|
||||
return !errorCollector.hasErrors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassFileFactory generate() {
|
||||
GenerationState generationState = new GenerationState(myEnvironment.getProject(), ClassBuilderFactory.BINARIES);
|
||||
generationState.compileCorrectFiles(myBindingContext, mySourceFiles);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -109,13 +110,13 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
return loadRootNamespaceClass(state);
|
||||
}
|
||||
|
||||
protected Class loadRootNamespaceClass(ClassFileFactory state) {
|
||||
protected Class loadRootNamespaceClass(@NotNull ClassFileFactory state) {
|
||||
String fqName = NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(myFile)).replace("/", ".");
|
||||
Map<String, Class> classMap = loadAllClasses(state);
|
||||
return classMap.get(fqName);
|
||||
}
|
||||
|
||||
protected Class loadClass(String fqName, ClassFileFactory state) {
|
||||
protected Class loadClass(String fqName, @NotNull ClassFileFactory state) {
|
||||
List<String> files = state.files();
|
||||
for (String file : files) {
|
||||
if (file.equals(fqName.replace('.', '/') + ".class")) {
|
||||
@@ -128,7 +129,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Map<String, Class> loadAllClasses(ClassFileFactory state) {
|
||||
protected Map<String, Class> loadAllClasses(@NotNull ClassFileFactory state) {
|
||||
Map<String, Class> result = new HashMap<String, Class>();
|
||||
for (String fileName : state.files()) {
|
||||
String className = StringUtil.trimEnd(fileName, ".class").replace('/', '.');
|
||||
@@ -139,6 +140,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
try {
|
||||
GenerationState state = new GenerationState(getProject(), ClassBuilderFactory.BINARIES);
|
||||
@@ -200,7 +202,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
assertTrue(Math.abs(returnValue - currentTime) <= 1L);
|
||||
}
|
||||
|
||||
protected Class loadImplementationClass(ClassFileFactory codegens, final String name) {
|
||||
protected Class loadImplementationClass(@NotNull ClassFileFactory codegens, final String name) {
|
||||
return loadClass(name, codegens);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
|
||||
@@ -30,6 +32,7 @@ public class StdlibTest extends CodegenTestCase {
|
||||
return session.generateText();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
try {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
@@ -38,7 +41,7 @@ public class StdlibTest extends CodegenTestCase {
|
||||
session.addStdLibSources(true);
|
||||
|
||||
if (!session.analyze(System.out)) {
|
||||
return null;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
return session.generate();
|
||||
|
||||
Reference in New Issue
Block a user