Package org.jboss.forge.parser.java

Examples of org.jboss.forge.parser.java.JavaAnnotation


            member.setDefault(null);
         }
         else
         {
            String stub = "public @interface Stub { String stub() default " + value + "; }";
            JavaAnnotation temp = (JavaAnnotation) JavaParser.parse(stub);
            AnnotationTypeMemberDeclaration internal = (AnnotationTypeMemberDeclaration) temp.getAnnotationElements()
                     .get(0).getInternal();
            member.setDefault((Expression) ASTNode.copySubtree(ast, internal.getDefault()));
         }
         return this;
      }
View Full Code Here


                     help = "the annotation definition: surround with quotes",
                     description = "annotation definition") final String... def) throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

      JavaAnnotation type = null;
      if (def != null)
      {
         String classDef = Strings.join(Arrays.asList(def), " ");
         type = JavaParser.parse(JavaAnnotation.class, classDef);
      }
      else if (in != null)
      {
         type = JavaParser.parse(JavaAnnotation.class, in);
      }
      else
      {
         throw new RuntimeException("arguments required");
      }

      if (pckg != null)
      {
         type.setPackage(pckg);
      }

      if (documented)
      {
         type.addAnnotation(Documented.class);
      }
      if (retentionPolicy != null)
      {
         type.addAnnotation(Retention.class).setEnumValue(retentionPolicy);
      }
      if (!type.hasSyntaxErrors())
      {
         java.saveJavaSource(type);
      }
      else
      {
         writer.println(ShellColor.RED, "Syntax Errors:");
         for (SyntaxError error : type.getSyntaxErrors())
         {
            writer.println(error.toString());
         }
         writer.println();
View Full Code Here

      }

      JavaSource<?> source = resource.getJavaSource();
      if (source.isAnnotation())
      {
         JavaAnnotation parent = JavaAnnotation.class.cast(source);

         String addName;
         if (elementDef != null)
         {
            addName = JavaParser.parse(JavaAnnotation.class, "public @interface Temp{}").addAnnotationElement(elementDef).getName();
         }
         else
         {
            addName = name;
         }

         if (parent.hasAnnotationElement(addName))
         {
            throw new IllegalStateException("Element named [" + addName + "] already exists.");
         }

         if (elementDef != null)
         {
            parent.addAnnotationElement(elementDef);
         }
         else
         {
            parent.addAnnotationElement().setName(name).setType(type);
         }
         java.saveJavaSource(source);
      }
   }
View Full Code Here

         throw new RuntimeException("Type already exists [" + resource.getFullyQualifiedName()
                  + "] Re-run with '--overwrite' to continue.");
      }

      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
      JavaAnnotation qualifier = JavaParser.create(JavaAnnotation.class);
      qualifier.setName(java.calculateName(resource));
      qualifier.setPackage(java.calculatePackage(resource));
      qualifier.addAnnotation(Qualifier.class);
      if (inherited)
      {
         qualifier.addAnnotation(Inherited.class);
      }
      qualifier.addAnnotation(Retention.class).setEnumValue(RUNTIME);
      qualifier.addAnnotation(Target.class).setEnumValue(METHOD, FIELD, PARAMETER, TYPE);
      qualifier.addAnnotation(Documented.class);

      java.saveJavaSource(qualifier);
      pickup.fire(new PickupResource(java.getJavaResource(qualifier)));
   }
View Full Code Here

      {
         throw new RuntimeException("Type already exists [" + resource.getFullyQualifiedName()
                  + "] Re-run with '--overwrite' to continue.");
      }
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
      JavaAnnotation stereotype = JavaParser.create(JavaAnnotation.class);
      stereotype.setName(java.calculateName(resource));
      stereotype.setPackage(java.calculatePackage(resource));
      stereotype.addAnnotation(Stereotype.class);
      if (inherited)
      {
         stereotype.addAnnotation(Inherited.class);
      }
      if (named)
      {
         stereotype.addAnnotation(Named.class);
      }
      if (alternative)
      {
         stereotype.addAnnotation(Alternative.class);
      }
      stereotype.addAnnotation(Retention.class).setEnumValue(RUNTIME);

      final Set<ElementType> targetTypes;
      if (allTargets)
      {
         targetTypes = STEREOTYPE_TARGETS;
      }
      else
      {
         Set<ElementType> input;
         while (true)
         {
            input = shell.promptMultiSelect("Select target element types", STEREOTYPE_TARGETS);
            if (input.isEmpty())
            {
               ShellMessages.error(shell, "No target element types selected");
               continue;
            }
            if (input.contains(TYPE) && input.size() == 2)
            {
               ShellMessages.error(shell, "Invalid combination of target element types: " + input);
               continue;
            }
            break;
         }
         targetTypes = input;
      }

      stereotype.addAnnotation(Target.class).setEnumValue(targetTypes.toArray(new ElementType[targetTypes.size()]));
      stereotype.addAnnotation(Documented.class);

      java.saveJavaSource(stereotype);
      pickup.fire(new PickupResource(java.getJavaResource(stereotype)));
   }
View Full Code Here

         throw new RuntimeException("Type already exists [" + resource.getFullyQualifiedName()
                  + "] Re-run with '--overwrite' to continue.");
      }

      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
      JavaAnnotation scope = JavaParser.create(JavaAnnotation.class);
      scope.setName(java.calculateName(resource));
      scope.setPackage(java.calculatePackage(resource));

      if (pseudo)
      {
         scope.addAnnotation(Scope.class);
      }
      else
      {
         Annotation<JavaAnnotation> normalScope = scope.addAnnotation(NormalScope.class);
         if (passivating)
         {
            normalScope.setLiteralValue("passivating", Boolean.toString(true));
         }
      }
      scope.addAnnotation(Retention.class).setEnumValue(RUNTIME);
      scope.addAnnotation(Target.class).setEnumValue(TYPE, METHOD, FIELD);
      scope.addAnnotation(Documented.class);

      java.saveJavaSource(scope);
      pickup.fire(new PickupResource(java.getJavaResource(scope)));
   }
View Full Code Here

TOP

Related Classes of org.jboss.forge.parser.java.JavaAnnotation

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.