Search in sources :

Example 1 with PrintingMessageCollector

use of org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector 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 2 with PrintingMessageCollector

use of org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector in project kotlin by JetBrains.

the class StdlibTest method createEnvironment.

@Override
protected KotlinCoreEnvironment createEnvironment() {
    @SuppressWarnings("deprecation") File[] runtimeClasspath = ForTestCompileRuntime.runtimeClassesForTests();
    CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_NO_RUNTIME, TestJdkKind.FULL_JDK, runtimeClasspath);
    JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.kotlinTestJarForTests());
    File junitJar = new File("libraries/lib/junit-4.11.jar");
    assertTrue(junitJar.exists());
    JvmContentRootsKt.addJvmClasspathRoot(configuration, junitJar);
    ContentRootsKt.addKotlinSourceRoot(configuration, KotlinTestUtils.getHomeDirectory() + "/libraries/stdlib/test");
    configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, new PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false));
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    ModuleVisibilityManager moduleVisibilityManager = ModuleVisibilityManager.SERVICE.getInstance(environment.getProject());
    for (File path : runtimeClasspath) {
        moduleVisibilityManager.addFriendPath(path.getPath());
    }
    return environment;
}
Also used : ModuleVisibilityManager(org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager) KotlinCoreEnvironment(org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment) CompilerConfiguration(org.jetbrains.kotlin.config.CompilerConfiguration) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) PrintingMessageCollector(org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)

Example 3 with PrintingMessageCollector

use of org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector in project kotlin by JetBrains.

the class BasicTest method translateFiles.

private void translateFiles(@NotNull List<KtFile> jetFiles, @NotNull File outputFile, @NotNull MainCallParameters mainCallParameters, @NotNull JsConfig config) throws Exception {
    K2JSTranslator translator = new K2JSTranslator(config);
    TranslationResult translationResult = translator.translate(jetFiles, mainCallParameters);
    if (!(translationResult instanceof TranslationResult.Success)) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PrintingMessageCollector collector = new PrintingMessageCollector(new PrintStream(outputStream), MessageRenderer.PLAIN_FULL_PATHS, true);
        AnalyzerWithCompilerReport.Companion.reportDiagnostics(translationResult.getDiagnostics(), collector);
        String messages = new String(outputStream.toByteArray(), "UTF-8");
        throw new AssertionError("The following errors occurred compiling test:\n" + messages);
    }
    TranslationResult.Success successResult = (TranslationResult.Success) translationResult;
    OutputFileCollection outputFiles = successResult.getOutputFiles(outputFile, getOutputPrefixFile(), getOutputPostfixFile());
    File outputDir = outputFile.getParentFile();
    assert outputDir != null : "Parent file for output file should not be null, outputFilePath: " + outputFile.getPath();
    OutputUtilsKt.writeAllTo(outputFiles, outputDir);
    processJsProgram(successResult.getProgram(), jetFiles);
}
Also used : PrintStream(java.io.PrintStream) OutputFileCollection(org.jetbrains.kotlin.backend.common.output.OutputFileCollection) K2JSTranslator(org.jetbrains.kotlin.js.facade.K2JSTranslator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TranslationResult(org.jetbrains.kotlin.js.facade.TranslationResult) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) JsTestUtils.convertFileNameToDotJsFile(org.jetbrains.kotlin.js.test.utils.JsTestUtils.convertFileNameToDotJsFile) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) PrintingMessageCollector(org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)

Aggregations

PrintingMessageCollector (org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector)3 File (java.io.File)2 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)1 OutputFileCollection (org.jetbrains.kotlin.backend.common.output.OutputFileCollection)1 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)1 K2JSTranslator (org.jetbrains.kotlin.js.facade.K2JSTranslator)1 TranslationResult (org.jetbrains.kotlin.js.facade.TranslationResult)1 JsTestUtils.convertFileNameToDotJsFile (org.jetbrains.kotlin.js.test.utils.JsTestUtils.convertFileNameToDotJsFile)1 ModuleVisibilityManager (org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1