preparations to multi-file compilation
This commit is contained in:
@@ -24,23 +24,24 @@ import com.intellij.openapi.progress.ProcessCanceledException;
|
|||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.util.containers.MultiMap;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
import org.jetbrains.jet.di.InjectorForJvmCodegen;
|
import org.jetbrains.jet.di.InjectorForJvmCodegen;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetObjectLiteralExpression;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.utils.Progress;
|
import org.jetbrains.jet.utils.Progress;
|
||||||
import org.objectweb.asm.commons.Method;
|
import org.objectweb.asm.commons.Method;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class GenerationState {
|
public class GenerationState {
|
||||||
private final Project project;
|
private final Project project;
|
||||||
@@ -123,22 +124,29 @@ public class GenerationState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void compileCorrectFiles(@NotNull CompilationErrorHandler errorHandler) {
|
public void compileCorrectFiles(@NotNull CompilationErrorHandler errorHandler) {
|
||||||
|
MultiMap<String, JetFile> namespaceGrouping = new MultiMap<String, JetFile>();
|
||||||
for (JetFile file : this.files) {
|
for (JetFile file : this.files) {
|
||||||
if (file == null) throw new IllegalArgumentException("A null file given for compilation");
|
if (file == null) throw new IllegalArgumentException("A null file given for compilation");
|
||||||
VirtualFile vFile = file.getVirtualFile();
|
namespaceGrouping.putValue(JetPsiUtil.getFQName(file).getFqName(), file);
|
||||||
String path = vFile != null ? vFile.getPath() : "no_virtual_file/" + file.getName();
|
}
|
||||||
progress.log("For source: " + path);
|
|
||||||
try {
|
for (Map.Entry<String, Collection<JetFile>> entry : namespaceGrouping.entrySet()) {
|
||||||
generateNamespace(file);
|
for (JetFile file : entry.getValue()) {
|
||||||
}
|
VirtualFile vFile = file.getVirtualFile();
|
||||||
catch (ProcessCanceledException e) {
|
String path = vFile != null ? vFile.getPath() : "no_virtual_file/" + file.getName();
|
||||||
throw e;
|
progress.log("For source: " + path + "\tFor namespace: " + entry.getKey());
|
||||||
}
|
try {
|
||||||
catch (Throwable e) {
|
generateNamespace(file);
|
||||||
errorHandler.reportException(e, vFile == null ? "no file" : vFile.getUrl());
|
}
|
||||||
DiagnosticUtils.throwIfRunningOnServer(e);
|
catch (ProcessCanceledException e) {
|
||||||
if (ApplicationManager.getApplication().isInternal()) {
|
throw e;
|
||||||
e.printStackTrace();
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
errorHandler.reportException(e, vFile == null ? "no file" : vFile.getUrl());
|
||||||
|
DiagnosticUtils.throwIfRunningOnServer(e);
|
||||||
|
if (ApplicationManager.getApplication().isInternal()) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -92,6 +92,17 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
Predicates.<PsiFile>alwaysTrue(), compilerDependencies);
|
Predicates.<PsiFile>alwaysTrue(), compilerDependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AnalyzeExhaust analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||||
|
Project project, Collection<JetFile> files, List<AnalyzerScriptParameter> scriptParameters, Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||||
|
@NotNull CompilerDependencies compilerDependencies) {
|
||||||
|
AnalyzeExhaust analyzeExhaust = analyzeFilesWithJavaIntegration(
|
||||||
|
project, files, scriptParameters, filesToAnalyzeCompletely, compilerDependencies, false);
|
||||||
|
|
||||||
|
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||||
|
|
||||||
|
return analyzeExhaust;
|
||||||
|
}
|
||||||
|
|
||||||
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
|
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
|
||||||
Project project, Collection<JetFile> files, List<AnalyzerScriptParameter> scriptParameters, Predicate<PsiFile> filesToAnalyzeCompletely,
|
Project project, Collection<JetFile> files, List<AnalyzerScriptParameter> scriptParameters, Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||||
@NotNull CompilerDependencies compilerDependencies) {
|
@NotNull CompilerDependencies compilerDependencies) {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
fun box() = ok()
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
fun ok() = "OK"
|
||||||
@@ -206,8 +206,8 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
|||||||
// String clearText = pattern.matcher(text).replaceAll("");
|
// String clearText = pattern.matcher(text).replaceAll("");
|
||||||
// createAndCheckPsiFile(name, clearText);
|
// createAndCheckPsiFile(name, clearText);
|
||||||
//
|
//
|
||||||
// BindingContext bindingContext = AnalyzingUtils.getInstance(ImportingStrategy.NONE).analyzeFileWithCache((JetFile) myFile);
|
// BindingContext bindingContext = AnalyzingUtils.getInstance(ImportingStrategy.NONE).analyzeFileWithCache((JetFile) myFiles);
|
||||||
// String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(myFile, bindingContext).toString();
|
// String expectedText = CheckerTestUtil.addDiagnosticMarkersToText(myFiles, bindingContext).toString();
|
||||||
//
|
//
|
||||||
// File destFile = new File(dest, file.getName());
|
// File destFile = new File(dest, file.getName());
|
||||||
// FileWriter fileWriter = new FileWriter(destFile);
|
// FileWriter fileWriter = new FileWriter(destFile);
|
||||||
|
|||||||
@@ -17,23 +17,20 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.testFramework.UsefulTestCase;
|
import com.intellij.testFramework.UsefulTestCase;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
|
||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
@@ -48,8 +45,6 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
@@ -59,7 +54,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
// for environment and classloader
|
// for environment and classloader
|
||||||
protected JetCoreEnvironment myEnvironment;
|
protected JetCoreEnvironment myEnvironment;
|
||||||
private List<File> extraClasspath = Lists.newArrayList();
|
private List<File> extraClasspath = Lists.newArrayList();
|
||||||
protected CodegenTestFile myFile;
|
protected CodegenTestFiles myFiles;
|
||||||
|
|
||||||
protected Object scriptInstance;
|
protected Object scriptInstance;
|
||||||
|
|
||||||
@@ -107,26 +102,30 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
myFile = null;
|
myFiles = null;
|
||||||
myEnvironment = null;
|
myEnvironment = null;
|
||||||
scriptInstance = null;
|
scriptInstance = null;
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadText(final String text) {
|
protected void loadText(final String text) {
|
||||||
myFile = CodegenTestFile.create("a.jet", text, myEnvironment.getProject());
|
myFiles = CodegenTestFiles.create("a.jet", text, myEnvironment.getProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String loadFile(final String name) {
|
protected String loadFile(final String name) {
|
||||||
try {
|
try {
|
||||||
final String content = JetTestUtils.doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
|
final String content = JetTestUtils.doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
|
||||||
myFile = CodegenTestFile.create(name, content, myEnvironment.getProject());
|
myFiles = CodegenTestFiles.create(name, content, myEnvironment.getProject());
|
||||||
return content;
|
return content;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void loadFiles(final String... names) {
|
||||||
|
myFiles = CodegenTestFiles.create(myEnvironment.getProject(), names);
|
||||||
|
}
|
||||||
|
|
||||||
protected void loadFile() {
|
protected void loadFile() {
|
||||||
loadFile(getPrefix() + "/" + getTestName(true) + ".jet");
|
loadFile(getPrefix() + "/" + getTestName(true) + ".jet");
|
||||||
}
|
}
|
||||||
@@ -140,6 +139,11 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
blackBox();
|
blackBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void blackBoxMultiFile(String... filenames) {
|
||||||
|
loadFiles(filenames);
|
||||||
|
blackBox();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Class<?> loadClassFromType(@NotNull Type type) {
|
private Class<?> loadClassFromType(@NotNull Type type) {
|
||||||
try {
|
try {
|
||||||
@@ -186,15 +190,15 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
String r;
|
String r;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (myFile.getPsiFile().isScript()) {
|
if (myFiles.isScript()) {
|
||||||
Class<?> scriptClass = loader.loadClass("Script");
|
Class<?> scriptClass = loader.loadClass("Script");
|
||||||
|
|
||||||
Constructor constructor = getConstructor(scriptClass, state.getScriptConstructorMethod());
|
Constructor constructor = getConstructor(scriptClass, state.getScriptConstructorMethod());
|
||||||
scriptInstance = constructor.newInstance(myFile.getScriptParameterValues().toArray());
|
scriptInstance = constructor.newInstance(myFiles.getScriptParameterValues().toArray());
|
||||||
|
|
||||||
assertFalse("expecting at least one expectation", myFile.getExpectedValues().isEmpty());
|
assertFalse("expecting at least one expectation", myFiles.getExpectedValues().isEmpty());
|
||||||
|
|
||||||
for (Pair<String, String> nameValue : myFile.getExpectedValues()) {
|
for (Pair<String, String> nameValue : myFiles.getExpectedValues()) {
|
||||||
String fieldName = nameValue.first;
|
String fieldName = nameValue.first;
|
||||||
String expectedValue = nameValue.second;
|
String expectedValue = nameValue.second;
|
||||||
|
|
||||||
@@ -215,7 +219,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile.getPsiFile())).getFqName().getFqName();
|
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFiles.getPsiFiles().get(0))).getFqName().getFqName();
|
||||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||||
Method method = namespaceClass.getMethod("box");
|
Method method = namespaceClass.getMethod("box");
|
||||||
r = (String) method.invoke(null);
|
r = (String) method.invoke(null);
|
||||||
@@ -250,12 +254,15 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) {
|
private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) {
|
||||||
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors(
|
||||||
myFile.getPsiFile(), myFile.getScriptParameterTypes(),
|
myEnvironment.getProject(),
|
||||||
|
myFiles.getPsiFiles(),
|
||||||
|
myFiles.getScriptParameterTypes(),
|
||||||
|
Predicates.<PsiFile>alwaysTrue(),
|
||||||
myEnvironment.getCompilerDependencies());
|
myEnvironment.getCompilerDependencies());
|
||||||
analyzeExhaust.throwIfError();
|
analyzeExhaust.throwIfError();
|
||||||
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||||
GenerationState state = new GenerationState(myEnvironment.getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile.getPsiFile()));
|
GenerationState state = new GenerationState(myEnvironment.getProject(), classBuilderFactory, analyzeExhaust, myFiles.getPsiFiles());
|
||||||
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -271,7 +278,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Class loadRootNamespaceClass(@NotNull ClassFileFactory state) {
|
protected Class loadRootNamespaceClass(@NotNull ClassFileFactory state) {
|
||||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile.getPsiFile())).getFqName().getFqName();
|
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFiles.getPsiFile())).getFqName().getFqName();
|
||||||
try {
|
try {
|
||||||
return createClassLoader(state).loadClass(fqName);
|
return createClassLoader(state).loadClass(fqName);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
|||||||
+36
-10
@@ -23,21 +23,23 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
||||||
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stepan Koltsov
|
* @author Stepan Koltsov
|
||||||
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class CodegenTestFile {
|
public class CodegenTestFiles {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final JetFile psiFile;
|
private final List<JetFile> psiFiles;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final List<Pair<String, String>> expectedValues;
|
private final List<Pair<String, String>> expectedValues;
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -45,12 +47,12 @@ public class CodegenTestFile {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final List<Object> scriptParameterValues;
|
private final List<Object> scriptParameterValues;
|
||||||
|
|
||||||
private CodegenTestFile(
|
private CodegenTestFiles(
|
||||||
@NotNull JetFile psiFile,
|
@NotNull List<JetFile> psiFiles,
|
||||||
@NotNull List<Pair<String, String>> expectedValues,
|
@NotNull List<Pair<String, String>> expectedValues,
|
||||||
@NotNull List<AnalyzerScriptParameter> scriptParameterTypes,
|
@NotNull List<AnalyzerScriptParameter> scriptParameterTypes,
|
||||||
@NotNull List<Object> scriptParameterValues) {
|
@NotNull List<Object> scriptParameterValues) {
|
||||||
this.psiFile = psiFile;
|
this.psiFiles = psiFiles;
|
||||||
this.expectedValues = expectedValues;
|
this.expectedValues = expectedValues;
|
||||||
this.scriptParameterTypes = scriptParameterTypes;
|
this.scriptParameterTypes = scriptParameterTypes;
|
||||||
this.scriptParameterValues = scriptParameterValues;
|
this.scriptParameterValues = scriptParameterValues;
|
||||||
@@ -58,7 +60,8 @@ public class CodegenTestFile {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetFile getPsiFile() {
|
public JetFile getPsiFile() {
|
||||||
return psiFile;
|
assert psiFiles.size() == 1;
|
||||||
|
return psiFiles.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -77,7 +80,30 @@ public class CodegenTestFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static CodegenTestFile create(@NotNull String fileName, @NotNull String content, @NotNull Project project) {
|
public List<JetFile> getPsiFiles() {
|
||||||
|
return psiFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isScript() {
|
||||||
|
return psiFiles.size() == 1 && psiFiles.get(0).isScript();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CodegenTestFiles create(Project project, String[] names) {
|
||||||
|
ArrayList<JetFile> files = new ArrayList<JetFile>();
|
||||||
|
for (String name : names) {
|
||||||
|
try {
|
||||||
|
String content = JetTestUtils.doLoadFile(JetParsingTest.getTestDataDir() + "/codegen/", name);
|
||||||
|
JetFile file = (JetFile) JetTestUtils.createFile(name, content, project);
|
||||||
|
files.add(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new CodegenTestFiles(files, Collections.<Pair<String, String>>emptyList(), Collections.<AnalyzerScriptParameter>emptyList(), Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static CodegenTestFiles create(@NotNull String fileName, @NotNull String content, @NotNull Project project) {
|
||||||
JetFile file = (JetFile) JetTestUtils.createFile(fileName, content, project);
|
JetFile file = (JetFile) JetTestUtils.createFile(fileName, content, project);
|
||||||
|
|
||||||
List<Pair<String, String>> expectedValues = Lists.newArrayList();
|
List<Pair<String, String>> expectedValues = Lists.newArrayList();
|
||||||
@@ -123,6 +149,6 @@ public class CodegenTestFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CodegenTestFile(file, expectedValues, scriptParameterTypes, scriptParameterValues);
|
return new CodegenTestFiles(Collections.singletonList(file), expectedValues, scriptParameterTypes, scriptParameterValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class MultiFileGenTest extends CodegenTestCase {
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimple() {
|
||||||
|
blackBoxMultiFile("/multi/simple/box.kt", "/multi/simple/ok.kt");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -150,7 +150,7 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
GeneratedClassLoader loader = createClassLoader(codegens);
|
GeneratedClassLoader loader = createClassLoader(codegens);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile.getPsiFile())).getFqName().getFqName();
|
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFiles.getPsiFile())).getFqName().getFqName();
|
||||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||||
Method method = namespaceClass.getMethod("box", Method.class);
|
Method method = namespaceClass.getMethod("box", Method.class);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user