Search in sources :

Example 11 with AnalysisResult

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());
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) ArrayList(java.util.ArrayList) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PackageViewDescriptor(org.jetbrains.kotlin.descriptors.PackageViewDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with AnalysisResult

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();
}
Also used : CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with AnalysisResult

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;
}
Also used : KtFile(org.jetbrains.kotlin.psi.KtFile) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with AnalysisResult

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);
}
Also used : KtFile(org.jetbrains.kotlin.psi.KtFile) Printer(org.jetbrains.kotlin.utils.Printer) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult)

Aggregations

AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)14 File (java.io.File)9 KtFile (org.jetbrains.kotlin.psi.KtFile)8 NotNull (org.jetbrains.annotations.NotNull)7 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)6 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)3 PackageViewDescriptor (org.jetbrains.kotlin.descriptors.PackageViewDescriptor)3 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)3 AnalyzerWithCompilerReport (org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport)2 JsAnalysisResult (org.jetbrains.kotlin.js.analyzer.JsAnalysisResult)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Unit (kotlin.Unit)1 OutputFileCollection (org.jetbrains.kotlin.backend.common.output.OutputFileCollection)1 Pseudocode (org.jetbrains.kotlin.cfg.pseudocode.Pseudocode)1 MessageCollector (org.jetbrains.kotlin.cli.common.messages.MessageCollector)1