Package org.codehaus.groovy.ast

Examples of org.codehaus.groovy.ast.AnnotationNode


    assertGrabAnnotationHasBeenTransformation();
  }

  private AnnotationNode createGrabAnnotation() {
    ClassNode classNode = new ClassNode(Grab.class);
    AnnotationNode annotationNode = new AnnotationNode(classNode);
    annotationNode.addMember("value", new ConstantExpression("spring-core"));
    return annotationNode;
  }
View Full Code Here


      }
    }

    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;
      }
      // Remove GrabReolvers because all the dependencies are local now
View Full Code Here

  public void basicAdd() {
    this.dependencyCustomizer.add("spring-boot-starter-logging");
    List<AnnotationNode> grabAnnotations = this.classNode
        .getAnnotations(new ClassNode(Grab.class));
    assertEquals(1, grabAnnotations.size());
    AnnotationNode annotationNode = grabAnnotations.get(0);
    assertGrabAnnotation(annotationNode, "org.springframework.boot",
        "spring-boot-starter-logging", "1.2.3", null, null, true);
  }
View Full Code Here

  public void nonTransitiveAdd() {
    this.dependencyCustomizer.add("spring-boot-starter-logging", false);
    List<AnnotationNode> grabAnnotations = this.classNode
        .getAnnotations(new ClassNode(Grab.class));
    assertEquals(1, grabAnnotations.size());
    AnnotationNode annotationNode = grabAnnotations.get(0);
    assertGrabAnnotation(annotationNode, "org.springframework.boot",
        "spring-boot-starter-logging", "1.2.3", null, null, false);
  }
View Full Code Here

    this.dependencyCustomizer.add("spring-boot-starter-logging", "my-classifier",
        "my-type", false);
    List<AnnotationNode> grabAnnotations = this.classNode
        .getAnnotations(new ClassNode(Grab.class));
    assertEquals(1, grabAnnotations.size());
    AnnotationNode annotationNode = grabAnnotations.get(0);
    assertGrabAnnotation(annotationNode, "org.springframework.boot",
        "spring-boot-starter-logging", "1.2.3", "my-classifier", "my-type", false);
  }
View Full Code Here

        if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
            throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
        }

        AnnotatedNode parent = (AnnotatedNode) nodes[1];
        AnnotationNode node = (AnnotationNode) nodes[0];
        if (!MY_TYPE.equals(node.getClassNode())) return;

        if (parent instanceof FieldNode) {
            FieldNode fNode = (FieldNode) parent;
            ClassNode cNode = fNode.getDeclaringClass();
            if (cNode.getProperty(fNode.getName()) == null) {
View Full Code Here

    if (!(firstNode instanceof AnnotationNode) || !(secondNode instanceof AnnotatedNode)) {
      throw new RuntimeException("Internal error: wrong types: " + firstNode.getClass().getName() +
          " / " + secondNode.getClass().getName());
    }

    final AnnotationNode grailsCacheAnnotationNode = (AnnotationNode) firstNode;
    final AnnotatedNode annotatedNode = (AnnotatedNode) secondNode;
    final AnnotationNode springCacheAnnotationNode = getCorrespondingSpringAnnotation(
        grailsCacheAnnotationNode);
    annotatedNode.addAnnotation(springCacheAnnotationNode);
  }
View Full Code Here

  protected AnnotationNode getCorrespondingSpringAnnotation(final AnnotationNode grailsCacheAnnotationNode) {
    final Map<String, Expression> grailsAnnotationMembers = grailsCacheAnnotationNode.getMembers();

    final ClassNode springCacheAnnotationClassNode = GRAILS_ANNOTATION_CLASS_NODE_TO_SPRING_ANNOTATION_CLASS_NODE.get(
        grailsCacheAnnotationNode.getClassNode());
    final AnnotationNode springCacheAnnotationNode = new AnnotationNode(springCacheAnnotationClassNode);
    for (Map.Entry<String, Expression> entry : grailsAnnotationMembers.entrySet()) {
      springCacheAnnotationNode.addMember(entry.getKey(), entry.getValue());
    }
    return springCacheAnnotationNode;
  }
View Full Code Here

    }
    compilerConfiguration.addCompilationCustomizers(new CompilationCustomizer(CompilePhase.CONVERSION) {
      @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);
        }
      }
    });

    return new GroovyClassLoader(parentLoader, compilerConfiguration) {
      @Override
      protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) {
        return new CompilationUnit(config, source, this) {
          {
            verifier = new Verifier() {
              @Override
              public void visitClass(ClassNode node) {
                if (node.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type)) {
                  AnnotationNode lineNumberAnnotation = new AnnotationNode(LINE_NUMBER_CLASS_NODE);
                  lineNumberAnnotation.addMember("value", new ConstantExpression(node.getLineNumber(), true));
                  node.addAnnotation(lineNumberAnnotation);
                }

                super.visitClass(node);
              }
View Full Code Here

  public void execute(TestCodeSnippet snippet) {
    CompilerConfiguration config = new CompilerConfiguration();
    config.addCompilationCustomizers(new CompilationCustomizer(CompilePhase.CONVERSION) {
      @Override
      public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
        classNode.addAnnotation(new AnnotationNode(new ClassNode(CompileStatic.class)));
      }
    });

    ClassLoader classLoader = new URLClassLoader(new URL[]{}, getClass().getClassLoader());
    GroovyShell groovyShell = new GroovyShell(classLoader, new Binding(), config);
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.ast.AnnotationNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.