Search in sources :

Example 1 with AnalysisResult

use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.

the class K2JSCompiler method analyzeAndReportErrors.

private static AnalyzerWithCompilerReport analyzeAndReportErrors(@NotNull MessageCollector messageCollector, @NotNull final List<KtFile> sources, @NotNull final JsConfig config) {
    AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(messageCollector);
    analyzerWithCompilerReport.analyzeAndReport(sources, new AnalyzerWithCompilerReport.Analyzer() {

        @NotNull
        @Override
        public AnalysisResult analyze() {
            return TopDownAnalyzerFacadeForJS.analyzeFiles(sources, config);
        }

        @Override
        public void reportEnvironmentErrors() {
        }
    });
    return analyzerWithCompilerReport;
}
Also used : AnalyzerWithCompilerReport(org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport) NotNull(org.jetbrains.annotations.NotNull) JsAnalysisResult(org.jetbrains.kotlin.js.analyzer.JsAnalysisResult) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult)

Example 2 with AnalysisResult

use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.

the class AbstractLoadJavaTest method doTestJavaAgainstKotlin.

protected void doTestJavaAgainstKotlin(String expectedFileName) throws Exception {
    File expectedFile = new File(expectedFileName);
    File sourcesDir = new File(expectedFileName.replaceFirst("\\.txt$", ""));
    FileUtil.copyDir(sourcesDir, new File(tmpdir, "test"), new FileFilter() {

        @Override
        public boolean accept(@NotNull File pathname) {
            return pathname.getName().endsWith(".java");
        }
    });
    CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, getJdkKind());
    ContentRootsKt.addKotlinSourceRoot(configuration, sourcesDir.getAbsolutePath());
    JvmContentRootsKt.addJavaSourceRoot(configuration, new File("compiler/testData/loadJava/include"));
    JvmContentRootsKt.addJavaSourceRoot(configuration, tmpdir);
    final KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    AnalysisResult result = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(environment.getProject(), environment.getSourceFiles(), new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), configuration, new Function1<GlobalSearchScope, PackagePartProvider>() {

        @Override
        public PackagePartProvider invoke(GlobalSearchScope scope) {
            return new JvmPackagePartProvider(environment, scope);
        }
    });
    PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
    checkJavaPackage(expectedFile, packageView, result.getBindingContext(), COMPARATOR_CONFIGURATION);
}
Also used : CliLightClassGenerationSupport(org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JvmPackagePartProvider(org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) JvmPackagePartProvider(org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider) FileFilter(java.io.FileFilter) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 3 with AnalysisResult

use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.

the class AbstractPseudocodeTest method doTest.

protected void doTest(String fileName) throws Exception {
    File file = new File(fileName);
    KtFile jetFile = KotlinTestUtils.loadJetFile(getProject(), file);
    SetMultimap<KtElement, Pseudocode> data = LinkedHashMultimap.create();
    AnalysisResult analysisResult = KotlinTestUtils.analyzeFile(jetFile, getEnvironment());
    List<KtDeclaration> declarations = jetFile.getDeclarations();
    BindingContext bindingContext = analysisResult.getBindingContext();
    for (KtDeclaration declaration : declarations) {
        addDeclaration(data, bindingContext, declaration);
        if (declaration instanceof KtDeclarationContainer) {
            for (KtDeclaration member : ((KtDeclarationContainer) declaration).getDeclarations()) {
                // Properties and initializers are processed elsewhere
                if (member instanceof KtNamedFunction || member instanceof KtSecondaryConstructor) {
                    addDeclaration(data, bindingContext, member);
                }
            }
        }
    }
    try {
        processCFData(file, data, bindingContext);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if ("true".equals(System.getProperty("kotlin.control.flow.test.dump.graphs"))) {
            CFGraphToDotFilePrinter.dumpDot(file, data.values());
        }
    }
}
Also used : IOException(java.io.IOException) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) Pseudocode(org.jetbrains.kotlin.cfg.pseudocode.Pseudocode) File(java.io.File)

Example 4 with AnalysisResult

use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testNoWarningsOnJavaKotlinInheritance.

public void testNoWarningsOnJavaKotlinInheritance() throws Exception {
    // This test checks that there are no PARAMETER_NAME_CHANGED_ON_OVERRIDE or DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES
    // warnings when subclassing in Kotlin from Java binaries (in case when no parameter names are available for Java classes)
    KotlinTestUtils.compileJavaFiles(Collections.singletonList(getTestDataFileWithExtension("java")), Arrays.asList("-d", tmpdir.getPath()));
    KotlinCoreEnvironment environment = createEnvironment(Collections.singletonList(tmpdir));
    AnalysisResult result = JvmResolveUtil.analyze(KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment);
    result.throwIfError();
    BindingContext bindingContext = result.getBindingContext();
    AnalyzerWithCompilerReport.Companion.reportDiagnostics(bindingContext.getDiagnostics(), new PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false));
    assertEquals("There should be no diagnostics", 0, Iterables.size(bindingContext.getDiagnostics()));
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PrintingMessageCollector(org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)

Example 5 with AnalysisResult

use of org.jetbrains.kotlin.analyzer.AnalysisResult in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method analyzeFileToPackageView.

@NotNull
private PackageViewDescriptor analyzeFileToPackageView(@NotNull File... extraClassPath) throws IOException {
    KotlinCoreEnvironment environment = createEnvironment(Arrays.asList(extraClassPath));
    AnalysisResult result = JvmResolveUtil.analyzeAndCheckForErrors(KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment);
    PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
    assertFalse("Failed to find package: " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
    return packageView;
}
Also used : KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult) PackageViewDescriptor(org.jetbrains.kotlin.descriptors.PackageViewDescriptor) NotNull(org.jetbrains.annotations.NotNull)

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