diff options
3 files changed, 30 insertions, 13 deletions
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java index 49ddf1d..0e24cc0 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java @@ -117,8 +117,10 @@ public class DelegateClassAdapter extends ClassAdapter { int accessDelegate = access; // change access to public for the original one - access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); - access |= Opcodes.ACC_PUBLIC; + if (Main.sOptions.generatePublicAccess) { + access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); + access |= Opcodes.ACC_PUBLIC; + } MethodVisitor mwOriginal = super.visitMethod(access, name + ORIGINAL_SUFFIX, desc, signature, exceptions); diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java index 0fce7ef..c539578 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java @@ -37,7 +37,7 @@ import java.util.Set; * which does: * <pre> * $ make layoutlib_create <bunch of framework jars> - * $ out/host/linux-x86/framework/bin/layoutlib_create \ + * $ java -jar out/host/linux-x86/framework/layoutlib_create.jar \ * out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar \ * out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar \ * out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar @@ -45,6 +45,12 @@ import java.util.Set; */ public class Main { + public static class Options { + public boolean generatePublicAccess = true; + } + + public static final Options sOptions = new Options(); + public static void main(String[] args) { Log log = new Log(); @@ -53,7 +59,7 @@ public class Main { String[] osDestJar = { null }; if (!processArgs(log, args, osJarPath, osDestJar)) { - log.error("Usage: layoutlib_create [-v] output.jar input.jar ..."); + log.error("Usage: layoutlib_create [-v] [-p] output.jar input.jar ..."); System.exit(1); } @@ -135,6 +141,8 @@ public class Main { String s = args[i]; if (s.equals("-v")) { log.setVerbose(true); + } else if (s.equals("-p")) { + sOptions.generatePublicAccess = false; } else if (!s.startsWith("-")) { if (osDestJar[0] == null) { osDestJar[0] = s; diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java index f2d9755..5a0a44a 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java @@ -72,8 +72,10 @@ class TransformClassAdapter extends ClassAdapter { name = mClassName; // remove protected or private and set as public - access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED); - access |= Opcodes.ACC_PUBLIC; + if (Main.sOptions.generatePublicAccess) { + access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED); + access |= Opcodes.ACC_PUBLIC; + } // remove final access = access & ~Opcodes.ACC_FINAL; // note: leave abstract classes as such @@ -87,8 +89,10 @@ class TransformClassAdapter extends ClassAdapter { @Override public void visitInnerClass(String name, String outerName, String innerName, int access) { // remove protected or private and set as public - access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED); - access |= Opcodes.ACC_PUBLIC; + if (Main.sOptions.generatePublicAccess) { + access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED); + access |= Opcodes.ACC_PUBLIC; + } // remove final access = access & ~Opcodes.ACC_FINAL; // note: leave abstract classes as such @@ -117,8 +121,10 @@ class TransformClassAdapter extends ClassAdapter { String methodSignature = mClassName.replace('/', '.') + "#" + name; // change access to public - access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); - access |= Opcodes.ACC_PUBLIC; + if (Main.sOptions.generatePublicAccess) { + access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); + access |= Opcodes.ACC_PUBLIC; + } // remove final access = access & ~Opcodes.ACC_FINAL; @@ -155,9 +161,10 @@ class TransformClassAdapter extends ClassAdapter { public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { // change access to public - access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); - access |= Opcodes.ACC_PUBLIC; - + if (Main.sOptions.generatePublicAccess) { + access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); + access |= Opcodes.ACC_PUBLIC; + } return super.visitField(access, name, desc, signature, value); } |