/** * Copies annotation from the trait to the helper, excluding the trait annotation itself * @param cNode the trait class node * @param helper the helper class node */ private static void copyClassAnnotations(final ClassNode cNode, final ClassNode helper) { List<AnnotationNode> annotations = cNode.getAnnotations(); for (AnnotationNode annotation : annotations) { if (!annotation.getClassNode().equals(Traits.TRAIT_CLASSNODE)) { helper.addAnnotation(annotation); } } }
private void addSpecMetadata(Spec spec) { AnnotationNode ann = new AnnotationNode(nodeCache.SpecMetadata); String pathname = spec.getAst().getModule().getContext().getName(); String filename = new File(pathname).getName(); ann.setMember(SpecMetadata.FILENAME, new ConstantExpression(filename)); ann.setMember(SpecMetadata.LINE, new ConstantExpression(spec.getAst().getLineNumber())); spec.getAst().addAnnotation(ann); }
private void setScriptBaseClassFromConfig(ClassNode cn) { String baseClassName = null; if (unit != null) { baseClassName = unit.getConfig().getScriptBaseClass(); } else if (context != null) { baseClassName = context.getConfiguration().getScriptBaseClass(); } if (baseClassName != null) { if (!cn.getSuperClass().getName().equals(baseClassName)) { cn.setSuperClass(ClassHelper.make(baseClassName)); AnnotationNode annotationNode = new AnnotationNode(BaseScriptASTTransformation.MY_TYPE); cn.addAnnotation(annotationNode); } } }
ACC_PUBLIC | ACC_STATIC | ACC_FINAL, ClassHelper.OBJECT_TYPE.getPlainNodeReference()); cn.getModule().addClass(helper); helper.addAnnotation(new AnnotationNode(COMPILESTATIC_CLASSNODE)); MethodNode serializeClass = collector.getClassNode().getMethod("serializeClass", Parameter.EMPTY_ARRAY); collector.setMember("serializeClass", new ClassExpression(helper.getPlainNodeReference()));
private void addAnnotationsFromTo(final AnnotationNode annotationNode, final ClassNode annotatedNode) { final String qualifiedName = A.UTIL.NODE.get(annotationNode, String.class); final String target = A.UTIL.NODE.get(annotationNode, "applyTo", String.class); annotatedNode.addAnnotation(getTargetAnnotation(target)); annotatedNode.addAnnotation(getRetentionAnnotation()); annotatedNode.addAnnotation(getGroovyAnnotationWith(qualifiedName)); }
/** * All transformation will be always annotated with: * * <ul> * <li>{@link InheritConstructors}</li> * <li>{@link GroovyASTTransformation}</li> * </ul> * * To avoid repeating this over and over again this method adds * both to the annotated {@link ClassNode} passed as first * argument * * @param annotated The {@link ClassNode} we want to add both * annotations to * @param compilePhase The {@link CompilePhase} used as argument for * the {@link GroovyASTTransformation} annotation. * @since 0.2.0 */ public static void addASTAnnotationsFromTo(final ClassNode annotated, final CompilePhase compilePhase) { final AnnotationNode groovyAnn = getGroovyAnnotation(compilePhase); final AnnotationNode inheritConsAnn = getInheritConstructorsAnnotation(); annotated.addAnnotation(inheritConsAnn); annotated.addAnnotation(groovyAnn); }
private void markClassNodeAsContracted(final ClassNode classNode) { final ClassNode contractedAnnotationClassNode = ClassHelper.makeWithoutCaching(Contracted.class); if (classNode.getAnnotations(contractedAnnotationClassNode).isEmpty()) classNode.addAnnotation(new AnnotationNode(contractedAnnotationClassNode)); } }
private void setAnnotationMetaData(ClassNode cn) { Annotation[] annotations = cn.getTypeClass().getAnnotations(); for (int i=0; i<annotations.length; i++) { Annotation annotation = annotations[i]; AnnotationNode node = new AnnotationNode(ClassHelper.make(annotation.annotationType())); configureAnnotation(node,annotation); cn.addAnnotation(node); } }
private void addEnableAutoConfigurationAnnotation(ClassNode classNode) { if (!hasEnableAutoConfigureAnnotation(classNode)) { AnnotationNode annotationNode = new AnnotationNode( ClassHelper.make("EnableAutoConfiguration")); classNode.addAnnotation(annotationNode); } }
@Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { if (staticCompile) { classNode.addAnnotation(new AnnotationNode(new ClassNode(CompileStatic.class))); } classNode.addAnnotation(new AnnotationNode(new ClassNode(InheritConstructors.class))); if (scriptPath != null) { AnnotationNode scriptPathAnnotation = new AnnotationNode(new ClassNode(ScriptPath.class)); scriptPathAnnotation.addMember("value", new ConstantExpression(scriptPath.toUri().toString())); classNode.addAnnotation(scriptPathAnnotation); } } });
public void applyGroovyInstrumentor(ClassNode classNode) { classNode.addAnnotation(new AnnotationNode(new ClassNode(GroovyInstrumentor.class))); } }
@Override public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration, GeneratorContext generatorContext, SourceUnit source, ClassNode classNode) throws CompilationFailedException { if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) { AnnotationNode runWith = new AnnotationNode(ClassHelper.make("RunWith")); runWith.addMember("value", new ClassExpression(ClassHelper.make("SpringRunner"))); classNode.addAnnotation(runWith); } }
private void setAnnotationMetaData(ClassNode cn) { Annotation[] annotations = cn.getTypeClass().getAnnotations(); for (Annotation annotation : annotations) { AnnotationNode node = new AnnotationNode(ClassHelper.make(annotation.annotationType())); configureAnnotation(node, annotation); cn.addAnnotation(node); } }
/** * Add a single dependency with the specified classifier and type and, optionally, all * of its dependencies. The group ID and version of the dependency are resolved from * the module by using the customizer's {@link ArtifactCoordinatesResolver}. * @param module the module ID * @param classifier the classifier, may be {@code null} * @param type the type, may be {@code null} * @param transitive {@code true} if the transitive dependencies should also be added, * otherwise {@code false} * @return this {@link DependencyCustomizer} for continued use */ public DependencyCustomizer add(String module, String classifier, String type, boolean transitive) { if (canAdd()) { ArtifactCoordinatesResolver artifactCoordinatesResolver = this.dependencyResolutionContext .getArtifactCoordinatesResolver(); this.classNode.addAnnotation( createGrabAnnotation(artifactCoordinatesResolver.getGroupId(module), artifactCoordinatesResolver.getArtifactId(module), artifactCoordinatesResolver.getVersion(module), classifier, type, transitive)); } return this; }
classNode.addAnnotation(new AnnotationNode(WORKFLOW_TRANSFORMED_TYPE));
private void visitModule(ModuleNode module) { for (ClassNode classNode : module.getClasses()) { AnnotationNode annotation = new AnnotationNode(new ClassNode(Grab.class)); annotation.addMember("value", new ConstantExpression("groovy")); classNode.addAnnotation(annotation); // We only need to do it at most once break; } // Disable the addition of a static initializer that calls Grape.addResolver // because all the dependencies are local now disableGrabResolvers(module.getClasses()); disableGrabResolvers(module.getImports()); }
@Override public void visitBlockStatement(BlockStatement block) { if (block.isEmpty() || this.xformed) { return; } ClosureExpression closure = ratpack(block); if (closure != null) { this.classNode.addAnnotation(new AnnotationNode(ClassHelper .make("Component"))); // Add a marker interface to the current script this.classNode.addInterface(ClassHelper.make(SOURCE_INTERFACE)); // Implement the interface by adding a public read-only property with the // same name as the method in the interface (getRatpack). Make it return the // closure. this.classNode.addProperty(new PropertyNode(RATPACK, Modifier.PUBLIC | Modifier.FINAL, ClassHelper.CLOSURE_TYPE .getPlainNodeReference(), this.classNode, closure, null, null)); // Only do this once per class this.xformed = true; } }