List of usage examples for org.objectweb.asm Opcodes ACC_PROTECTED
int ACC_PROTECTED
To view the source code for org.objectweb.asm Opcodes ACC_PROTECTED.
Click Source Link
From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java
License:Apache License
@Override public void visitInnerClass(String name, String outerName, String innerName, int access) { int newAccess = access & (~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) | Opcodes.ACC_PUBLIC; super.visitInnerClass(name, outerName, innerName, newAccess); }
From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java
License:Apache License
/** * If a method/field is not private, make it public. This is to workaround the fact * <ul>Our restart.dex files are loaded with a different class loader than the main dex file * class loader on restart. so we need methods/fields to be public</ul> * <ul>Our reload.dex are loaded from a different class loader as well but methods/fields * are accessed through reflection, yet you need class visibility.</ul> * * remember that in Java, protected methods or fields can be acessed by classes in the same * package :/*www .j a v a2s . c o m*/ * {@see https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html} * * @param access the original class/method/field access. * @return the new access or the same one depending on the original access rights. */ private static int transformAccessForInstantRun(int access) { AccessRight accessRight = AccessRight.fromNodeAccess(access); if (accessRight != AccessRight.PRIVATE) { access &= ~Opcodes.ACC_PROTECTED; access &= ~Opcodes.ACC_PRIVATE; return access | Opcodes.ACC_PUBLIC; } return access; }
From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java
License:Apache License
private static boolean isParentClassVisible(@NonNull ClassNode parent, @NonNull ClassNode child) { return ((parent.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0 || Objects .equal(ByteCodeUtils.getPackageName(parent.name), ByteCodeUtils.getPackageName(child.name))); }
From source file:com.android.build.gradle.internal.incremental.IncrementalSupportVisitor.java
License:Apache License
@SuppressWarnings("SimplifiableIfStatement") private static boolean isCallableFromSubclass(@NonNull MethodNode method, @NonNull ClassNode superClass, @NonNull ClassNode subclass) {//from w ww .j ava 2 s. c o m if ((method.access & Opcodes.ACC_PRIVATE) != 0) { return false; } else if ((method.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0) { return true; } else { // "package private" access modifier. return Objects.equal(ByteCodeUtils.getPackageName(superClass.name), ByteCodeUtils.getPackageName(subclass.name)); } }
From source file:com.android.mkstubs.FilterClassAdapter.java
License:Apache License
/** * Visits a field.//w w w . j a v a2 s .c om * * {@inheritDoc} * * Examples: * name = mArg * desc = Ljava/Lang/String; * signature = null (not a template) or template type */ @Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { // only accept public/protected fields if ((access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0) { return null; } // filter on field name String filterName = String.format("%s#%s", mClassName, name); if (!mFilter.accept(filterName)) { mLog.debug("- Remove field " + filterName); return null; } // TODO we should produce an error if a filtered desc/signature is being used. return super.visitField(access, name, desc, signature, value); }
From source file:com.android.mkstubs.FilterClassAdapter.java
License:Apache License
/** * Visits a method.//from ww w . j a v a 2 s . c o m * * {@inheritDoc} * * Examples: * name = <init> * desc = ()V * signature = null (not a template) or template type */ @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { // only accept public/protected methods if ((access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0) { return null; } // filter on method name using the non-generic descriptor String filterName = String.format("%s#%s%s", mClassName, name, desc); if (!mFilter.accept(filterName)) { mLog.debug("- Remove method " + filterName); return null; } // filter on method name using the generic signature if (signature != null) { filterName = String.format("%s#%s%s", mClassName, name, signature); if (!mFilter.accept(filterName)) { mLog.debug("- Remove method " + filterName); return null; } } // TODO we should produce an error if a filtered desc/signature/exception is being used. return super.visitMethod(access, name, desc, signature, exceptions); }
From source file:com.android.mkstubs.FilterClassAdapter.java
License:Apache License
@Override public void visitInnerClass(String name, String outerName, String innerName, int access) { // only accept public/protected inner classes if ((access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0) { return;/*from w w w . java 2 s . com*/ } // filter on name if (!mFilter.accept(name)) { return; } super.visitInnerClass(name, outerName, innerName, access); }
From source file:com.android.tools.layoutlib.create.DelegateClassAdapter.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; boolean isNative = (access & Opcodes.ACC_NATIVE) != 0; boolean useDelegate = (isNative && mDelegateMethods.contains(ALL_NATIVES)) || mDelegateMethods.contains(name); if (!useDelegate) { // Not creating a delegate for this method, pass it as-is from the reader // to the writer. return super.visitMethod(access, name, desc, signature, exceptions); }/*w w w . ja v a 2s. com*/ if (useDelegate) { if (CONSTRUCTOR.equals(name) || CLASS_INIT.equals(name)) { // We don't currently support generating delegates for constructors. throw new UnsupportedOperationException( String.format("Delegate doesn't support overriding constructor %1$s:%2$s(%3$s)", //$NON-NLS-1$ mClassName, name, desc)); } } if (isNative) { // Remove native flag access = access & ~Opcodes.ACC_NATIVE; MethodVisitor mwDelegate = super.visitMethod(access, name, desc, signature, exceptions); DelegateMethodAdapter2 a = new DelegateMethodAdapter2(mLog, null /*mwOriginal*/, mwDelegate, mClassName, name, desc, isStatic); // A native has no code to visit, so we need to generate it directly. a.generateDelegateCode(); return mwDelegate; } // Given a non-native SomeClass.MethodName(), we want to generate 2 methods: // - A copy of the original method named SomeClass.MethodName_Original(). // The content is the original method as-is from the reader. // - A brand new implementation of SomeClass.MethodName() which calls to a // non-existing method named SomeClass_Delegate.MethodName(). // The implementation of this 'delegate' method is done in layoutlib_brigde. int accessDelegate = access; // change access to public for the original one 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); MethodVisitor mwDelegate = super.visitMethod(accessDelegate, name, desc, signature, exceptions); DelegateMethodAdapter2 a = new DelegateMethodAdapter2(mLog, mwOriginal, mwDelegate, mClassName, name, desc, isStatic); return a; }
From source file:com.android.tools.layoutlib.create.TransformClassAdapter.java
License:Apache License
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {//from w w w. j ava 2 s . c o m // This class might be being renamed. name = mClassName; // remove protected or private and set as public 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 // don't try to implement stub for interfaces mIsInterface = ((access & Opcodes.ACC_INTERFACE) != 0); super.visit(version, access, name, signature, superName, interfaces); }
From source file:com.android.tools.layoutlib.create.TransformClassAdapter.java
License:Apache License
@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;/*from w w w.jav a2 s .c o m*/ // remove final access = access & ~Opcodes.ACC_FINAL; // note: leave abstract classes as such // don't try to implement stub for interfaces super.visitInnerClass(name, outerName, innerName, access); }