Move test loading Java TYPE_USE annotation to Java8 module

#KT-11454 Fixed
This commit is contained in:
Denis Zharkov
2016-03-16 15:37:39 +03:00
parent 85329e59ca
commit 04eb5ff4f7
14 changed files with 267 additions and 38 deletions
@@ -0,0 +1,61 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jvm.compiler;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@RunWith(JUnit3RunnerWithInners.class)
public class LoadJava8TestGenerated extends AbstractLoadJava8Test {
@TestMetadata("compiler/testData/loadJava8/compiledJava")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class CompiledJava extends AbstractLoadJava8Test {
public void testAllFilesPresentInCompiledJava() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/compiledJava"), Pattern.compile("^(.+)\\.java$"), true);
}
@TestMetadata("TypeAnnotations.java")
public void testTypeAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/TypeAnnotations.java");
doTestCompiledJava(fileName);
}
}
@TestMetadata("compiler/testData/loadJava8/sourceJava")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SourceJava extends AbstractLoadJava8Test {
public void testAllFilesPresentInSourceJava() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/sourceJava"), Pattern.compile("^(.+)\\.java$"), true);
}
@TestMetadata("TypeAnnotations.java")
public void testTypeAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/sourceJava/TypeAnnotations.java");
doTestSourceJava(fileName);
}
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jvm.runtime;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/loadJava8/compiledJava")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class Jvm8RuntimeDescriptorLoaderTestGenerated extends AbstractJvm8RuntimeDescriptorLoaderTest {
public void testAllFilesPresentInCompiledJava() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/compiledJava"), Pattern.compile("^(.+)\\.java$"), true, "sam", "kotlinSignature/propagation");
}
@TestMetadata("TypeAnnotations.java")
public void testTypeAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/TypeAnnotations.java");
doTest(fileName);
}
}
@@ -1,16 +0,0 @@
package test;
import java.lang.annotation.*;
@Target(ElementType.TYPE_USE)
@interface A {
String value() default "";
}
interface G<T> {}
interface G2<A, B> {}
public interface TypeAnnotations<TT> {
void f(G<@A String> p);
void f(G2<@A String, @A Integer> p);
}
@@ -1,6 +0,0 @@
package test
public interface TypeAnnotations</*0*/ TT : kotlin.Any!> {
public abstract fun f(/*0*/ p: test.G2<@test.A() kotlin.String!, @test.A() kotlin.Int!>!): kotlin.Unit
public abstract fun f(/*0*/ p: test.G<@test.A() kotlin.String!>!): kotlin.Unit
}
@@ -0,0 +1,23 @@
package test;
import java.lang.annotation.*;
public class TypeAnnotations {
@Target(ElementType.TYPE_USE)
@interface A {
String value() default "";
}
interface G<T> {
}
interface G2<A, B> {
}
// Currently annotations on type parameters and arguments are not loaded from compiled code because of IDEA-153093
// Once it will be fixed check if KT-11454 is ready to be resolved
public interface MyClass<TT> {
void f(G<@A String> p);
void f(G2<@A String, @A("abc") Integer> p);
}
}
@@ -0,0 +1,21 @@
package test
public open class TypeAnnotations {
public constructor TypeAnnotations()
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public/*package*/ final annotation class A : kotlin.Annotation {
public/*package*/ constructor A(/*0*/ value: kotlin.String = ...)
public final val value: kotlin.String
}
public/*package*/ interface G</*0*/ T : kotlin.Any!> {
}
public/*package*/ interface G2</*0*/ A : kotlin.Any!, /*1*/ B : kotlin.Any!> {
}
public interface MyClass</*0*/ TT : kotlin.Any!> {
public abstract fun f(/*0*/ p0: test.TypeAnnotations.G2<kotlin.String!, kotlin.Int!>!): kotlin.Unit
public abstract fun f(/*0*/ p0: test.TypeAnnotations.G<kotlin.String!>!): kotlin.Unit
}
}
@@ -0,0 +1,21 @@
package test;
import java.lang.annotation.*;
public class TypeAnnotations {
@Target(ElementType.TYPE_USE)
@interface A {
String value() default "";
}
interface G<T> {
}
interface G2<A, B> {
}
public interface MyClass<TT> {
void f(G<@A String> p);
void f(G2<@A String, @A("abc") Integer> p);
}
}
@@ -0,0 +1,21 @@
package test
public open class TypeAnnotations {
public constructor TypeAnnotations()
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public/*package*/ final annotation class A : kotlin.Annotation {
public/*package*/ constructor A(/*0*/ value: kotlin.String = ...)
public final val value: kotlin.String
}
public/*package*/ interface G</*0*/ T : kotlin.Any!> {
}
public/*package*/ interface G2</*0*/ A : kotlin.Any!, /*1*/ B : kotlin.Any!> {
}
public interface MyClass</*0*/ TT : kotlin.Any!> {
public abstract fun f(/*0*/ p: test.TypeAnnotations.G2<@test.TypeAnnotations.A() kotlin.String!, @test.TypeAnnotations.A(value = "abc") kotlin.Int!>!): kotlin.Unit
public abstract fun f(/*0*/ p: test.TypeAnnotations.G<@test.TypeAnnotations.A() kotlin.String!>!): kotlin.Unit
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jvm.compiler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.test.TestJdkKind;
public abstract class AbstractLoadJava8Test extends AbstractLoadJavaTest {
@NotNull
@Override
protected TestJdkKind getJdkKind() {
return TestJdkKind.FULL_JDK;
}
}
@@ -117,7 +117,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
Assert.assertEquals("test", packageFromSource.getName().asString());
PackageViewDescriptor packageFromBinary = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot(
tmpdir, getTestRootDisposable(), TestJdkKind.MOCK_JDK, configurationKind, true
tmpdir, getTestRootDisposable(), getJdkKind(), configurationKind, true
).first;
for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(packageFromBinary.getMemberScope())) {
@@ -146,7 +146,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
});
CompilerConfiguration configuration = KotlinTestUtils.compilerConfigurationForTests(
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK);
ConfigurationKind.JDK_ONLY, getJdkKind());
ContentRootsKt.addKotlinSourceRoot(configuration, sourcesDir.getAbsolutePath());
JvmContentRootsKt.addJavaSourceRoot(configuration, new File("compiler/testData/loadJava/include"));
JvmContentRootsKt.addJavaSourceRoot(configuration, tmpdir);
@@ -187,7 +187,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(
getTestRootDisposable(),
compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, getAnnotationsJar(), libraryOut),
compilerConfigurationForTests(ConfigurationKind.JDK_ONLY, getJdkKind(), getAnnotationsJar(), libraryOut),
EnvironmentConfigFiles.JVM_CONFIG_FILES);
KtFile jetFile = KotlinTestUtils.createFile(kotlinSrc.getPath(), FileUtil.loadFile(kotlinSrc, true), environment.getProject());
@@ -203,6 +203,11 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
), expectedFile);
}
@NotNull
protected TestJdkKind getJdkKind() {
return TestJdkKind.MOCK_JDK;
}
protected void doTestSourceJava(@NotNull String javaFileName) throws Exception {
File originalJavaFile = new File(javaFileName);
File expectedFile = getTxtFile(javaFileName);
@@ -212,7 +217,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
FileUtil.copy(originalJavaFile, new File(testPackageDir, originalJavaFile.getName()));
Pair<PackageViewDescriptor, BindingContext> javaPackageAndContext = loadTestPackageAndBindingContextFromJavaRoot(
tmpdir, getTestRootDisposable(), TestJdkKind.MOCK_JDK, ConfigurationKind.JDK_ONLY, false
tmpdir, getTestRootDisposable(), getJdkKind(), ConfigurationKind.JDK_ONLY, false
);
checkJavaPackage(expectedFile, javaPackageAndContext.first, javaPackageAndContext.second,
@@ -256,7 +261,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
@NotNull ConfigurationKind configurationKind
) throws IOException {
compileJavaWithAnnotationsJar(javaFiles, outDir);
return loadTestPackageAndBindingContextFromJavaRoot(outDir, myTestRootDisposable, TestJdkKind.MOCK_JDK, configurationKind, true);
return loadTestPackageAndBindingContextFromJavaRoot(outDir, myTestRootDisposable, getJdkKind(), configurationKind, true);
}
private static void checkJavaPackage(
@@ -5111,12 +5111,6 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestSourceJava(fileName);
}
@TestMetadata("TypeAnnotations.java")
public void testTypeAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/sourceJava/TypeAnnotations.java");
doTestSourceJava(fileName);
}
@TestMetadata("WrongNumberOfGenericParameters.java")
public void testWrongNumberOfGenericParameters() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/sourceJava/WrongNumberOfGenericParameters.java");
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jvm.runtime
import org.jetbrains.kotlin.test.TestJdkKind
abstract class AbstractJvm8RuntimeDescriptorLoaderTest : AbstractJvmRuntimeDescriptorLoaderTest() {
override val defaultJdkKind: TestJdkKind = TestJdkKind.MOCK_JDK
}
@@ -72,6 +72,8 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
}
}
protected open val defaultJdkKind: TestJdkKind = TestJdkKind.MOCK_JDK
// NOTE: this test does a dirty hack of text substitution to make all annotations defined in source code retain at runtime.
// Specifically each @interface in Java sources is extended by @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
// Also type related annotations are removed from Java because they are invisible at runtime
@@ -83,7 +85,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
val jdkKind =
if (InTextDirectivesUtils.isDirectiveDefined(text, "FULL_JDK")) TestJdkKind.FULL_JDK
else TestJdkKind.MOCK_JDK
else defaultJdkKind
compileFile(file, text, jdkKind)
@@ -113,10 +113,8 @@ import org.jetbrains.kotlin.jps.build.*
import org.jetbrains.kotlin.jps.build.android.AbstractAndroidJpsTestCase
import org.jetbrains.kotlin.jps.incremental.AbstractProtoComparisonTest
import org.jetbrains.kotlin.js.test.semantics.*
import org.jetbrains.kotlin.jvm.compiler.AbstractCompileJavaAgainstKotlinTest
import org.jetbrains.kotlin.jvm.compiler.AbstractLoadJavaTest
import org.jetbrains.kotlin.jvm.compiler.AbstractLoadKotlinWithTypeTableTest
import org.jetbrains.kotlin.jvm.compiler.AbstractWriteSignatureTest
import org.jetbrains.kotlin.jvm.compiler.*
import org.jetbrains.kotlin.jvm.runtime.AbstractJvm8RuntimeDescriptorLoaderTest
import org.jetbrains.kotlin.jvm.runtime.AbstractJvmRuntimeDescriptorLoaderTest
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBoxTest
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBytecodeShapeTest
@@ -340,12 +338,23 @@ fun main(args: Array<String>) {
testClass<AbstractBlackBoxCodegenTest>("BlackBoxWithJava8CodegenTestGenerated") {
model("codegen/java8/box")
}
testClass<AbstractDiagnosticsWithFullJdkTest>("DiagnosticsWithJava8TestGenerated") {
model("diagnostics/testsWithJava8")
}
testClass<AbstractForeignJava8AnnotationsTest>() {
model("foreignAnnotationsJava8/tests")
}
testClass<AbstractLoadJava8Test> {
model("loadJava8/compiledJava", extension = "java", testMethod = "doTestCompiledJava")
model("loadJava8/sourceJava", extension = "java", testMethod = "doTestSourceJava")
}
testClass<AbstractJvm8RuntimeDescriptorLoaderTest>() {
model("loadJava8/compiledJava", extension = "java", excludeDirs = listOf("sam", "kotlinSignature/propagation"))
}
}