List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:com.yahoo.yqlplus.engine.internal.bytecode.UnitGenerator.java
public void generate(ClassSink cws) { if (constructors.size() == 0) { createConstructor();//from w w w . j a v a2 s . c o m } ClassVisitor cw = cws.create(internalName); String[] interfaceList = null; if (interfaces.size() > 0) { interfaceList = new String[interfaces.size()]; for (int i = 0; i < interfaces.size(); ++i) { interfaceList[i] = interfaces.get(i).getInternalName(); } } cw.visit(V1_7, ACC_PUBLIC | ACC_FINAL | ACC_SUPER, internalName, null, superInternalName, interfaceList); annotations.generateAnnotations(cw); { FieldVisitor fv = cw.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "$TYPE$", Type.getDescriptor(TypeWidget.class), null, null); fv.visitEnd(); } for (Map.Entry<String, FieldDefinition> e : fields.entrySet()) { e.getValue().generate(cw); } for (ConstructorGenerator constructor : constructors) { constructor.generate(cw); } for (Map.Entry<String, MethodGenerator> e : methods.entries()) { e.getValue().generate(cw); } cw.visitEnd(); }
From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java
License:Open Source License
/** * Creates text representation of asm method access flag. * /*w w w . j a v a 2 s . c o m*/ * @param flag asm method access flag * @return formatted string representing the access flag */ public static String formatMethodAccessFlags(int flag) { List<String> accesses = new ArrayList<>(); if ((flag & Opcodes.ACC_PUBLIC) != 0) { accesses.add("public"); } if ((flag & Opcodes.ACC_PROTECTED) != 0) { accesses.add("protected"); } if ((flag & Opcodes.ACC_PRIVATE) != 0) { accesses.add("private"); } if ((flag & Opcodes.ACC_STATIC) != 0) { accesses.add("static"); } if ((flag & Opcodes.ACC_ABSTRACT) != 0) { accesses.add("abstract"); } if ((flag & Opcodes.ACC_FINAL) != 0) { accesses.add("final"); } return join(accesses.toArray(new String[accesses.size()]), " "); }
From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java
License:Open Source License
/** * Creates text representation of asm class access flag. * //from w w w. j a va 2 s . co m * @param flag asm class access flag * @return formatted string representing the access flag */ public static String formatClassAccessFlags(int flag) { List<String> accesses = new ArrayList<>(); if ((flag & Opcodes.ACC_PUBLIC) != 0) { accesses.add("public"); } if ((flag & Opcodes.ACC_PROTECTED) != 0) { accesses.add("protected"); } if ((flag & Opcodes.ACC_PRIVATE) != 0) { accesses.add("private"); } if ((flag & Opcodes.ACC_STATIC) != 0) { accesses.add("static"); } if ((flag & Opcodes.ACC_ABSTRACT) != 0) { accesses.add("abstract"); } if ((flag & Opcodes.ACC_FINAL) != 0) { accesses.add("final"); } if ((flag & Opcodes.ACC_ENUM) != 0) { accesses.add("enum"); } else if ((flag & Opcodes.ACC_INTERFACE) != 0) { accesses.add("interface"); } else { accesses.add("class"); } return join(accesses.toArray(new String[accesses.size()]), " "); }
From source file:de.javanarior.vo.generator.ByteCodeGenerator.java
License:Apache License
/** * Generate a implementation of a value object. * * @param valueType/*from w ww.j a va 2s. c om*/ * - value object type * @param technicalType * - to which the value object is mapped * @param wrapperClass * - abstract wrapper class, correspond to the technical type * @return class name and byte code in a container */ /* CHECKSTYLE:OFF */ public static ByteCodeContainer generate(Class<?> valueType, Class<? extends Comparable<?>> technicalType, @SuppressWarnings("rawtypes") Class<? extends AbstractValue> wrapperClass) { /* CHECKSTYLE:ON */ if (!isInterface(valueType)) { throw new IllegalArgumentException("Could not generate implementation for class " + valueType.getName() + ". Please provide interface"); } ClassWriter classWriter = new ClassWriter(0); MethodVisitor methodVisitor; classWriter.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, implementationClassName(valueType), "L" + parentClassName(wrapperClass) + "<" + addTypeDiscriptor(valueType) + ">;" + addTypeDiscriptor(valueType), parentClassName(wrapperClass), implementedInterfaces(valueType)); methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR, methodDescriptor(technicalType), null, null); methodVisitor.visitCode(); Label label0 = new Label(); methodVisitor.visitLabel(label0); /* CHECKSTYLE:OFF */ methodVisitor.visitLineNumber(8, label0); /* CHECKSTYLE:ON */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(getILOADOpCode(technicalType), 1); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, parentClassName(wrapperClass), CONSTRUCTOR, methodDescriptor(technicalType), false); Label label1 = new Label(); methodVisitor.visitLabel(label1); /* CHECKSTYLE:OFF */ methodVisitor.visitLineNumber(9, label1); /* CHECKSTYLE:ON */ methodVisitor.visitInsn(Opcodes.RETURN); Label label2 = new Label(); methodVisitor.visitLabel(label2); methodVisitor.visitLocalVariable("this", addTypeSignature(implementationClassName(valueType)), null, label0, label2, 0); methodVisitor.visitLocalVariable("value", getType(technicalType), null, label0, label2, 1); int stackSize = getStackSize(Type.getDescriptor(technicalType)); methodVisitor.visitMaxs(stackSize, stackSize); methodVisitor.visitEnd(); classWriter.visitEnd(); return new ByteCodeContainer(binaryClassName(valueType), classWriter.toByteArray()); }
From source file:de.sanandrew.core.manpack.transformer.AnnotationChecker.java
License:Creative Commons License
private static int getAccessLevelInt(int access) { if (checkBitwiseEqual(access, Opcodes.ACC_PRIVATE)) { return 0; } else if (checkBitwiseEqual(access, Opcodes.ACC_PROTECTED)) { return 2; } else if (checkBitwiseEqual(access, Opcodes.ACC_PUBLIC)) { return 3; } else { // if ACC_PACKAGE_LOCAL return 1; }/* w w w . j a v a2 s . co m*/ }
From source file:de.sanandrew.core.manpack.transformer.AnnotationChecker.java
License:Creative Commons License
private static String getAccessLevelName(int access) { if (checkBitwiseEqual(access, Opcodes.ACC_PRIVATE)) { return "private"; } else if (checkBitwiseEqual(access, Opcodes.ACC_PROTECTED)) { return "protected"; } else if (checkBitwiseEqual(access, Opcodes.ACC_PUBLIC)) { return "public"; } else { // if ACC_PACKAGE_LOCAL return "packageLocal"; }//from ww w .j av a 2 s. c o m }
From source file:de.sanandrew.core.manpack.transformer.AnnotationChecker.java
License:Creative Commons License
private static int getAccessLevelOpcode(String accessName) { String[] accessSplit = accessName.split(";"); int ret = 0;/*www .j a v a 2s . co m*/ for (String acc : accessSplit) { switch (acc) { case "private": ret |= Opcodes.ACC_PRIVATE; break; case "protected": ret |= Opcodes.ACC_PROTECTED; break; case "public": ret |= Opcodes.ACC_PUBLIC; break; case "deprecated": ret |= Opcodes.ACC_DEPRECATED; break; } } return ret; }
From source file:de.sanandrew.core.manpack.transformer.TransformBadPotionsATN.java
License:Creative Commons License
private byte[] transformPotion(byte[] bytes) { ClassNode cn = ASMHelper.createClassNode(bytes); if (ASMHelper.hasClassMethodName(cn, ASMNames.M_isBadEffect)) { return bytes; }/*from w w w . j a v a 2 s.com*/ MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, ASMNames.M_isBadEffect, "()Z", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/potion/Potion", ASMNames.F_isBadEffect, "Z"); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/potion/Potion;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); cn.methods.add(method); bytes = ASMHelper.createBytes(cn, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformELBAttackingPlayer.java
License:Creative Commons License
private static byte[] transformAttackingPlayer(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); /** ADD GETTER FOR ATTACKING PLAYER **/ {//from w ww . ja v a 2 s. co m MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getAttackingPlayer", "()Lnet/minecraft/entity/player/EntityPlayer;", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR ATTACKING PLAYER **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setAttackingPlayer", "(Lnet/minecraft/entity/player/EntityPlayer;)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("player", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD GETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getRecentlyHit", "()I", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setRecentlyHit", "(I)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ILOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("hit", "I", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } bytes = ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformEntityCollision.java
License:Creative Commons License
private static byte[] transformEntity(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PUBLIC, ASMNames.MD_SAP_ENTITY_GET_BOUNDING_BOX); method.visitCode();// w w w . j ava 2 s . c o m Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 2); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY, null, l0, l1, 0); method.visitLocalVariable("entity", ASMNames.CL_T_ENTITY, null, l0, l1, 1); method.visitLocalVariable("oldAABB", ASMNames.CL_T_AXIS_ALIGNED_BB, null, l0, l1, 2); method.visitMaxs(1, 2); method.visitEnd(); clazz.methods.add(method); bytes = ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); return bytes; }