From b6b7487e233316149f2471a76be52d4910a26223 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Mon, 6 Oct 2014 16:20:49 -0700 Subject: [PATCH] Bug 17782530: Annotations using retention policy source remain in .class Change-Id: I763e99c243d85406162e3b898fe1e5af8c216173 --- .../android/tools/rmtypedefs/RmTypeDefs.java | 2 +- .../tools/rmtypedefs/RmTypeDefsTest.java | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/rmtypedefs/src/com/android/tools/rmtypedefs/RmTypeDefs.java b/tools/rmtypedefs/src/com/android/tools/rmtypedefs/RmTypeDefs.java index df7294195..ab6d1f7d1 100644 --- a/tools/rmtypedefs/src/com/android/tools/rmtypedefs/RmTypeDefs.java +++ b/tools/rmtypedefs/src/com/android/tools/rmtypedefs/RmTypeDefs.java @@ -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); diff --git a/tools/rmtypedefs/test/com/android/tools/rmtypedefs/RmTypeDefsTest.java b/tools/rmtypedefs/test/com/android/tools/rmtypedefs/RmTypeDefsTest.java index 37a24ea5f..423d22b54 100644 --- a/tools/rmtypedefs/test/com/android/tools/rmtypedefs/RmTypeDefsTest.java +++ b/tools/rmtypedefs/test/com/android/tools/rmtypedefs/RmTypeDefsTest.java @@ -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; } } -} \ No newline at end of file +}