Basic annotation collector tests
This commit is contained in:
@@ -30,5 +30,6 @@
|
||||
<orderEntry type="module" module-name="android-jps-plugin" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-test-framework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-completion" scope="TEST" />
|
||||
<orderEntry type="module" module-name="annotation-collector" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -20,6 +20,7 @@ import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.AbstractDataFlowValueRenderingTest
|
||||
import org.jetbrains.kotlin.addImport.AbstractAddImportTest
|
||||
import org.jetbrains.kotlin.android.*
|
||||
import org.jetbrains.kotlin.annotation.AbstractAnnotationProcessorBoxTest
|
||||
import org.jetbrains.kotlin.asJava.AbstractKotlinLightClassTest
|
||||
import org.jetbrains.kotlin.cfg.AbstractControlFlowTest
|
||||
import org.jetbrains.kotlin.cfg.AbstractDataFlowTest
|
||||
@@ -785,6 +786,12 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("plugins/annotation-collector/test", "plugins/annotation-collector/testData") {
|
||||
testClass(javaClass<AbstractAnnotationProcessorBoxTest>()) {
|
||||
model("collectToFile", recursive = false, extension = null)
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("plugins/android-idea-plugin/tests", "plugins/android-idea-plugin/testData") {
|
||||
testClass(javaClass<AbstractParserResultEqualityTest>()) {
|
||||
model("android/parserResultEquality", recursive = false, extension = null)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
@@ -12,5 +13,8 @@
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
<orderEntry type="module" module-name="compiler-tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="cli" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="idea-full" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestCase
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestUtil
|
||||
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
|
||||
import org.jetbrains.kotlin.codegen.generated.AbstractBlackBoxCodegenTest
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.JetTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import java.io.File
|
||||
import java.io.StringWriter
|
||||
import java.io.Writer
|
||||
import org.junit.Assert.*
|
||||
|
||||
public abstract class AbstractAnnotationProcessorBoxTest : CodegenTestCase() {
|
||||
|
||||
public fun doTest(path: String) {
|
||||
val fileName = path + getTestName(true) + ".kt"
|
||||
val collectorExtension = createTestEnvironment()
|
||||
loadFileByFullPath(fileName)
|
||||
CodegenTestUtil.generateFiles(myEnvironment, myFiles)
|
||||
|
||||
val actualAnnotations = collectorExtension.stringWriter.toString()
|
||||
val expectedAnnotationsFile = File(path + "annotations.txt")
|
||||
|
||||
JetTestUtils.assertEqualsToFile(expectedAnnotationsFile, actualAnnotations)
|
||||
}
|
||||
|
||||
override fun codegenTestBasePath(): String {
|
||||
return "plugins/annotation-collector/testData/codegen/"
|
||||
}
|
||||
|
||||
fun createTestEnvironment(): AnnotationCollectorExtensionForTests {
|
||||
val configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK)
|
||||
val environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
val project = environment.project
|
||||
|
||||
val collectorExtension = AnnotationCollectorExtensionForTests()
|
||||
ClassBuilderInterceptorExtension.registerExtension(project, collectorExtension)
|
||||
|
||||
myEnvironment = environment
|
||||
|
||||
return collectorExtension
|
||||
}
|
||||
|
||||
private class AnnotationCollectorExtensionForTests : AnnotationCollectorExtensionBase() {
|
||||
val stringWriter = StringWriter()
|
||||
|
||||
override fun getWriter(diagnostic: DiagnosticSink) = stringWriter
|
||||
|
||||
override val annotationFilterList = listOf<String>()
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
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-collector/testData/codegen/collectToFile")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class AnnotationProcessorBoxTestGenerated extends AbstractAnnotationProcessorBoxTest {
|
||||
public void testAllFilesPresentInCollectToFile() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/annotation-collector/testData/codegen/collectToFile"), Pattern.compile("^([^\\.]+)$"), false);
|
||||
}
|
||||
|
||||
@TestMetadata("classAnnotations")
|
||||
public void testClassAnnotations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/annotation-collector/testData/codegen/collectToFile/classAnnotations/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultPackage")
|
||||
public void testDefaultPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/annotation-collector/testData/codegen/collectToFile/defaultPackage/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fieldAnnotations")
|
||||
public void testFieldAnnotations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/annotation-collector/testData/codegen/collectToFile/fieldAnnotations/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localClasses")
|
||||
public void testLocalClasses() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/annotation-collector/testData/codegen/collectToFile/localClasses/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("methodAnnotations")
|
||||
public void testMethodAnnotations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/annotation-collector/testData/codegen/collectToFile/methodAnnotations/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClasses")
|
||||
public void testNestedClasses() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/annotation-collector/testData/codegen/collectToFile/nestedClasses/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("plugins/annotation-collector/testData/codegen/collectToFile/simple/");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
a javax.inject.Named 0
|
||||
p org.test 0
|
||||
c 0 0/SomeClass
|
||||
c 0 0/SomeObject
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.test
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
Named("KotlinClass")
|
||||
public class SomeClass
|
||||
|
||||
Named("KotlinObject")
|
||||
public object SomeObject
|
||||
@@ -0,0 +1,8 @@
|
||||
a javax.inject.Named 0
|
||||
c 0 SomeClass
|
||||
a javax.inject.Inject 1
|
||||
f 1 SomeClass annotatedProperty
|
||||
a org.jetbrains.annotations.Nullable 2
|
||||
f 2 SomeClass annotatedProperty
|
||||
m 2 SomeClass getAnnotatedProperty
|
||||
m 1 SomeClass annotatedFunction
|
||||
@@ -0,0 +1,14 @@
|
||||
import javax.inject.*
|
||||
|
||||
Named("KotlinClass")
|
||||
public class SomeClass {
|
||||
|
||||
Inject
|
||||
public var annotatedProperty: String? = null
|
||||
|
||||
Inject
|
||||
public fun annotatedFunction() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
a javax.inject.Inject 0
|
||||
p org.test 0
|
||||
f 0 0/SomeClass annotatedVal
|
||||
a org.jetbrains.annotations.Nullable 1
|
||||
f 1 0/SomeClass annotatedVal
|
||||
m 1 0/SomeClass getAnnotatedVal
|
||||
f 0 0/SomeClass annotatedVar
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.test
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
public class SomeClass {
|
||||
|
||||
Inject
|
||||
public val annotatedVal: String? = null
|
||||
|
||||
Inject
|
||||
public var annotatedVar: Int = 5
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
a javax.inject.Named 0
|
||||
p org.test 0
|
||||
c 0 0/SomeClass$someFunction$LocalClass
|
||||
a javax.inject.Inject 1
|
||||
f 1 0/SomeClass$someFunction$LocalClass annotatedProperty
|
||||
a org.jetbrains.annotations.Nullable 2
|
||||
f 2 0/SomeClass$someFunction$LocalClass annotatedProperty
|
||||
m 2 0/SomeClass$someFunction$LocalClass getAnnotatedProperty
|
||||
m 1 0/SomeClass$someFunction$LocalClass annotatedFunction
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.test
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
public class SomeClass {
|
||||
|
||||
public fun someFunction() {
|
||||
[Named("LocalKotlinClass")]
|
||||
class LocalClass {
|
||||
|
||||
[Inject]
|
||||
public var annotatedProperty: String? = null
|
||||
|
||||
[Inject]
|
||||
public fun annotatedFunction() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
a javax.inject.Inject 0
|
||||
p org.test 0
|
||||
m 0 0/SomeClass annotatedFunction
|
||||
a javax.inject.Named 1
|
||||
m 1 0/SomeClass$annotatedFunction$1 invoke
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.test
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
public class SomeClass {
|
||||
|
||||
Inject
|
||||
public fun annotatedFunction() {
|
||||
|
||||
[Named("LocalFunction")]
|
||||
fun localFunction() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
a javax.inject.Named 0
|
||||
p org.test 0
|
||||
c 0 0/SomeClass$Companion
|
||||
a org.jetbrains.annotations.NotNull 1
|
||||
m 1 0/SomeClass$Companion access$init$0
|
||||
c 0 0/SomeClass$SomeInnerObject
|
||||
c 0 0/SomeClass$InnerClass
|
||||
c 0 0/SomeClass$NestedClass
|
||||
a java.lang.Deprecated 2
|
||||
f 2 0/SomeClass OBJECT$
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.test
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
public class SomeClass {
|
||||
|
||||
Named("CompanionObject")
|
||||
companion object {
|
||||
|
||||
}
|
||||
|
||||
Named("KotlinInnerObject")
|
||||
object SomeInnerObject {
|
||||
|
||||
}
|
||||
|
||||
Named("InnerClass")
|
||||
inner class InnerClass {
|
||||
|
||||
}
|
||||
|
||||
Named("NestedClass")
|
||||
class NestedClass {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
a javax.inject.Inject 0
|
||||
p org.test 0
|
||||
m 0 0/SomeClass annotatedFunction
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.test
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
public class SomeClass {
|
||||
|
||||
Inject
|
||||
public fun annotatedFunction() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user