Skip to content

Commit

Permalink
Don't let dead code eliminator modify runtime annotation classes.
Browse files Browse the repository at this point in the history
	Change on 2016/01/07 by tball <tball@google.com>
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=111606986
  • Loading branch information
tomball committed Jan 11, 2016
1 parent fae2f0d commit 98134e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -71,7 +71,10 @@ public void endVisit(EnumDeclaration node) {

@Override
public void endVisit(AnnotationTypeDeclaration node) {
eliminateDeadCode(node.getTypeBinding(), node.getBodyDeclarations());
ITypeBinding binding = node.getTypeBinding();
if (!BindingUtil.isRuntimeAnnotation(binding)) {
eliminateDeadCode(binding, node.getBodyDeclarations());
}
}

@Override
Expand Down
Expand Up @@ -250,4 +250,20 @@ public void testDeadClass_DeadInnerClassConstructor() throws IOException {
assertNotInTranslation(translation, "self->z_ = x;");
assertNotInTranslation(translation, "- (jint)f");
}

// Verify that annotation bodies aren't stripped when specified in a dead code report.
public void testDeadAnnotation() throws IOException {
DeadCodeMap map = DeadCodeMap.builder()
.addDeadClass("Foo")
.build();
setDeadCodeMap(map);
String source = "import java.lang.annotation.Retention;\n"
+ "import java.lang.annotation.RetentionPolicy;\n"
+ "@Retention(RetentionPolicy.RUNTIME)\n"
+ "public @interface Foo {\n"
+ " String value() default \"\";\n"
+ "}\n";
String translation = translateSourceFile(source, "Foo", "Foo.h");
assertTranslation(translation, "@property (readonly) NSString *value;");
}
}

0 comments on commit 98134e1

Please sign in to comment.