Skip to content

Commit

Permalink
JRE reflection stripping: do not strip metadata from runtime annotati…
Browse files Browse the repository at this point in the history
…ons.

	Change on 2018/09/17 by antoniocortes <antoniocortes@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=213266548
  • Loading branch information
antonio-cortes-perez authored and Tom Ball committed Oct 9, 2018
1 parent f26f53b commit fd9b2d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package java.lang;

import com.google.j2objc.annotations.ReflectionSupport;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;

Expand All @@ -41,7 +40,5 @@
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
// TODO(user): remove once reflection data is not stripped from runtime annotations.
@ReflectionSupport(value = ReflectionSupport.Level.FULL)
public @interface Deprecated {
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public boolean needsReflection(TypeElement type) {
if (ElementUtil.isLambda(type)) {
return false;
}
if (isJUnitTestClass(type)) {
if (isJUnitTestClass(type) || ElementUtil.isRuntimeAnnotation(type)) {
return true;
}
PackageElement packageElement = ElementUtil.getPackage(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,21 @@ public void testJUnit4TestKeepsReflection() {
TranslationUtil translationUtil = unit.getEnv().translationUtil();
assertTrue(translationUtil.needsReflection(unit.getTypes().get(0)));
}

public void testRuntimeAnnotationKeepsReflection() {
options.setStripReflection(true);
String source =
"package foo; "
+ "import static java.lang.annotation.ElementType.TYPE; "
+ "import static java.lang.annotation.RetentionPolicy.RUNTIME; "
+ "import java.lang.annotation.Retention; "
+ "import java.lang.annotation.Target; "
+ "import org.junit.runners.JUnit4; "
+ "@Retention(RUNTIME) "
+ "@Target(value={TYPE}) "
+ "public @interface AnAnnotation {} ";
CompilationUnit unit = translateType("foo.AnAnnotation", source);
TranslationUtil translationUtil = unit.getEnv().translationUtil();
assertTrue(translationUtil.needsReflection(unit.getTypes().get(0)));
}
}

0 comments on commit fd9b2d6

Please sign in to comment.