• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.tools.layoutlib.create;
2 
3 import org.objectweb.asm.ClassVisitor;
4 import org.objectweb.asm.MethodVisitor;
5 
6 import java.util.Set;
7 
8 import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
9 import static org.objectweb.asm.Opcodes.ACC_PROTECTED;
10 import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
11 
12 public class PromoteMethodClassAdapter extends ClassVisitor {
13 
14     private final Set<String> mMethodNames;
15     private static final int CLEAR_PRIVATE_MASK = ~(ACC_PRIVATE | ACC_PROTECTED);
16 
PromoteMethodClassAdapter(ClassVisitor cv, Set<String> methodNames)17     public PromoteMethodClassAdapter(ClassVisitor cv, Set<String> methodNames) {
18         super(Main.ASM_VERSION, cv);
19         mMethodNames = methodNames;
20     }
21 
22     @Override
visitMethod(int access, String name, String desc, String signature, String[] exceptions)23     public MethodVisitor visitMethod(int access, String name, String desc, String signature,
24             String[] exceptions) {
25         if (mMethodNames.contains(name)) {
26             if ((access & ACC_PUBLIC) == 0) {
27                 access = (access & CLEAR_PRIVATE_MASK) | ACC_PUBLIC;
28             }
29         }
30         return super.visitMethod(access, name, desc, signature, exceptions);
31     }
32 }
33