); if (shouldAnnotate) { methodNode.addAnnotation(generatedAnnotation); methodNode.addAnnotation(internalAnnotation); ); if (shouldAnnotate) { methodNode.addAnnotation(generatedAnnotation); methodNode.addAnnotation(internalAnnotation); ); if (shouldAnnotate) { methodNode.addAnnotation(generatedAnnotation); methodNode.addAnnotation(internalAnnotation); ); if (shouldAnnotate) { methodNode.addAnnotation(generatedAnnotation); methodNode.addAnnotation(internalAnnotation); ); if (shouldAnnotate) { methodNode.addAnnotation(generatedAnnotation); methodNode.addAnnotation(internalAnnotation);
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; }
protected void addTypeCheckingInfoAnnotation(final MethodNode node) { // TypeChecked$TypeCheckingInfo can not be applied on constructors if (node instanceof ConstructorNode) return; // if a returned inferred type is available and no @TypeCheckingInfo is on node, then add an // annotation to the method node ClassNode rtype = getInferredReturnType(node); if (rtype != null && node.getAnnotations(TYPECHECKING_INFO_NODE).isEmpty()) { AnnotationNode anno = new AnnotationNode(TYPECHECKING_INFO_NODE); anno.setMember("version", CURRENT_SIGNATURE_PROTOCOL); SignatureCodec codec = SignatureCodecFactory.getCodec(CURRENT_SIGNATURE_PROTOCOL_VERSION, getTransformLoader()); String genericsSignature = codec.encode(rtype); if (genericsSignature != null) { ConstantExpression signature = new ConstantExpression(genericsSignature); signature.setType(STRING_TYPE); anno.setMember("inferredType", signature); node.addAnnotation(anno); } } }
bridgeAnnotation.addMember("traitClass", new ClassExpression(trait)); bridgeAnnotation.addMember("desc", new ConstantExpression(BytecodeHelper.getMethodDescriptor(helperMethod.getReturnType(), traitMethodParams))); forwarder.addAnnotation( bridgeAnnotation );
bridge.addAnnotation(new AnnotationNode(COMPILESTATIC_CLASSNODE));
private void addFeatureMetadata(FeatureMethod feature) { AnnotationNode ann = new AnnotationNode(nodeCache.FeatureMetadata); ann.setMember(FeatureMetadata.NAME, new ConstantExpression(feature.getName())); ann.setMember(FeatureMetadata.ORDINAL, new ConstantExpression(feature.getOrdinal())); ann.setMember(FeatureMetadata.LINE, new ConstantExpression(feature.getAst().getLineNumber())); ann.setMember(FeatureMetadata.BLOCKS, blockAnnElems = new ListExpression()); ListExpression paramNames = new ListExpression(); for (Parameter param : feature.getAst().getParameters()) paramNames.addExpression(new ConstantExpression(param.getName())); ann.setMember(FeatureMetadata.PARAMETER_NAMES, paramNames); feature.getAst().addAnnotation(ann); }
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); }
); AnnotationNode an = new AnnotationNode(COMPILESTATIC_CLASSNODE); impl.addAnnotation(an); cNode.addTransform(StaticCompileTransformation.class, an); cNode.addMethod(impl);
protected void autoAnnotateSetupTeardown(ClassNode classNode) { MethodNode setupMethod = classNode.getDeclaredMethod(SET_UP_METHOD, GrailsArtefactClassInjector.ZERO_PARAMETERS); if ( setupMethod != null && setupMethod.getAnnotations(TestForTransformation.BEFORE_CLASS_NODE).size() == 0) { setupMethod.addAnnotation(TestForTransformation.BEFORE_ANNOTATION); } MethodNode tearDown = classNode.getDeclaredMethod(TEAR_DOWN_METHOD, GrailsArtefactClassInjector.ZERO_PARAMETERS); if ( tearDown != null && tearDown.getAnnotations(TestForTransformation.AFTER_CLASS_NODE).size() == 0) { tearDown.addAnnotation(TestForTransformation.AFTER_ANNOTATION); } } }
private BlockStatement getJunit4Setup(ClassNode classNode) { MethodNode setupMethod = classNode.getDeclaredMethod(SET_UP_METHOD, GrailsArtefactClassInjector.ZERO_PARAMETERS); if (setupMethod == null) { setupMethod = new MethodNode(SET_UP_METHOD,Modifier.PUBLIC,ClassHelper.VOID_TYPE,GrailsArtefactClassInjector.ZERO_PARAMETERS,null,new BlockStatement()); setupMethod.addAnnotation(MIXIN_METHOD_ANNOTATION); classNode.addMethod(setupMethod); } if (setupMethod.getAnnotations(BEFORE_CLASS_NODE).size() == 0) { setupMethod.addAnnotation(BEFORE_ANNOTATION); } return getOrCreateMethodBody(classNode, setupMethod, SET_UP_METHOD); }
private void autoAddTestAnnotation(ClassNode classNode) { if(isSpockTest(classNode)) return; Map<String, MethodNode> declaredMethodsMap = classNode.getDeclaredMethodsMap(); for (String methodName : declaredMethodsMap.keySet()) { MethodNode methodNode = declaredMethodsMap.get(methodName); ClassNode testAnnotationClassNode = TEST_ANNOTATION.getClassNode(); List<AnnotationNode> existingTestAnnotations = methodNode.getAnnotations(testAnnotationClassNode); if (isCandidateMethod(methodNode) && (methodNode.getName().startsWith("test") || existingTestAnnotations.size()>0)) { if (existingTestAnnotations.size()==0) { ClassNode returnType = methodNode.getReturnType(); if (returnType.getName().equals(VOID_TYPE)) { methodNode.addAnnotation(TEST_ANNOTATION); } } } } }
protected void annotateActionMethod(ClassNode controllerClassNode, final Parameter[] parameters, final MethodNode methodNode) { if (isCommandObjectAction(parameters)) { ListExpression initArray = new ListExpression(); for (Parameter parameter : parameters) { initArray.addExpression(new ClassExpression(parameter.getType())); } AnnotationNode paramActionAnn = new AnnotationNode(new ClassNode(Action.class)); paramActionAnn.setMember(ACTION_MEMBER_TARGET, initArray); methodNode.addAnnotation(paramActionAnn); } else { methodNode.addAnnotation(ACTION_ANNOTATION_NODE); } }
public void addFieldAnnotationToMethod(ClassNode classNode, FieldNode fieldNode, AnnotationNode annotationNode) throws NoSuchGetterException { MethodNode getterNode = GroovyUtils.getGetter(classNode, fieldNode); if (getterNode == null || !getterNode.getDeclaringClass().equals(classNode)) throw new NoSuchGetterException("Cannot apply chromattic annotations because getter don't exist for : " + fieldNode.getName()); getterNode.addAnnotation(annotationNode); }
private void setAnnotationMetaData(MethodNode mn, Method m) { Annotation[] annotations = m.getAnnotations(); for (Annotation annotation : annotations) { AnnotationNode node = new AnnotationNode(ClassHelper.make(annotation.annotationType())); configureAnnotation(node, annotation); mn.addAnnotation(node); } }
public void addSetterDelegationAnnotation(ClassNode classNode, FieldNode fieldNode) throws NoSuchSetterException { MethodNode setterNode = GroovyUtils.getSetter(classNode, fieldNode); if (setterNode == null || !setterNode.getDeclaringClass().equals(classNode)) throw new NoSuchSetterException("Cannot apply annotation @ChromatticDelegation because setter don't exist for : " + fieldNode.getName()); setterNode.addAnnotation(new AnnotationNode(new ClassNode(ChromatticDelegation.class))); }
/** * Captures the parameter names as annotations on the class. */ private void write(MethodNode c) { ListExpression v = new ListExpression(); for( Parameter p : c.getParameters() ) v.addExpression(new ConstantExpression(p.getName())); AnnotationNode a = new AnnotationNode(new ClassNode(CapturedParameterNames.class)); a.addMember("value",v); c.addAnnotation(a); } }
/** * Captures the parameter names as annotations on the class. */ private void write(MethodNode c) { ListExpression v = new ListExpression(); for( Parameter p : c.getParameters() ) v.addExpression(new ConstantExpression(p.getName())); AnnotationNode a = new AnnotationNode(new ClassNode(CapturedParameterNames.class)); a.addMember("value",v); c.addAnnotation(a); } }
/** * Captures the parameter names as annotations on the class. */ private void write(MethodNode c) { ListExpression v = new ListExpression(); for( Parameter p : c.getParameters() ) v.addExpression(new ConstantExpression(p.getName())); AnnotationNode a = new AnnotationNode(new ClassNode(CapturedParameterNames.class)); a.addMember("value",v); c.addAnnotation(a); } }
protected MethodNode addClassUnderTestMethod(ClassNode classNode, ClassExpression targetClass, String type) { String methodName = "setup" + type + "UnderTest"; String fieldName = TestMixinTransformation.getPropertyNameRepresentation(type); String getterName = TestMixinTransformation.getGetterName(fieldName); fieldName = '$' +fieldName; if (classNode.getField(fieldName) == null) { classNode.addField(fieldName, Modifier.PRIVATE, targetClass.getType(),null); } MethodNode methodNode = classNode.getMethod(methodName,TestMixinTransformation.ZERO_PARAMETERS); VariableExpression fieldExpression = new VariableExpression(fieldName); if (methodNode == null) { BlockStatement setupMethodBody = new BlockStatement(); addMockClassUnderTest(type, fieldExpression, targetClass, setupMethodBody); methodNode = new MethodNode(methodName, Modifier.PUBLIC, ClassHelper.VOID_TYPE, TestMixinTransformation.ZERO_PARAMETERS,null, setupMethodBody); methodNode.addAnnotation(BEFORE_ANNOTATION); methodNode.addAnnotation(MIXIN_METHOD_ANNOTATION); classNode.addMethod(methodNode); } MethodNode getter = classNode.getMethod(getterName, TestMixinTransformation.ZERO_PARAMETERS); if(getter == null) { BlockStatement getterBody = new BlockStatement(); getter = new MethodNode(getterName, Modifier.PUBLIC, targetClass.getType().getPlainNodeReference(),TestMixinTransformation.ZERO_PARAMETERS,null, getterBody); getterBody.addStatement(new ReturnStatement(fieldExpression)); classNode.addMethod(getter); } return methodNode; }
methodNode.addAnnotation(BEFORE_ANNOTATION); methodNode.addAnnotation(MIXIN_METHOD_ANNOTATION);