Sealed classes: extra java against kotlin tests, together with an implementation of Java diagnostics inside these tests
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package test;
|
||||
|
||||
// It's not possible to inherit from Season (it's sealed in Kotlin)
|
||||
public class Derived extends Season {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Derived.java:4:8:compiler.err.report.access
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
public sealed class Season {
|
||||
class Warm: Season()
|
||||
class Cold: Season()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package test
|
||||
|
||||
public sealed class Season {
|
||||
private constructor Season()
|
||||
|
||||
internal final class Cold : test.Season {
|
||||
public constructor Cold()
|
||||
}
|
||||
|
||||
internal final class Warm : test.Season {
|
||||
public constructor Warm()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package test;
|
||||
|
||||
public class Instance {
|
||||
// It is not possible to create Season instance (it's sealed in Kotlin)
|
||||
static Season create() {
|
||||
return new Season();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Instance.java:6:16:compiler.err.abstract.cant.be.instantiated
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
public sealed class Season {
|
||||
class Warm: Season()
|
||||
class Cold: Season()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package test
|
||||
|
||||
public sealed class Season {
|
||||
private constructor Season()
|
||||
|
||||
internal final class Cold : test.Season {
|
||||
public constructor Cold()
|
||||
}
|
||||
|
||||
internal final class Warm : test.Season {
|
||||
public constructor Warm()
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -64,9 +64,11 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
||||
File ktFile = new File(ktFilePath);
|
||||
File javaFile = new File(ktFilePath.replaceFirst("\\.kt$", ".java"));
|
||||
File expectedFile = new File(ktFilePath.replaceFirst("\\.kt$", ".txt"));
|
||||
File javaErrorFile = new File(ktFilePath.replaceFirst("\\.kt$", ".javaerr.txt"));
|
||||
|
||||
File out = new File(tmpdir, "out");
|
||||
compileKotlinWithJava(Collections.singletonList(javaFile), Collections.singletonList(ktFile), out, getTestRootDisposable());
|
||||
compileKotlinWithJava(Collections.singletonList(javaFile), Collections.singletonList(ktFile),
|
||||
out, getTestRootDisposable(), javaErrorFile);
|
||||
|
||||
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(
|
||||
getTestRootDisposable(),
|
||||
|
||||
@@ -170,7 +170,8 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
FileUtil.findFilesByMask(Pattern.compile(".+\\.java$"), librarySrc),
|
||||
FileUtil.findFilesByMask(Pattern.compile(".+\\.kt$"), librarySrc),
|
||||
libraryOut,
|
||||
getTestRootDisposable()
|
||||
getTestRootDisposable(),
|
||||
null
|
||||
);
|
||||
|
||||
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(
|
||||
|
||||
+21
@@ -494,6 +494,27 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/compileJavaAgainstKotlin/sealed")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Sealed extends AbstractCompileJavaAgainstKotlinTest {
|
||||
public void testAllFilesPresentInSealed() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileJavaAgainstKotlin/sealed"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("Derived.kt")
|
||||
public void testDerived() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Derived.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Instance.kt")
|
||||
public void testInstance() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/compileJavaAgainstKotlin/sealed/Instance.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/compileJavaAgainstKotlin/staticFields")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -49,7 +49,7 @@ public class KotlinClassFinderTest : KotlinTestWithEnvironmentManagement() {
|
||||
fun testNestedClass() {
|
||||
val tmpdir = JetTestUtils.tmpDirForTest(this)
|
||||
JetTestUtils.compileKotlinWithJava(
|
||||
listOf(), listOf(File("compiler/testData/kotlinClassFinder/nestedClass.kt")), tmpdir, getTestRootDisposable()!!
|
||||
listOf(), listOf(File("compiler/testData/kotlinClassFinder/nestedClass.kt")), tmpdir, getTestRootDisposable()!!, null
|
||||
)
|
||||
|
||||
val environment = createEnvironment(tmpdir)
|
||||
|
||||
@@ -526,7 +526,8 @@ public class JetTestUtils {
|
||||
@NotNull List<File> javaFiles,
|
||||
@NotNull List<File> ktFiles,
|
||||
@NotNull File outDir,
|
||||
@NotNull Disposable disposable
|
||||
@NotNull Disposable disposable,
|
||||
@Nullable File javaErrorFile
|
||||
) throws IOException {
|
||||
if (!ktFiles.isEmpty()) {
|
||||
compileKotlinToDirAndGetAnalysisResult(ktFiles, outDir, disposable, ALL);
|
||||
@@ -539,7 +540,7 @@ public class JetTestUtils {
|
||||
compileJavaFiles(javaFiles, Arrays.asList(
|
||||
"-classpath", outDir.getPath() + File.pathSeparator + ForTestCompileRuntime.runtimeJarForTests(),
|
||||
"-d", outDir.getPath()
|
||||
));
|
||||
), javaErrorFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,6 +743,10 @@ public class JetTestUtils {
|
||||
}
|
||||
|
||||
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options) throws IOException {
|
||||
compileJavaFiles(files, options, null);
|
||||
}
|
||||
|
||||
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options, @Nullable File javaErrorFile) throws IOException {
|
||||
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
|
||||
StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(diagnosticCollector, Locale.ENGLISH, Charset.forName("utf-8"));
|
||||
@@ -757,7 +762,13 @@ public class JetTestUtils {
|
||||
javaFileObjectsFromFiles);
|
||||
|
||||
Boolean success = task.call(); // do NOT inline this variable, call() should complete before errorsToString()
|
||||
Assert.assertTrue(errorsToString(diagnosticCollector), success);
|
||||
String diagnosticString = errorsToString(diagnosticCollector);
|
||||
if (javaErrorFile == null || !javaErrorFile.exists()) {
|
||||
Assert.assertTrue(diagnosticString, success);
|
||||
}
|
||||
else {
|
||||
assertEqualsToFile(javaErrorFile, diagnosticString);
|
||||
}
|
||||
} finally {
|
||||
fileManager.close();
|
||||
}
|
||||
@@ -767,7 +778,10 @@ public class JetTestUtils {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (javax.tools.Diagnostic<? extends JavaFileObject> diagnostic : diagnosticCollector.getDiagnostics()) {
|
||||
if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
|
||||
builder.append(diagnostic).append("\n");
|
||||
builder.append(diagnostic.getSource().getName()).append(":")
|
||||
.append(diagnostic.getLineNumber()).append(":")
|
||||
.append(diagnostic.getColumnNumber()).append(":")
|
||||
.append(diagnostic.getCode()).append("\n");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
|
||||
Reference in New Issue
Block a user