List of usage examples for org.objectweb.asm Opcodes ACC_SYNTHETIC
int ACC_SYNTHETIC
To view the source code for org.objectweb.asm Opcodes ACC_SYNTHETIC.
Click Source Link
From source file:org.spockframework.compiler.SpecRewriter.java
License:Apache License
private void createSharedFieldSetter(Field field) { String setterName = "set" + MetaClassHelper.capitalize(field.getName()); Parameter[] params = new Parameter[] { new Parameter(field.getAst().getType(), "$spock_value") }; MethodNode setter = spec.getAst().getMethod(setterName, params); if (setter != null) { errorReporter.error(field.getAst(), "@Shared field '%s' conflicts with method '%s'; please rename either of them", field.getName(), setter.getName());/*from www . j a va 2 s . c om*/ return; } BlockStatement setterBlock = new BlockStatement(); setter = new MethodNode(setterName, determineVisibilityForSharedFieldAccessor(field) | Opcodes.ACC_SYNTHETIC, ClassHelper.VOID_TYPE, params, ClassNode.EMPTY_ARRAY, setterBlock); setterBlock.addStatement(new ExpressionStatement(new BinaryExpression( new AttributeExpression(getSharedInstance(), // use internal name new ConstantExpression(field.getAst().getName())), Token.newSymbol(Types.ASSIGN, -1, -1), new VariableExpression("$spock_value")))); setter.setSourcePosition(field.getAst()); spec.getAst().addMethod(setter); }
From source file:org.spockframework.compiler.SpecRewriter.java
License:Apache License
private FixtureMethod getInitializerMethod() { if (spec.getInitializerMethod() == null) { // method is private s.t. multiple initializer methods along hierarchy can be called independently MethodNode gMethod = new MethodNode(InternalIdentifiers.INITIALIZER_METHOD, Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC, ClassHelper.DYNAMIC_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement()); spec.getAst().addMethod(gMethod); FixtureMethod method = new FixtureMethod(spec, gMethod); method.addBlock(new AnonymousBlock(method)); spec.setInitializerMethod(method); }//ww w . j a va 2 s . c o m return spec.getInitializerMethod(); }
From source file:org.spockframework.compiler.SpecRewriter.java
License:Apache License
private FixtureMethod getSharedInitializerMethod() { if (spec.getSharedInitializerMethod() == null) { // method is private s.t. multiple initializer methods along hierarchy can be called independently MethodNode gMethod = new MethodNode(InternalIdentifiers.SHARED_INITIALIZER_METHOD, Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC, ClassHelper.DYNAMIC_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, new BlockStatement()); spec.getAst().addMethod(gMethod); FixtureMethod method = new FixtureMethod(spec, gMethod); method.addBlock(new AnonymousBlock(method)); spec.setSharedInitializerMethod(method); }/*from w ww . j a v a2s . c om*/ return spec.getSharedInitializerMethod(); }
From source file:org.spockframework.compiler.WhereBlockRewriter.java
License:Apache License
private void createDataProviderMethod(Expression dataProviderExpr, int nextDataVariableIndex) { instanceFieldAccessChecker.check(dataProviderExpr); dataProviderExpr = dataProviderExpr.transformExpression(new DataTablePreviousVariableTransformer()); MethodNode method = new MethodNode( InternalIdentifiers.getDataProviderName(whereBlock.getParent().getAst().getName(), dataProviderCount++), Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, ClassHelper.OBJECT_TYPE, getPreviousParameters(nextDataVariableIndex), ClassNode.EMPTY_ARRAY, new BlockStatement( Arrays.<Statement>asList(new ReturnStatement(new ExpressionStatement(dataProviderExpr))), new VariableScope())); method.addAnnotation(createDataProviderAnnotation(dataProviderExpr, nextDataVariableIndex)); whereBlock.getParent().getParent().getAst().addMethod(method); }
From source file:org.spockframework.compiler.WhereBlockRewriter.java
License:Apache License
@SuppressWarnings("unchecked") private void createDataProcessorMethod() { if (dataProcessorVars.isEmpty()) return;//from w w w . j a v a2 s.c o m dataProcessorStats .add(new ReturnStatement(new ArrayExpression(ClassHelper.OBJECT_TYPE, (List) dataProcessorVars))); BlockStatement blockStat = new BlockStatement(dataProcessorStats, new VariableScope()); new DataProcessorVariableRewriter().visitBlockStatement(blockStat); whereBlock.getParent().getParent().getAst() .addMethod(new MethodNode( InternalIdentifiers.getDataProcessorName(whereBlock.getParent().getAst().getName()), Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, ClassHelper.OBJECT_TYPE, dataProcessorParams.toArray(new Parameter[dataProcessorParams.size()]), ClassNode.EMPTY_ARRAY, blockStat)); }
From source file:org.spongepowered.asm.mixin.injection.struct.InjectionInfo.java
License:MIT License
/** * Inject a method into the target class * /*from w w w .ja va2 s . c om*/ * @param access Method access flags, synthetic will be automatically added * @param name Method name * @param desc Method descriptor * * @return new method */ public MethodNode addMethod(int access, String name, String desc) { MethodNode method = new MethodNode(Opcodes.ASM5, access | Opcodes.ACC_SYNTHETIC, name, desc, null, null); this.injectedMethods.add(method); return method; }
From source file:org.spongepowered.asm.mixin.transformer.ClassInfo.java
License:MIT License
/** * Initialise a ClassInfo from the supplied {@link ClassNode} * /* w ww .jav a 2s . c o m*/ * @param classNode Class node to inspect */ private ClassInfo(ClassNode classNode) { this.name = classNode.name; this.superName = classNode.superName != null ? classNode.superName : ClassInfo.JAVA_LANG_OBJECT; this.methods = new HashSet<Method>(); this.fields = new ArrayList<String>(); this.isInterface = ((classNode.access & Opcodes.ACC_INTERFACE) != 0); this.interfaces = Collections.unmodifiableList(classNode.interfaces); this.access = classNode.access; this.isMixin = classNode instanceof MixinClassNode; this.mixin = this.isMixin ? ((MixinClassNode) classNode).getMixin() : null; for (MethodNode method : classNode.methods) { this.addMethod(method, this.isMixin); } String outerName = classNode.outerClass; if (outerName == null) { for (FieldNode field : classNode.fields) { if ((field.access & Opcodes.ACC_SYNTHETIC) != 0) { if (field.name.startsWith("this$")) { outerName = field.desc; if (outerName.startsWith("L")) { outerName = outerName.substring(1, outerName.length() - 1); } } } else if ((field.access & Opcodes.ACC_PRIVATE) == 0) { this.fields.add(field.name + "()" + field.desc); } } } this.outerName = outerName; }
From source file:org.spongepowered.asm.mixin.transformer.MixinTransformer.java
License:MIT License
/** * Mixin methods from the mixin class into the target class * /*w w w .j a va2 s .c o m*/ * @param targetClass * @param mixin */ private void applyMixinMethods(ClassNode targetClass, MixinTargetContext mixin) { for (MethodNode mixinMethod : mixin.getClassNode().methods) { // Reparent all mixin methods into the target class mixin.transformMethod(mixinMethod); boolean isShadow = ASMHelper.getVisibleAnnotation(mixinMethod, Shadow.class) != null; boolean isOverwrite = ASMHelper.getVisibleAnnotation(mixinMethod, Overwrite.class) != null; boolean isAbstract = MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_ABSTRACT); if (isShadow || isAbstract) { // For shadow (and abstract, which can be used as a shorthand for Shadow) methods, we just check they're present MethodNode target = this.findTargetMethod(targetClass, mixinMethod); if (target == null) { throw new InvalidMixinException(mixin, String .format("Shadow method %s was not located in the target class", mixinMethod.name)); } } else if (!mixinMethod.name.startsWith("<")) { if (MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_STATIC) && !MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_PRIVATE) && !MixinTransformer.hasFlag(mixinMethod, Opcodes.ACC_SYNTHETIC) && !isOverwrite) { throw new InvalidMixinException(mixin, String.format("Mixin classes cannot contain visible static methods or fields, found %s", mixinMethod.name)); } this.mergeMethod(targetClass, mixin, mixinMethod, isOverwrite); } else if (MixinTransformer.CLINIT.equals(mixinMethod.name)) { // Class initialiser insns get appended this.appendInsns(targetClass, mixinMethod.name, mixinMethod); } } }
From source file:org.spongepowered.mod.asm.util.ASMHelper.java
License:MIT License
/** * Generate a new method "boolean name()", which returns a constant value. * * @param clazz Class to add method to/*from w w w . j av a 2 s . co m*/ * @param name Name of method * @param retval Return value of method */ public static void generateBooleanMethodConst(ClassNode clazz, String name, boolean retval) { MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()Z", null, null); InsnList code = method.instructions; code.add(new InsnNode(retval ? Opcodes.ICONST_1 : Opcodes.ICONST_0)); code.add(new InsnNode(Opcodes.IRETURN)); clazz.methods.add(method); }
From source file:org.spongepowered.mod.asm.util.ASMHelper.java
License:MIT License
/** * Generate a new method "int name()", which returns a constant value. * * @param clazz Class to add method to/*from ww w . j av a2s. c om*/ * @param name Name of method * @param retval Return value of method */ public static void generateIntegerMethodConst(ClassNode clazz, String name, short retval) { MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()I", null, null); InsnList code = method.instructions; // Probably doesn't make a huge difference, but use BIPUSH if the value is small enough. if (retval >= Byte.MIN_VALUE && retval <= Byte.MAX_VALUE) { code.add(new IntInsnNode(Opcodes.BIPUSH, retval)); } else { code.add(new IntInsnNode(Opcodes.SIPUSH, retval)); } code.add(new InsnNode(Opcodes.IRETURN)); clazz.methods.add(method); }