Merge "Bug 17782530: Annotations using retention policy source remain in .class" into lmp-dev

This commit is contained in:
Tor Norbye
2014-10-07 01:07:24 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 2 deletions

View File

@@ -183,7 +183,7 @@ public class RmTypeDefs {
assert parentFile != null : file;
File container = new File(parentFile, fileName.substring(0, index) + ".class");
if (container.exists()) {
mAnnotationOuterClassFiles.add(file);
mAnnotationOuterClassFiles.add(container);
} else {
System.err.println("Warning: Could not find outer class " + container
+ " for typedef " + file);

View File

@@ -16,6 +16,9 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static com.google.common.base.Charsets.UTF_8;
import static java.io.File.separatorChar;
@SuppressWarnings("SpellCheckingInspection")
public class RmTypeDefsTest extends TestCase {
public void test() throws IOException {
@@ -169,10 +172,37 @@ public class RmTypeDefsTest extends TestCase {
+ " testDir/test/pkg/TestClass.java\n",
getDirectoryContents(dir));
// Make sure the Visibility symbol is completely gone from the outer class
assertDoesNotContainBytes(new File(dir,
"test/pkg/TestClass$StaticInnerClass.class".replace('/', separatorChar)),
"Visibility");
deleteDir(dir);
}
private void assertDoesNotContainBytes(File file, String sub) throws IOException {
byte[] contents = Files.toByteArray(file);
// Like the strings command, look for 4 or more consecutive printable characters
for (int i = 0, n = contents.length; i < n; i++) {
if (Character.isJavaIdentifierStart(contents[i])) {
for (int j = i + 1; j < n; j++) {
if (!Character.isJavaIdentifierPart(contents[j])) {
if (j > i + 4) {
int length = j - i - 1;
if (length == sub.length()) {
String symbol = new String(contents, i, length, UTF_8);
assertFalse("Found " + sub + " in class file " + file,
sub.equals(symbol));
}
}
i = j;
break;
}
}
}
}
}
String getDirectoryContents(File root) {
StringBuilder sb = new StringBuilder();
list(sb, root, "", 0, "testDir");
@@ -251,4 +281,4 @@ public class RmTypeDefsTest extends TestCase {
return mStatus;
}
}
}
}