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:erjang.EFun.java
License:Apache License
static byte[] gen_fun_class_data(int arity) { String self_type = EFUN_TYPE.getInternalName() + arity; ClassWriter cw = new ClassWriter(true); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, self_type, null, EFUN_TYPE.getInternalName(), null); make_invoke_method(cw, self_type, arity); CompilerVisitor.make_invoketail_method(cw, self_type, arity, 0); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "arity", "()I", null, null); mv.visitCode();/*from ww w .j a va 2 s . c o m*/ mv.visitLdcInsn(new Integer(arity)); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(2, 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "invoke", "(" + EPROC_TYPE.getDescriptor() + EOBJECT_ARR_TYPE.getDescriptor() + ")" + EOBJECT_TYPE.getDescriptor(), null, PAUSABLE_EX); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); // load this mv.visitVarInsn(Opcodes.ALOAD, 1); // load proc for (int i = 0; i < arity; i++) { mv.visitVarInsn(Opcodes.ALOAD, 2); push_int(mv, i); mv.visitInsn(Opcodes.AALOAD); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, self_type, "invoke", EUtil.getSignature(arity, true)); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(arity + 2, arity + 2); mv.visitEnd(); mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "()V", null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, EFUN_TYPE.getInternalName(), "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); make_cast_method(cw, arity); cw.visitEnd(); byte[] data = cw.toByteArray(); return data; }
From source file:erjang.EFun.java
License:Apache License
static byte[] get_exported_fun_class_data(int arity) { /* Code template://from w w w.ja v a 2 s . c o m * public abstract class EFun{arity}Exported extends EFun{arity} { * protected final EAtom module_name, function_name; * protected EFun{arity}Exported(String m, String f) { * module_name = EAtom.intern(m); * function_name = EAtom.intern(f); * } * } */ ensure(arity); // Ensure presence of superclass. String super_type = EFUN_TYPE.getInternalName() + arity; String self_type = super_type + "Exported"; ClassWriter cw = new ClassWriter(true); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, self_type, null, super_type, null); cw.visitField(ACC_PROTECTED | ACC_FINAL, "module_name", EATOM_TYPE.getDescriptor(), null, null).visitEnd(); cw.visitField(ACC_PROTECTED | ACC_FINAL, "function_name", EATOM_TYPE.getDescriptor(), null, null) .visitEnd(); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V", null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, super_type, "<init>", "()V"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern", "(Ljava/lang/String;)Lerjang/EAtom;"); mv.visitFieldInsn(Opcodes.PUTFIELD, self_type, "module_name", EATOM_DESC); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, EATOM_TYPE.getInternalName(), "intern", "(Ljava/lang/String;)Lerjang/EAtom;"); mv.visitFieldInsn(Opcodes.PUTFIELD, self_type, "function_name", EATOM_DESC); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(3, 3); mv.visitEnd(); make_encode_method_for_exported(cw, self_type, arity); cw.visitEnd(); byte[] data = cw.toByteArray(); return data; }
From source file:graph.Modifier.java
License:Apache License
/** * Returns an integer bit field for the EnumSet, where the bit values are * defined as in the class file format./* w w w.j a va 2 s.c om*/ * * @param set Set of modifiers to convert to a bit field. * @return Integer bit field. */ public static int getBitField(EnumSet<Modifier> set) { int access = 0; if (set.contains(PUBLIC)) { access |= Opcodes.ACC_PUBLIC; } if (set.contains(PROTECTED)) { access |= Opcodes.ACC_PROTECTED; } if (set.contains(PRIVATE)) { access |= Opcodes.ACC_PRIVATE; } if (set.contains(STATIC)) { access |= Opcodes.ACC_STATIC; } if (set.contains(FINAL)) { access |= Opcodes.ACC_FINAL; } if (set.contains(SUPER)) { access |= Opcodes.ACC_SUPER; } if (set.contains(INTERFACE)) { access |= Opcodes.ACC_INTERFACE; } if (set.contains(ABSTRACT)) { access |= Opcodes.ACC_ABSTRACT; } if (set.contains(SYNTHETIC)) { access |= Opcodes.ACC_SYNTHETIC; } if (set.contains(ANNOTATION)) { access |= Opcodes.ACC_ANNOTATION; } if (set.contains(ENUM)) { access |= Opcodes.ACC_ENUM; } if (set.contains(VOLATILE)) { access |= Opcodes.ACC_VOLATILE; } if (set.contains(TRANSIENT)) { access |= Opcodes.ACC_TRANSIENT; } if (set.contains(SYNCHRONIZED)) { access |= Opcodes.ACC_SYNCHRONIZED; } if (set.contains(BRIDGE)) { access |= Opcodes.ACC_BRIDGE; } if (set.contains(VARARGS)) { access |= Opcodes.ACC_VARARGS; } if (set.contains(NATIVE)) { access |= Opcodes.ACC_NATIVE; } return access; }
From source file:graph.Modifier.java
License:Apache License
/** * Returns an EnumSet of the modifiers, based on the given bit field (where * the bit values are defined as in the class file format). * * @param access Integer bit field giving access modifiers. * @return Set of modifiers.//from w ww. jav a 2 s. c o m */ public static EnumSet<Modifier> getSet(int access) { EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class); if ((access & Opcodes.ACC_PUBLIC) != 0) { modifiers.add(Modifier.PUBLIC); } if ((access & Opcodes.ACC_PROTECTED) != 0) { modifiers.add(Modifier.PROTECTED); } if ((access & Opcodes.ACC_PRIVATE) != 0) { modifiers.add(Modifier.PRIVATE); } if ((access & Opcodes.ACC_STATIC) != 0) { modifiers.add(Modifier.STATIC); } if ((access & Opcodes.ACC_FINAL) != 0) { modifiers.add(Modifier.FINAL); } if ((access & Opcodes.ACC_SUPER) != 0) { modifiers.add(Modifier.SUPER); } if ((access & Opcodes.ACC_INTERFACE) != 0) { modifiers.add(Modifier.INTERFACE); } if ((access & Opcodes.ACC_ABSTRACT) != 0) { modifiers.add(Modifier.ABSTRACT); } if ((access & Opcodes.ACC_SYNTHETIC) != 0) { modifiers.add(Modifier.SYNTHETIC); } if ((access & Opcodes.ACC_ANNOTATION) != 0) { modifiers.add(Modifier.ANNOTATION); } if ((access & Opcodes.ACC_ENUM) != 0) { modifiers.add(Modifier.ENUM); } if ((access & Opcodes.ACC_VOLATILE) != 0) { modifiers.add(Modifier.VOLATILE); } if ((access & Opcodes.ACC_TRANSIENT) != 0) { modifiers.add(Modifier.TRANSIENT); } if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) { modifiers.add(Modifier.SYNCHRONIZED); } if ((access & Opcodes.ACC_BRIDGE) != 0) { modifiers.add(Modifier.BRIDGE); } if ((access & Opcodes.ACC_VARARGS) != 0) { modifiers.add(Modifier.VARARGS); } if ((access & Opcodes.ACC_NATIVE) != 0) { modifiers.add(Modifier.NATIVE); } if ((access & Opcodes.ACC_STRICT) != 0) { modifiers.add(Modifier.STRICT); } return modifiers; }
From source file:jaspex.speculation.CreateSpeculativeMethodVisitor.java
License:Open Source License
private static MethodVisitor createNextMethodVisitor(int access, String name, String desc, String signature, String[] exceptions, ClassVisitor cv) { if (name.endsWith("$transactional")) { name = name.replace("$transactional", "$speculative"); // Mtodo original podia ser nativo, mas o $speculative no access &= ~Opcodes.ACC_NATIVE; // Todos os mtodos $speculative devem ser public (seno o codegen falha com java.lang.IllegalAccessError) access = access & ~Opcodes.ACC_PRIVATE & ~Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC; }// w w w. ja v a 2s . c o m return cv.visitMethod(access, name, desc, signature, exceptions); }
From source file:jaspex.speculation.SpeculativeTransformer.java
License:Open Source License
public byte[] createSpeculativeMethods(ClassReader cr) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassVisitor cv = cw;//from w w w .j a va2s. c o m // Tornar classe public: para o codegen funcionar, todas as classes tm que ser pblicas // (todos os mtodos $speculative tambm j so public) if (!_JDKClass) cv = new ClassVisitor(Opcodes.ASM4, cv) { @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { access = access & ~Opcodes.ACC_PRIVATE & ~Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC; cv.visit(version, access, name, signature, superName, interfaces); } }; // Visitor que adiciona fields e mtodos para o -detectlocal cv = new InjectDetectLocalClassVisitor(cv); // Criar verses $speculative de mtodos cv = new GenericMethodVisitorAdapter(cv, CreateSpeculativeMethodVisitor.class, currentClass, _JDKClass); // Marcar constructores com SpeculativeCtorMarker cv = new GenericMethodVisitorAdapter(cv, SpeculativeCtorMethodVisitor.class); // Potencialmente substituir alguns dos mtodos com verses internas do JaSPEx cv = new GenericMethodVisitorAdapter(cv, MethodReplacerMethodVisitor.class, currentClass, _JDKClass); // Resolver problema com o acesso a mtodos privados cv = new GenericMethodVisitorAdapter(cv, FixPrivateMethodAccessMethodVisitor.class, currentClass, _JDKClass); // Injectar overloads para a todos os mtodos que so herdados de superclasses no-transactificveis // Nota: Deve estar na pipeline *antes* do CreateSpeculativeMethodVisitor if (!_JDKClass) cv = new InjectOverloadsClassVisitor(cv, currentClass); cr.accept(cv, 0); // Criar verses non-speculative dos mtodos, que funcionam transaccionalmente, mas no // fazem spawn de especulaes new ClassReader(cw.toByteArray()).accept(new CreateNonSpeculativeMethodsClassVisitor(cw), 0); return cw.toByteArray(); }
From source file:jasy.lang.ASMCompiler.java
private static int getAccessModifier(JasyParser.AccessModifierContext ctx, JasyParser.ModStaticContext statCtx) { int mod = Opcodes.ACC_PRIVATE; if (ctx != null) { switch (((TerminalNode) ctx.getChild(0)).getSymbol().getType()) { case JasyLexer.ACC_MOD_PRIVATE: mod = Opcodes.ACC_PRIVATE;/*from w w w.j a v a 2s . c o m*/ break; case JasyLexer.ACC_MOD_PROTECTED: mod = Opcodes.ACC_PROTECTED; break; case JasyLexer.ACC_MOD_PUBLIC: mod = Opcodes.ACC_PUBLIC; break; } } if (statCtx != null) return mod | Opcodes.ACC_STATIC; return mod; }
From source file:jasy.SourceToAstTest.java
private static Predicate<FieldAST> fIsProtected() { return f -> f.selector.accessModifier == Opcodes.ACC_PROTECTED; }
From source file:net.fabricmc.base.transformer.AccessTransformer.java
License:Apache License
@Override public byte[] transform(String name, String transformedName, byte[] bytes) { if (!name.startsWith("net.minecraft")) { return bytes; }/*from w w w . j a v a 2s . c o m*/ ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); boolean isClassProtected = classNode.access == Opcodes.ACC_PROTECTED; boolean isClassPrivate = classNode.access == Opcodes.ACC_PRIVATE; if (isClassProtected || isClassPrivate) { classNode.access = Opcodes.ACC_PUBLIC; } for (MethodNode method : classNode.methods) { boolean isProtected = method.access == Opcodes.ACC_PROTECTED; boolean isPrivate = method.access == Opcodes.ACC_PRIVATE; if (isProtected || isPrivate) { method.access = Opcodes.ACC_PUBLIC; } } for (FieldNode field : classNode.fields) { boolean isProtected = field.access == Opcodes.ACC_PROTECTED; boolean isPrivate = field.access == Opcodes.ACC_PRIVATE; if (isProtected || isPrivate) { field.access = Opcodes.ACC_PUBLIC; } } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); }
From source file:net.sf.clirr.core.internal.asm.AbstractAsmScoped.java
License:Open Source License
public Scope getDeclaredScope() { if (checkFlag(Opcodes.ACC_PRIVATE)) { return Scope.PRIVATE; } else if (checkFlag(Opcodes.ACC_PROTECTED)) { return Scope.PROTECTED; } else if (checkFlag(Opcodes.ACC_PUBLIC)) { return Scope.PUBLIC; }/* w w w .j a v a 2s . c o m*/ return Scope.PACKAGE; }