use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.
the class LoadDescriptorUtil method loadTestPackageAndBindingContextFromJavaRoot.
@NotNull
public static Pair<PackageViewDescriptor, BindingContext> loadTestPackageAndBindingContextFromJavaRoot(@NotNull File javaRoot, @NotNull Disposable disposable, @NotNull TestJdkKind testJdkKind, @NotNull ConfigurationKind configurationKind, boolean isBinaryRoot) {
List<File> javaBinaryRoots = new ArrayList<File>();
javaBinaryRoots.add(KotlinTestUtils.getAnnotationsJar());
List<File> javaSourceRoots = new ArrayList<File>();
javaSourceRoots.add(new File("compiler/testData/loadJava/include"));
if (isBinaryRoot) {
javaBinaryRoots.add(javaRoot);
} else {
javaSourceRoots.add(javaRoot);
}
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(configurationKind, testJdkKind, javaBinaryRoots, javaSourceRoots);
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
AnalysisResult analysisResult = JvmResolveUtil.analyze(environment);
PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
return Pair.create(packageView, analysisResult.getBindingContext());
}
use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.
the class CodegenTestUtil method generateFiles.
@NotNull
public static ClassFileFactory generateFiles(@NotNull KotlinCoreEnvironment environment, @NotNull CodegenTestFiles files, @NotNull ClassBuilderFactory classBuilderFactory) {
AnalysisResult analysisResult = JvmResolveUtil.analyzeAndCheckForErrors(files.getPsiFiles(), environment);
analysisResult.throwIfError();
AnalyzingUtils.throwExceptionOnErrors(analysisResult.getBindingContext());
CompilerConfiguration configuration = environment.getConfiguration();
GenerationState state = new GenerationState(environment.getProject(), classBuilderFactory, analysisResult.getModuleDescriptor(), analysisResult.getBindingContext(), files.getPsiFiles(), configuration);
if (analysisResult.getShouldGenerateCode()) {
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
}
// For JVM-specific errors
AnalyzingUtils.throwExceptionOnErrors(state.getCollectedExtraJvmDiagnostics());
return state.getFactory();
}
use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.
the class AbstractAnnotationDescriptorResolveTest method getFile.
@NotNull
protected KtFile getFile(@NotNull String content) {
KtFile ktFile = KotlinTestUtils.createFile("dummy.kt", content, getProject());
AnalysisResult analysisResult = KotlinTestUtils.analyzeFile(ktFile, getEnvironment());
context = analysisResult.getBindingContext();
return ktFile;
}
use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.
the class RecursiveDescriptorProcessorTest method testRecursive.
public void testRecursive() throws Exception {
File ktFile = new File("compiler/testData/recursiveProcessor/declarations.kt");
File txtFile = new File("compiler/testData/recursiveProcessor/declarations.txt");
String text = FileUtil.loadFile(ktFile, true);
KtFile jetFile = KotlinTestUtils.createFile("declarations.kt", text, getEnvironment().getProject());
AnalysisResult result = KotlinTestUtils.analyzeFile(jetFile, getEnvironment());
PackageViewDescriptor testPackage = result.getModuleDescriptor().getPackage(FqName.topLevel(Name.identifier("test")));
List<String> descriptors = recursivelyCollectDescriptors(testPackage);
StringBuilder builder = new StringBuilder();
Printer p = new Printer(builder);
for (String descriptor : descriptors) {
p.println(descriptor);
}
String actualText = builder.toString();
if (!txtFile.exists()) {
FileUtil.writeToFile(txtFile, actualText);
fail("Test data file did not exist and was created from the results of the test: " + txtFile);
}
assertSameLinesWithFile(txtFile.getAbsolutePath(), actualText);
}
Aggregations