List of usage examples for org.objectweb.asm Opcodes ACC_PRIVATE
int ACC_PRIVATE
To view the source code for org.objectweb.asm Opcodes ACC_PRIVATE.
Click Source Link
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); }/*from ww w. j a va2 s . c om*/ 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) {// w ww. j a v a 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.j av a 2s .co 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); }
From source file:com.android.tools.layoutlib.create.TransformClassAdapter.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (mDeleteReturns != null) { Type t = Type.getReturnType(desc); if (t.getSort() == Type.OBJECT) { String returnType = t.getInternalName(); if (returnType != null) { if (mDeleteReturns.contains(returnType)) { return null; }// w ww . java 2 s.co m } } } String methodSignature = mClassName.replace('/', '.') + "#" + name; // change access to public access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); access |= Opcodes.ACC_PUBLIC; // remove final access = access & ~Opcodes.ACC_FINAL; // stub this method if they are all to be stubbed or if it is a native method // and don't try to stub interfaces nor abstract non-native methods. if (!mIsInterface && ((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) != Opcodes.ACC_ABSTRACT) && (mStubAll || (access & Opcodes.ACC_NATIVE) != 0) || mStubMethods.contains(methodSignature)) { boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; boolean isNative = (access & Opcodes.ACC_NATIVE) != 0; // remove abstract, final and native access = access & ~(Opcodes.ACC_ABSTRACT | Opcodes.ACC_FINAL | Opcodes.ACC_NATIVE); String invokeSignature = methodSignature + desc; mLog.debug(" Stub: %s (%s)", invokeSignature, isNative ? "native" : ""); MethodVisitor mw = super.visitMethod(access, name, desc, signature, exceptions); return new StubMethodAdapter(mw, name, returnType(desc), invokeSignature, isStatic, isNative); } else { mLog.debug(" Keep: %s %s", name, desc); return super.visitMethod(access, name, desc, signature, exceptions); } }
From source file:com.android.tools.layoutlib.create.TransformClassAdapter.java
License:Apache License
@Override 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;/*from w w w .ja va2s .c o m*/ return super.visitField(access, name, desc, signature, value); }
From source file:com.asakusafw.dag.compiler.builtin.SummarizeOperatorGenerator.java
License:Apache License
private static void defineCheckNull(ClassWriter writer, UserOperator operator, DataModelReference inputType) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, METHOD_CHECK_NON_NULL, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(ValueOption.class), typeOf(Object.class), typeOf(String.class)), null, null);//ww w .j a va 2s. co m LocalVarRef optionVar = new LocalVarRef(Opcodes.ALOAD, 0); LocalVarRef objectVar = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef nameVar = new LocalVarRef(Opcodes.ALOAD, 2); // if (option.isNull()) { Label ifEnd = new Label(); optionVar.load(method); getNullity(method, VALUE_DESC); method.visitJumpInsn(Opcodes.IFEQ, ifEnd); // new NullPointerException ... method.visitTypeInsn(Opcodes.NEW, typeOf(NullPointerException.class).getInternalName()); method.visitInsn(Opcodes.DUP); // str = String.format("<type>.%s must not be null (in <operator>): %s", name, object) getConst(method, String.format("%s.%%s must not be null (in %s.%s): %%s", inputType.getDeclaration().getSimpleName(), operator.getMethod().getDeclaringClass().getSimpleName(), operator.getMethod().getName())); getArray(method, typeOf(Object.class), new LocalVarRef[] { nameVar, objectVar }); method.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(String.class).getInternalName(), "format", Type.getMethodDescriptor(typeOf(String.class), typeOf(String.class), typeOf(Object[].class)), false); // throw new NullPointerException(str) method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(NullPointerException.class).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(String.class)), false); method.visitInsn(Opcodes.ATHROW); method.visitLabel(ifEnd); // } method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Defines a new field./* w w w . j ava 2 s.c om*/ * @param writer the current class visitor * @param target the declaring type * @param name the field name * @param type the field type * @return the defined field ref */ public static FieldRef defineField(ClassVisitor writer, ClassDescription target, String name, Type type) { writer.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, name, type.getDescriptor(), null, null); return new FieldRef(target, name, type); }
From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java
License:Apache License
private static void addContextField(ClassWriter writer) { writer.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, FIELD_CONTEXT, typeOf(OperationAdapter.Context.class).getDescriptor(), null, null); }
From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java
License:Apache License
private static void addElementFields(ClassWriter writer, ClassDescription target, List<VertexElement> elements, Function<VertexElement, String> ids) { for (VertexElement element : elements) { writer.visitField(Opcodes.ACC_PRIVATE, ids.apply(element), typeOf(element.getRuntimeType()).getDescriptor(), null, null); }// w w w. ja v a 2 s . c o m }
From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java
License:Apache License
private static void addElementMethods(ClassWriter writer, ClassDescription target, List<VertexElement> elements, Function<VertexElement, String> ids) { for (VertexElement element : elements) { String id = ids.apply(element); MethodVisitor method = writer.visitMethod(Opcodes.ACC_PRIVATE, id, Type.getMethodDescriptor(Type.VOID_TYPE), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); switch (element.getElementKind()) { case VALUE: getValue(method, target, (ValueElement) element, ids); break; case OPERATOR: case AGGREGATE: getClass(method, target, (ClassNode) element, ids); break; case OUTPUT: getOutput(method, target, (OutputNode) element, ids); break; case DATA_TABLE: getDataTable(method, target, (DataTableNode) element, ids); break; case CONTEXT: getContext(method, target, ids); break; case EMPTY_DATA_TABLE: getEmptyDataTable(method, target, ids); break; default:/*w w w. j av a 2s . c o m*/ throw new AssertionError(element.getElementKind()); } method.visitFieldInsn(Opcodes.PUTFIELD, target.getInternalName(), id, typeOf(element.getRuntimeType()).getDescriptor()); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); } }