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;
}
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);
}
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());
}
}
}
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()));
}
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;
}
Aggregations