diff options
author | Alan Viverette <alanv@google.com> | 2019-06-24 13:27:27 -0400 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2019-06-26 11:37:55 -0400 |
commit | 7ed35cb8a1f66ed90780a9480595d06f0278338c (patch) | |
tree | cf1633ca2d8e7e7ae6d8bc729ca261d04881eeba | |
parent | 1a9ac2a2d07cc0e64c51bf9c1b38623ba300bae0 (diff) | |
download | support-7ed35cb8a1f66ed90780a9480595d06f0278338c.tar.gz |
Embed annotation-experimental project directly into test
Avoids issues with Android Studio refusing to detect Java source if it's
already been added to another project as a resource file.
Bug: 135765440
Test: ExperimentalDetectorTest
Change-Id: Ib112115fc3834ed7a6b8dc2f3400ba3b29c3e785
-rw-r--r-- | annotation/annotation-experimental-lint/build.gradle | 2 | ||||
-rw-r--r-- | annotation/annotation-experimental-lint/src/test/kotlin/androidx/annotation/lint/ExperimentalDetectorTest.kt | 47 |
2 files changed, 45 insertions, 4 deletions
diff --git a/annotation/annotation-experimental-lint/build.gradle b/annotation/annotation-experimental-lint/build.gradle index fb6718bc76e..6ef83b34b9f 100644 --- a/annotation/annotation-experimental-lint/build.gradle +++ b/annotation/annotation-experimental-lint/build.gradle @@ -28,8 +28,6 @@ plugins { sourceSets { test.resources.srcDirs( project(":annotation:annotation-experimental-lint-integration-tests") - .projectDir.toString() + "/src/main", - project(":annotation:annotation-experimental") .projectDir.toString() + "/src/main" ) } diff --git a/annotation/annotation-experimental-lint/src/test/kotlin/androidx/annotation/lint/ExperimentalDetectorTest.kt b/annotation/annotation-experimental-lint/src/test/kotlin/androidx/annotation/lint/ExperimentalDetectorTest.kt index c0367e7c207..ada019ec137 100644 --- a/annotation/annotation-experimental-lint/src/test/kotlin/androidx/annotation/lint/ExperimentalDetectorTest.kt +++ b/annotation/annotation-experimental-lint/src/test/kotlin/androidx/annotation/lint/ExperimentalDetectorTest.kt @@ -31,8 +31,8 @@ class ExperimentalDetectorTest { private fun checkJava(vararg testFiles: TestFile): TestLintResult { return lint() .files( - javaSample("androidx.annotation.Experimental"), - javaSample("androidx.annotation.UseExperimental"), + EXPERIMENTAL_JAVA, + USE_EXPERIMENTAL_JAVA, *testFiles ) .allowMissingSdk(true) @@ -140,6 +140,49 @@ src/sample/UseKtExperimentalFromJava.java:25: Error: This declaration is experim companion object { /* ktlint-disable max-line-length */ + // The contents of Experimental.java from the experimental annotation library. + val EXPERIMENTAL_JAVA: TestFile = java(""" + package androidx.annotation; + + import static java.lang.annotation.ElementType.ANNOTATION_TYPE; + import static java.lang.annotation.RetentionPolicy.CLASS; + + import java.lang.annotation.Retention; + import java.lang.annotation.Target; + + @Retention(CLASS) + @Target({ANNOTATION_TYPE}) + public @interface Experimental { + enum Level { + WARNING, + ERROR, + } + + Level level() default Level.ERROR; + } + """.trimIndent()) + + // The contents of UseExperimental.java from the experimental annotation library. + val USE_EXPERIMENTAL_JAVA: TestFile = java(""" + package androidx.annotation; + + import static java.lang.annotation.ElementType.CONSTRUCTOR; + import static java.lang.annotation.ElementType.FIELD; + import static java.lang.annotation.ElementType.METHOD; + import static java.lang.annotation.ElementType.PACKAGE; + import static java.lang.annotation.ElementType.TYPE; + import static java.lang.annotation.RetentionPolicy.CLASS; + + import java.lang.annotation.Retention; + import java.lang.annotation.Target; + + @Retention(CLASS) + @Target({TYPE, METHOD, CONSTRUCTOR, FIELD, PACKAGE}) + public @interface UseExperimental { + Class<?> markerClass(); + } + """.trimIndent()) + // The contents of Experimental.kt from the Kotlin standard library. val EXPERIMENTAL_KT: TestFile = kotlin(""" package kotlin |