Kapt: add some JeElement tests

(cherry picked from commit 948a4b6)
This commit is contained in:
Yan Zhulanow
2016-08-02 22:47:18 +03:00
committed by Yan Zhulanow
parent 0fc92c784b
commit 927280f7ce
51 changed files with 1154 additions and 14 deletions
+5
View File
@@ -30,5 +30,10 @@
<jarDirectory url="file://$MODULE_DIR$/../../../ideaSDK/plugins/gradle/lib" recursive="false" type="SOURCES" />
</library>
</orderEntry>
<orderEntry type="module" module-name="java-model-wrappers" scope="TEST" />
<orderEntry type="module" module-name="compiler-tests" scope="TEST" />
<orderEntry type="module" module-name="light-classes" scope="TEST" />
<orderEntry type="library" scope="TEST" name="junit-plugin" level="project" />
<orderEntry type="module" module-name="annotation-processing" scope="TEST" />
</component>
</module>
@@ -0,0 +1,152 @@
/*
* 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.annotation.processing.test.processor
import org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.codegen.AbstractBytecodeTextTest
import org.jetbrains.kotlin.codegen.CodegenTestUtil
import org.jetbrains.kotlin.java.model.JeName
import org.jetbrains.kotlin.java.model.elements.JeAnnotationMirror
import org.jetbrains.kotlin.java.model.elements.JeMethodExecutableElement
import org.jetbrains.kotlin.java.model.elements.JeTypeElement
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisCompletedHandlerExtension
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestJdkKind
import java.io.File
import java.nio.file.Files
import javax.annotation.processing.Completion
import javax.annotation.processing.ProcessingEnvironment
import javax.annotation.processing.Processor
import javax.annotation.processing.RoundEnvironment
import javax.lang.model.SourceVersion
import javax.lang.model.element.*
class AnnotationProcessingExtensionForTests(
val processors: List<Processor>
) : AbstractAnnotationProcessingExtension(createTempDir(), createTempDir(), listOf()) {
override fun loadAnnotationProcessors() = processors
private companion object {
fun createTempDir(): File = Files.createTempDirectory("ap-test").toFile().apply {
deleteOnExit()
}
}
}
abstract class AbstractProcessorTest : AbstractBytecodeTextTest() {
abstract val testDataDir: String
private fun createTestEnvironment(processors: List<Processor>): KotlinCoreEnvironment {
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK)
val environment = KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
val project = environment.project
val apExtension = AnnotationProcessingExtensionForTests(processors)
AnalysisCompletedHandlerExtension.registerExtension(project, apExtension)
return environment
}
fun doTest(path: String, processors: List<Processor>) {
myEnvironment = createTestEnvironment(processors)
loadFileByFullPath(path)
CodegenTestUtil.generateFiles(myEnvironment, myFiles)
}
protected fun Element.assertHasAnnotation(fqName: String, vararg parameterValues: Any?) {
val annotation = annotationMirrors.first { it is JeAnnotationMirror && it.psi.qualifiedName == fqName }
val actualValues = annotation.elementValues.values
assertEquals(parameterValues.size, actualValues.size)
for ((expected, actual) in parameterValues.zip(actualValues)) {
assertEquals(expected, actual.value)
}
}
protected fun test(
name: String,
vararg supportedAnnotations: String,
process: (Set<TypeElement>, RoundEnvironment, ProcessingEnvironment) -> Unit
) = testAP(true, name, process, *supportedAnnotations)
protected fun testShouldNotRun(
name: String,
vararg supportedAnnotations: String
) = testAP(false, name, { set, roundEnv, env -> fail("Should not run") }, *supportedAnnotations)
private fun testAP(
shouldRun: Boolean,
name: String,
process: (Set<TypeElement>, RoundEnvironment, ProcessingEnvironment) -> Unit,
vararg supportedAnnotations: String
) {
val ktFileName = File(testDataDir, name + ".kt")
var started = false
val processor = object : Processor {
lateinit var processingEnv: ProcessingEnvironment
override fun getSupportedOptions() = setOf<String>()
override fun process(annotations: Set<TypeElement>, roundEnv: RoundEnvironment): Boolean {
if (!roundEnv.processingOver()) {
started = true
process(annotations, roundEnv, processingEnv)
}
return true
}
override fun init(env: ProcessingEnvironment) {
processingEnv = env
}
override fun getCompletions(
element: Element?,
annotation: AnnotationMirror?,
member: ExecutableElement?,
userText: String?
): Iterable<Completion>? {
return emptyList()
}
override fun getSupportedSourceVersion() = SourceVersion.RELEASE_6
override fun getSupportedAnnotationTypes() = supportedAnnotations.toSet()
}
doTest(ktFileName.canonicalPath, listOf(processor))
if (started != shouldRun) {
fail("Annotation processor " + (if (shouldRun) "was not started" else "was started"))
}
}
protected fun TypeElement.findMethod(name: String, vararg parameterTypes: String): JeMethodExecutableElement {
return enclosedElements.first {
if (it !is JeMethodExecutableElement
|| it.simpleName.toString() != name
|| parameterTypes.size != it.parameters.size) return@first false
parameterTypes.zip(it.parameters).all { it.first == it.second.asType().toString() }
} as JeMethodExecutableElement
}
protected fun ProcessingEnvironment.findClass(fqName: String) = elementUtils.getTypeElement(fqName) as JeTypeElement
protected fun assertEquals(expected: String, actual: Name) = assertEquals(expected, actual.toString())
}
@@ -0,0 +1,131 @@
/*
* 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.annotation.processing.test.processor
import org.jetbrains.kotlin.annotation.processing.impl.KotlinElements
import org.jetbrains.kotlin.java.model.elements.JeTypeElement
import javax.lang.model.element.ExecutableElement
import javax.lang.model.element.TypeElement
class ElementsTests : AbstractProcessorTest() {
override val testDataDir = "plugins/annotation-processing/testData/elements"
fun testOverrides() = test("Overrides", "*") { set, roundEnv, env ->
val (parent, child, childChild) = Triple(env.findClass("Parent"), env.findClass("Child"), env.findClass("ChildOfChild"))
val parentA = parent.findMethod("a")
val childA = child.findMethod("a")
val childAString = child.findMethod("a", "java.lang.String")
val childB = child.findMethod("b")
val childChildA = childChild.findMethod("a")
val childChildACharSequence = childChild.findMethod("a", "java.lang.CharSequence")
val childChildB = childChild.findMethod("b")
fun ExecutableElement.assertOverrides(overridden: ExecutableElement, result: Boolean) {
assertEquals(result, env.elementUtils.overrides(this, overridden, enclosingElement as JeTypeElement))
}
parentA.assertOverrides(parentA, false)
childA.assertOverrides(parentA, true)
childAString.assertOverrides(childA, false)
childB.assertOverrides(parentA, false)
childChildA.assertOverrides(parentA, true)
childChildA.assertOverrides(childA, true)
childChildB.assertOverrides(childB, true)
childChildACharSequence.assertOverrides(childA, false)
}
fun testOverrides2() = test("Overrides2", "*") { set, roundEnv, env ->
val classes = listOf(env.findClass("Intf"), env.findClass("A"), env.findClass("B"))
val (intf, a, b) = classes.map { it.findMethod("a") }
fun ExecutableElement.assertOverrides(overridden: ExecutableElement, context: TypeElement, result: Boolean) {
assertEquals(result, env.elementUtils.overrides(this, overridden, context))
}
a.assertOverrides(intf, classes[1], false)
b.assertOverrides(a, classes[2], true)
b.assertOverrides(intf, classes[2], true)
a.assertOverrides(intf, classes[2], true)
}
fun testIsFunctionalInterface() = test("IsFunctionalInterface", "*") { set, roundEnv, env ->
with (env.elementUtils as KotlinElements) {
fun assertIsFunctionalInterface(fqName: String, isIntf: Boolean) {
assertEquals(isIntf, isFunctionalInterface(env.findClass(fqName)))
}
assertIsFunctionalInterface("A", false)
assertIsFunctionalInterface("A.AA", true)
assertIsFunctionalInterface("B", false)
assertIsFunctionalInterface("C", true)
assertIsFunctionalInterface("D", false)
assertIsFunctionalInterface("E", true)
assertIsFunctionalInterface("F", false)
}
}
fun testIsDeprecated() = test("IsDeprecated", "*") { set, roundEnv, env ->
with (env.elementUtils) {
assertEquals(true, isDeprecated(env.findClass("Depr")))
assertEquals(false, isDeprecated(env.findClass("NoDepr")))
assertEquals(true, isDeprecated(env.findClass("JavaDepr")))
}
}
fun testGetElementValuesWithDefaults() = test("GetElementValuesWithDefaults", "Anno") { set, roundEnv, env ->
val (a, b, c, d) = listOf(env.findClass("A"), env.findClass("B"), env.findClass("C"), env.findClass("D"))
fun getValues(e: JeTypeElement) = env.elementUtils
.getElementValuesWithDefaults(e.annotationMirrors.first { it.psi.qualifiedName == "Anno" })
.values.map { it.value }
assertEquals(listOf("Tom", 10), getValues(a))
assertEquals(listOf("Tom", 20), getValues(b))
assertEquals(listOf("Mary", 10), getValues(c))
assertEquals(listOf("Mary", 20), getValues(d))
}
fun testGetAllMembers() = test("GetAllMembers", "*") { set, roundEnv, env ->
val clazz = env.findClass("MyClass")
val members = clazz.enclosedElements
assertEquals(5, members.size) // constructor, field, getter/setter, arbitrary method
val allMembers = env.elementUtils.getAllMembers(clazz)
assertEquals(17, allMembers.size)
assertEquals("<init>, clone, equals, finalize, getClass, getMyProperty, hashCode, myFunction, myProperty, " +
"notify, notifyAll, registerNatives, setMyProperty, toString, wait, wait, wait",
allMembers.sortedBy { it.simpleName.toString() }.joinToString { it.simpleName })
}
fun testGetPackageOf() = test("GetPackageOf", "*") { set, roundEnv, env ->
val e = env.elementUtils
val myClass = env.findClass("test.MyClass")
val packageElement = e.getPackageOf(myClass)
assertEquals("test", packageElement.qualifiedName)
assertEquals(packageElement, e.getPackageOf(packageElement))
assertNull(e.getPackageElement("SomethingStrange"))
val testPackageElement = e.getPackageElement("test")
assertEquals(packageElement, testPackageElement)
assertFalse(packageElement.isUnnamed)
val classes = packageElement.enclosedElements.filterIsInstance<JeTypeElement>()
assertEquals(2, classes.size)
}
}
@@ -0,0 +1,75 @@
/*
* 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.annotation.processing.test.processor
import org.jetbrains.kotlin.java.model.elements.JeMethodExecutableElement
import org.jetbrains.kotlin.java.model.elements.JeTypeElement
import org.jetbrains.kotlin.java.model.elements.JeVariableElement
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
class ProcessorTests : AbstractProcessorTest() {
override val testDataDir = "plugins/annotation-processing/testData/processors"
fun testSimple() = test("Simple", "Anno") { set, roundEnv, env ->
assertEquals(1, set.size)
val annotated = roundEnv.getElementsAnnotatedWith(set.first())
assertEquals(3, annotated.size)
val clazz = annotated.firstIsInstance<JeTypeElement>()
val method = annotated.firstIsInstance<JeMethodExecutableElement>()
val field = annotated.firstIsInstance<JeVariableElement>()
listOf(clazz, method, field).forEach {
it.assertHasAnnotation("Anno", it.simpleName.toString() + "Anno")
}
}
fun testSeveralAnnotations() = test("SeveralAnnotations", "Name", "Age") { set, roundEnv, env ->
val annos = set.toList()
assertEquals(2, annos.size)
val annotated1 = roundEnv.getElementsAnnotatedWith(annos[0]).sortedBy { it.simpleName.toString() }
val annotated2 = roundEnv.getElementsAnnotatedWith(annos[1]).sortedBy { it.simpleName.toString() }
assertEquals(2, annotated1.size)
assertEquals(annotated1, annotated2)
val (kate, mary) = Pair(annotated1[0] as JeTypeElement, annotated1[1] as JeTypeElement)
assertEquals("Mary", mary.simpleName)
with (kate) {
assertEquals("Kate", simpleName)
assertHasAnnotation("Name", "Kate")
assertHasAnnotation("Age", 22)
}
}
fun testStar() = test("Star", "*") { set, roundEnv, env ->
assertEquals(true, set.any { it.qualifiedName.toString() == "Anno" })
}
fun testStar2() = test("Star", "Anno", "*") { set, roundEnv, env ->
assertEquals(true, set.any { it.qualifiedName.toString() == "Anno" })
}
fun testStar3() = test("Star3", "Anno", "*") { set, roundEnv, env ->
assertEquals(true, set.any { it.qualifiedName.toString() == "Anno2" })
}
fun testDoesNotRun() = testShouldNotRun("DoesNotRun", "Anno")
fun testDoesNotRun2() = testShouldNotRun("DoesNotRun2", "Anno")
}
@@ -0,0 +1,66 @@
/*
* 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.annotation.processing.test.wrappers;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
import junit.framework.TestCase;
import org.jetbrains.kotlin.asJava.AbstractCompilerLightClassTest;
import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class AbstractJavaAnnotationProcessingTest extends AbstractCompilerLightClassTest {
private final static Pattern SUBJECT_FQ_NAME_PATTERN = Pattern.compile("^//\\s*(.*)$", Pattern.MULTILINE);
@Override
protected void doTest(String testDirPath) throws Exception {
File testDir = new File(testDirPath);
File javaFile = new File(testDirPath, testDir.getName() + ".java");
String text = FileUtil.loadFile(javaFile, true);
Matcher matcher = SUBJECT_FQ_NAME_PATTERN.matcher(text);
TestCase.assertTrue("No FqName specified. First line of the form '// f.q.Name' expected", matcher.find());
String fqName = matcher.group(1);
getEnvironment().updateClasspath(Collections.singletonList(testDir));
super.doTest(new File(testDir.getParentFile(), "common.kt").getCanonicalPath());
KotlinTestUtils.resolveAllKotlinFiles(getEnvironment());
Project project = getEnvironment().getProject();
PsiClass javaClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.allScope(project));
TestCase.assertNotNull("Class $fqName was not found.", javaClass != null);
doTest(javaFile, javaClass);
}
@Override
protected void doMultiFileTest(File testDataFile, Map<String, ModuleAndDependencies> modules, List<Void> files) throws IOException {}
protected abstract void doTest(File testDataFile, PsiClass lightClass);
}
@@ -0,0 +1,56 @@
/*
* 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.annotation.processing.test.wrappers;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.kotlin.asJava.AbstractCompilerLightClassTest;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class AbstractKotlinAnnotationProcessingTest extends AbstractCompilerLightClassTest {
private final static Pattern SUBJECT_FQ_NAME_PATTERN = Pattern.compile("^//\\s*(.*)$", Pattern.MULTILINE);
@Override
protected void doMultiFileTest(File testDataFile, Map<String, ModuleAndDependencies> modules, List<Void> files) throws IOException {
String text = FileUtil.loadFile(testDataFile, true);
Matcher matcher = SUBJECT_FQ_NAME_PATTERN.matcher(text);
assertTrue("No FqName specified. First line of the form '// f.q.Name' expected", matcher.find());
String fqName = matcher.group(1);
PsiClass lightClass = findLightClass(fqName);
doTest(testDataFile, lightClass);
}
protected abstract void doTest(File testDataFile, PsiClass lightClass);
private PsiClass findLightClass(String fqName) {
try {
return createFinder(getEnvironment()).findClass(fqName, GlobalSearchScope.allScope(getEnvironment().getProject()));
}
catch (IOException e) {
throw ExceptionUtilsKt.rethrow(e);
}
}
}
@@ -0,0 +1,39 @@
/*
* 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.annotation.processing.test.wrappers
import com.intellij.psi.PsiClass
import org.jetbrains.kotlin.java.model.elements.DefaultJeElementRenderer
import org.jetbrains.kotlin.java.model.toJeElement
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
private val RENDERER = DefaultJeElementRenderer()
private fun runTest(testDataFile: File, lightClass: PsiClass) {
val modelFile = File(testDataFile.parent, testDataFile.nameWithoutExtension + ".txt")
val jeElement = lightClass.toJeElement() ?: error("JeElement is null")
KotlinTestUtils.assertEqualsToFile(modelFile, RENDERER.render(jeElement))
}
abstract class AbstractKotlinModelWrappersTest : AbstractKotlinAnnotationProcessingTest() {
override fun doTest(testDataFile: File, lightClass: PsiClass) = runTest(testDataFile, lightClass)
}
abstract class AbstractJavaModelWrappersTest : AbstractJavaAnnotationProcessingTest() {
override fun doTest(testDataFile: File, lightClass: PsiClass) = runTest(testDataFile, lightClass)
}
@@ -0,0 +1,62 @@
/*
* 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.annotation.processing.test.wrappers;
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("plugins/annotation-processing/testData/javaWrappers")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class JavaModelWrappersTestGenerated extends AbstractJavaModelWrappersTest {
public void testAllFilesPresentInJavaWrappers() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/annotation-processing/testData/javaWrappers"), Pattern.compile("^([^\\.]+)$"), true);
}
@TestMetadata("EnumClass")
public void testEnumClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/javaWrappers/EnumClass/");
doTest(fileName);
}
@TestMetadata("MetaAnnotation")
public void testMetaAnnotation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/javaWrappers/MetaAnnotation/");
doTest(fileName);
}
@TestMetadata("Simple")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/javaWrappers/Simple/");
doTest(fileName);
}
@TestMetadata("WithNested")
public void testWithNested() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/javaWrappers/WithNested/");
doTest(fileName);
}
}
@@ -0,0 +1,73 @@
/*
* 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.annotation.processing.test.wrappers;
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("plugins/annotation-processing/testData/kotlinWrappers")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class KotlinModelWrappersTestGenerated extends AbstractKotlinModelWrappersTest {
public void testAllFilesPresentInKotlinWrappers() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/annotation-processing/testData/kotlinWrappers"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("annotations.kt")
public void testAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/kotlinWrappers/annotations.kt");
doTest(fileName);
}
@TestMetadata("enum.kt")
public void testEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/kotlinWrappers/enum.kt");
doTest(fileName);
}
@TestMetadata("metaAnnotations.kt")
public void testMetaAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/kotlinWrappers/metaAnnotations.kt");
doTest(fileName);
}
@TestMetadata("nestedClasses.kt")
public void testNestedClasses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/kotlinWrappers/nestedClasses.kt");
doTest(fileName);
}
@TestMetadata("repeatableAnnotations.kt")
public void testRepeatableAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/kotlinWrappers/repeatableAnnotations.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/annotation-processing/testData/kotlinWrappers/simple.kt");
doTest(fileName);
}
}
@@ -41,7 +41,7 @@ abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
val layoutPaths = File(path).listFiles { it -> it.name.startsWith("layout") && it.isDirectory }!!.map { "$path${it.name}/" }
myEnvironment = createAndroidTestEnvironment(configuration, layoutPaths)
myEnvironment = createTestEnvironment(configuration, layoutPaths)
}
fun doCompileAgainstAndroidSdkTest(path: String) {
@@ -30,7 +30,7 @@ abstract class AbstractAndroidBytecodeShapeTest : AbstractBytecodeTextTest() {
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
val layoutPaths = getResPaths(path)
myEnvironment = createAndroidTestEnvironment(configuration, layoutPaths)
myEnvironment = createTestEnvironment(configuration, layoutPaths)
}
override fun doTest(path: String) {
@@ -32,7 +32,7 @@ import java.io.File
abstract class AbstractAndroidSyntheticPropertyDescriptorTest : KtUsefulTestCase() {
fun doTest(path: String) {
val config = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.ANDROID_API)
val env = createAndroidTestEnvironment(config, getResPaths(path))
val env = createTestEnvironment(config, getResPaths(path))
val project = env.project
val ext = PackageFragmentProviderExtension.getInstances(project).first { it is AndroidPackageFragmentProviderExtension }
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtens
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import java.io.File
fun KtUsefulTestCase.createAndroidTestEnvironment(configuration: CompilerConfiguration, resDirectories: List<String>): KotlinCoreEnvironment {
fun KtUsefulTestCase.createTestEnvironment(configuration: CompilerConfiguration, resDirectories: List<String>): KotlinCoreEnvironment {
configuration.put(AndroidConfigurationKeys.VARIANT, resDirectories)
configuration.put(AndroidConfigurationKeys.PACKAGE, "test")