private static MethodNode buildDelegatingMethod(final MethodNode annotatedMethod, final ClassNode ownerClassNode) { Statement code = annotatedMethod.getCode(); int access = ACC_PROTECTED; if (annotatedMethod.isStatic()) { access = ACC_PRIVATE | ACC_STATIC; } MethodNode method = new MethodNode( buildUniqueName(ownerClassNode, METHOD_LABEL, annotatedMethod), access, annotatedMethod.getReturnType(), cloneParams(annotatedMethod.getParameters()), annotatedMethod.getExceptions(), code ); method.addAnnotations(filterAnnotations(annotatedMethod.getAnnotations())); return method; }
private MethodNode copyMethod(MethodNode method, String newName) { // can't hurt to set return type to void MethodNode newMethod = new MethodNode(newName, method.getModifiers(), ClassHelper.VOID_TYPE, method.getParameters(), method.getExceptions(), method.getCode()); newMethod.addAnnotations(method.getAnnotations()); newMethod.setSynthetic(method.isSynthetic()); newMethod.setDeclaringClass(method.getDeclaringClass()); newMethod.setSourcePosition(method); newMethod.setVariableScope(method.getVariableScope()); newMethod.setGenericsTypes(method.getGenericsTypes()); newMethod.setAnnotationDefault(method.hasAnnotationDefault()); return newMethod; }
newMethod.addAnnotations(copyAnnotatedNodeAnnotations(candidate, MY_TYPE_NAME));
forwarder.addAnnotations(copied);
private MethodNode processMethod(ClassNode traitClass, ClassNode traitHelperClass, MethodNode methodNode, ClassNode fieldHelper, Collection<String> knownFields) { Parameter[] initialParams = methodNode.getParameters(); Parameter[] newParams = new Parameter[initialParams.length + 1]; newParams[0] = createSelfParameter(traitClass, methodNode.isStatic()); System.arraycopy(initialParams, 0, newParams, 1, initialParams.length); final int mod = methodNode.isPrivate() ? ACC_PRIVATE : ACC_PUBLIC | (methodNode.isFinal() ? ACC_FINAL : 0); MethodNode mNode = new MethodNode( methodNode.getName(), mod | ACC_STATIC, methodNode.getReturnType(), newParams, methodNode.getExceptions(), processBody(new VariableExpression(newParams[0]), methodNode.getCode(), traitClass, traitHelperClass, fieldHelper, knownFields) ); mNode.setSourcePosition(methodNode); mNode.addAnnotations(filterAnnotations(methodNode.getAnnotations())); mNode.setGenericsTypes(methodNode.getGenericsTypes()); if (methodNode.isAbstract()) { mNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT); } else { methodNode.addAnnotation(new AnnotationNode(Traits.IMPLEMENTED_CLASSNODE)); } methodNode.setCode(null); if (!methodNode.isPrivate() && !methodNode.isStatic()) { methodNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT); } return mNode; }
methodNode.addAnnotations(annotations); methodNode.setGenericsTypes(generics); methodNode.setAnnotationDefault(hasAnnotationDefault);
newMethod.addAnnotations(annotations);
/** * Creates a getter method and adds it to the declaring class. * * @param declaringClass The class to which the method is added * @param propertyNode The property node being accessed by this getter * @param getterName The name of the getter method * @param getterBlock The code body of the method */ protected void createGetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String getterName, Statement getterBlock, List<AnnotationNode> annotations) { int mod = propertyNode.getModifiers() | Opcodes.ACC_FINAL; MethodNode getter = new MethodNode(getterName, mod, propertyNode.getType(), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock); if (annotations != null) { getter.addAnnotations(annotations); } getter.setSynthetic(true); declaringClass.addMethod(getter); }
/** * Creates a setter method and adds it to the declaring class. The setter has the form: * <p> * void <setter>(<type> fieldName) * * @param declaringClass The class to which the method is added * @param propertyNode The property node being accessed by this setter * @param setterName The name of the setter method * @param setterBlock The code body of the method */ protected void createSetterMethod(ClassNode declaringClass, PropertyNode propertyNode, String setterName, Statement setterBlock, List<AnnotationNode> annotations) { Parameter[] setterParameterTypes = {new Parameter(propertyNode.getType(), "value")}; int mod = propertyNode.getModifiers() | Opcodes.ACC_FINAL; MethodNode setter = new MethodNode(setterName, mod, ClassHelper.VOID_TYPE, setterParameterTypes, ClassNode.EMPTY_ARRAY, setterBlock); if (annotations != null) { setter.addAnnotations(annotations); } setter.setSynthetic(true); declaringClass.addMethod(setter); }
methodNode.addAnnotations(annotations); methodNode.setGenericsTypes(generics); configureAST(methodNode, methodDef);
returnType, copyParameters(parameterTypes), EMPTY_CLASS_ARRAY, methodBody); methodNode.addAnnotations(delegateMethod.getAnnotations());
methodNode.addAnnotations(annotations); methodNode.setGenericsTypes(generics); methodNode.setAnnotationDefault(hasAnnotationDefault);
methodNode.addAnnotations(annotations); methodNode.setGenericsTypes(generics); methodNode.setAnnotationDefault(hasAnnotationDefault);
methodNode.addAnnotations(annotations); methodNode.setGenericsTypes(generics); methodNode.setAnnotationDefault(hasAnnotationDefault);
Modifier.PUBLIC, returnType, copyParameters(parameterTypes), EMPTY_CLASS_ARRAY, methodBody); methodNode.addAnnotations(declaredMethod.getAnnotations());
newMethod.addAnnotations(annotations);