diff options
author | kmb <kmb@google.com> | 2018-03-01 16:26:21 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-01 16:27:53 -0800 |
commit | f090082d62c3ea779d2dd33eb0fd7355b0ee9456 (patch) | |
tree | d4c2fd6f2b3ac8708e5a8a66105cdd64e9f3f603 /src/tools/android/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java | |
parent | 99be8b417a95224f66b3e00c9103cbde460d3b07 (diff) |
Android desugar config options to exclude methods from interface emulation
RELNOTES: None.
PiperOrigin-RevId: 187551970
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java b/src/tools/android/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java index c73874e977..e22c596c8e 100644 --- a/src/tools/android/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java +++ b/src/tools/android/java/com/google/devtools/build/android/desugar/CoreLibrarySupport.java @@ -44,6 +44,7 @@ class CoreLibrarySupport { private final ClassLoader targetLoader; /** Internal name prefixes that we want to move to a custom package. */ private final ImmutableSet<String> renamedPrefixes; + private final ImmutableSet<String> excludeFromEmulation; /** Internal names of interfaces whose default and static interface methods we'll emulate. */ private final ImmutableSet<Class<?>> emulatedInterfaces; /** Map from {@code owner#name} core library members to their new owners. */ @@ -58,13 +59,16 @@ class CoreLibrarySupport { GeneratedClassStore store, List<String> renamedPrefixes, List<String> emulatedInterfaces, - List<String> memberMoves) { + List<String> memberMoves, + List<String> excludeFromEmulation) { this.rewriter = rewriter; this.targetLoader = targetLoader; this.store = store; checkArgument( renamedPrefixes.stream().allMatch(prefix -> prefix.startsWith("java/")), renamedPrefixes); this.renamedPrefixes = ImmutableSet.copyOf(renamedPrefixes); + this.excludeFromEmulation = ImmutableSet.copyOf(excludeFromEmulation); + ImmutableSet.Builder<Class<?>> classBuilder = ImmutableSet.builder(); for (String itf : emulatedInterfaces) { checkArgument(itf.startsWith("java/util/"), itf); @@ -86,6 +90,8 @@ class CoreLibrarySupport { checkArgument(!isRenamedCoreLibrary(pair.get(0).substring(0, sep)), "Original renamed, no need to move it: %s", move); checkArgument(isRenamedCoreLibrary(pair.get(1)), "Target not renamed: %s", move); + checkArgument(!this.excludeFromEmulation.contains(pair.get(0)), + "Retargeted invocation %s shouldn't overlap with excluded", move); movesBuilder.put(pair.get(0), renameCoreLibrary(pair.get(1))); } @@ -245,6 +251,9 @@ class CoreLibrarySupport { // we can only get here if its a default method, and invokestatic we handled above. Method callee = findInterfaceMethod(clazz, name, desc); if (callee != null && callee.isDefault()) { + if (isExcluded(callee)) { + return null; + } Class<?> result = callee.getDeclaringClass(); if (isRenamedCoreLibrary(result.getName().replace('.', '/')) || emulatedInterfaces.stream().anyMatch(emulated -> emulated.isAssignableFrom(result))) { @@ -294,6 +303,12 @@ class CoreLibrarySupport { return null; } + private boolean isExcluded(Method method) { + String unprefixedOwner = + rewriter.unprefix(method.getDeclaringClass().getName().replace('.', '/')); + return excludeFromEmulation.contains(unprefixedOwner + "#" + method.getName()); + } + private Class<?> loadFromInternal(String internalName) { try { return targetLoader.loadClass(internalName.replace('/', '.')); |