List of usage examples for org.objectweb.asm Opcodes ACC_FINAL
int ACC_FINAL
To view the source code for org.objectweb.asm Opcodes ACC_FINAL.
Click Source Link
From source file:com.android.mkstubs.sourcer.FieldSourcerTest.java
License:Apache License
@Test public void testTemplateTypeField() throws Exception { FieldSourcer fs = new FieldSourcer(new Output(mWriter), Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, // access "mList", // name "Ljava/util/ArrayList;", // desc "Ljava/util/ArrayList<Ljava/lang/String;>;" // signature );/*w w w. j a v a 2s .co m*/ fs.visitEnd(); String s = mWriter.toString(); Assert.assertEquals("private final java.util.ArrayList<java.lang.String> mList;\n", s); }
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 a va 2 s .com*/ // 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 www . j a v a 2s . 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); }
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; }/* www . ja v a 2s. 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.lint.checks.CordovaVersionDetector.java
License:Apache License
@Override public void checkClass(@NonNull ClassContext context, @NonNull ClassNode classNode) { //noinspection VariableNotUsedInsideIf if (mCordovaVersion != null) { // Exit early if we have already found the cordova version in the JS file. // This will be the case for all versions > 3.x.x return;/* w w w . j a va 2s . c om*/ } // For cordova versions such as 2.7.1, the version is a static *non-final* field in // a class named Device. Since it is non-final, it is initialized in the <clinit> method. // Example: // // ldc #5 // String 2.7.1 // putstatic #6 // Field cordovaVersion:Ljava/lang/String; // ... if (classNode.name.equals(FQN_CORDOVA_DEVICE)) { //noinspection unchecked ASM api. List<MethodNode> methods = classNode.methods; for (MethodNode method : methods) { if (SdkConstants.CLASS_CONSTRUCTOR.equals(method.name)) { InsnList nodes = method.instructions; for (int i = 0, n = nodes.size(); i < n; i++) { AbstractInsnNode instruction = nodes.get(i); int type = instruction.getType(); if (type == AbstractInsnNode.FIELD_INSN) { checkInstructionInternal(context, classNode, instruction); break; } } } } } else if (classNode.name.equals(FQN_CORDOVA_WEBVIEW)) { // For versions > 3.x.x, the version string is stored as a static final String in // CordovaWebView. // Note that this is also stored in the cordova.js.* but from a lint api perspective, // it's much faster to look it up here than load and check in the JS file. // e.g. // public static final java.lang.String CORDOVA_VERSION; // descriptor: Ljava/lang/String; // flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL // ConstantValue: String 4.1.1 // //noinspection unchecked ASM api. List<FieldNode> fields = classNode.fields; for (FieldNode node : fields) { if (FIELD_NAME_CORDOVA_VERSION_WEBVIEW.equals(node.name) && (node.access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL // is final && (node.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC // is static && node.value instanceof String) { mCordovaVersion = createVersion((String) node.value); if (mCordovaVersion != null) { validateCordovaVersion(context, mCordovaVersion, context.getLocation(classNode)); } } } } }
From source file:com.asakusafw.dag.compiler.builtin.MasterJoinLikeOperatorGenerator.java
License:Apache License
private static void defineSelection(Context context, ClassWriter writer, UserOperator operator, FieldRef impl, Map<OperatorProperty, FieldRef> dependencies) { Method selector = Invariants.safe(() -> { return MasterJoinOperatorUtil.getSelection(context.getClassLoader(), operator); });//from w w w. j a v a2s.com if (selector == null) { return; } MethodVisitor method = writer.visitMethod(Opcodes.ACC_PROTECTED | Opcodes.ACC_FINAL, "selectMaster", Type.getMethodDescriptor(typeOf(Object.class), typeOf(List.class), typeOf(Object.class)), null, null); cast(method, 2, MasterJoinOperatorUtil.getTransactionInput(operator).getDataType()); List<ValueRef> arguments = new ArrayList<>(); impl.load(method); arguments.add(new LocalVarRef(Opcodes.ALOAD, 1)); arguments.add(new LocalVarRef(Opcodes.ALOAD, 2)); arguments .addAll(Lang.project(getExtraViews(operator), v -> Invariants.requireNonNull(dependencies.get(v)))); arguments .addAll(Lang.project(operator.getArguments(), v -> Invariants.requireNonNull(dependencies.get(v)))); for (int i = 0, n = selector.getParameterCount(); i < n; i++) { arguments.get(i).load(method); } method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(selector.getDeclaringClass()).getInternalName(), selector.getName(), Type.getMethodDescriptor(selector), false); method.visitInsn(Opcodes.ARETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.builtin.MasterJoinLikeOperatorGenerator.java
License:Apache License
private void defineProcess(Context context, ClassWriter writer, UserOperator operator, FieldRef impl, Map<OperatorProperty, FieldRef> dependencies, ClassDescription target) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PROTECTED | Opcodes.ACC_FINAL, "process", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(Object.class)), null, null); cast(method, 1, MasterJoinOperatorUtil.getMasterInput(operator).getDataType()); cast(method, 2, MasterJoinOperatorUtil.getTransactionInput(operator).getDataType()); defineProcess(method, context, operator, new LocalVarRef(Opcodes.ALOAD, 1), new LocalVarRef(Opcodes.ALOAD, 2), impl, dependencies, target); method.visitInsn(Opcodes.RETURN);//from w w w . j a va 2s. c o m method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.builtin.Util.java
License:Apache License
static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {//from w ww . java 2 s .c o m DataModelReference type = context.getDataModelLoader().load(dataType); List<PropertyReference> props = group.getGrouping().stream() .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList()); MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null, null); LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef object = cast(v, 2, dataType); for (PropertyReference p : props) { key.load(v); object.load(v); getOption(v, p); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append", Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true); v.visitInsn(Opcodes.POP); } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Defines a new field./*www .j av a2 s . co m*/ * @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.EdgeDataTableAdapterGenerator.java
License:Apache License
private static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {//from ww w. j ava2 s . c o m DataModelReference type = context.getDataModelLoader().load(dataType); List<PropertyReference> props = group.getGrouping().stream() .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList()); MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null, null); LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef object = cast(v, 2, dataType); for (PropertyReference p : props) { key.load(v); object.load(v); getOption(v, p); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append", Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true); v.visitInsn(Opcodes.POP); } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }