Package org.jboss.forge.project.facets

Examples of org.jboss.forge.project.facets.JavaSourceFacet


            final PipeOut out,
            @Option(required = false,
                     help = "the method definition: surround with single quotes",
                     description = "method definition") final String... def) throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

      String methodDef = null;
      if (def != null)
      {
         methodDef = Strings.join(Arrays.asList(def), " ");
      }
      else if (in != null)
      {
         methodDef = in;
      }
      else
      {
         throw new RuntimeException("arguments required");
      }

      JavaSource<?> source = resource.getJavaSource();
      if (source instanceof MethodHolder)
      {
         MethodHolder<?> clazz = ((MethodHolder<?>) source);

         Method<JavaClass> method = JavaParser.parse(JavaClass.class, "public class Temp{}").addMethod(methodDef);
         if (clazz.hasMethodSignature(method))
         {
            throw new IllegalStateException("Method with signature [" + method.toSignature()
                     + "] already exists.");
         }

         clazz.addMethod(methodDef);
         java.saveJavaSource(source);
      }
   }
View Full Code Here


            @Option(name = "type", required = false, help = "the annotation element type; use with --name", description = "annotation element type") final String type,
            @Option(required = false,
                     help = "the annotation element definition: surround with single quotes",
                     description = "annotation element definition") final String... def) throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

      String elementDef = null;
      if (def != null)
      {
         elementDef = Strings.join(Arrays.asList(def), " ");
      }
      else if (in != null)
      {
         elementDef = in;
      }
      else if (Strings.isNullOrEmpty(name) || Strings.isNullOrEmpty(type))
      {
         throw new RuntimeException("arguments required");
      }

      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

            @Option(required = false,
                     help = "the class definition: surround with quotes",
                     description = "class definition") final String... def) throws FileNotFoundException
   {

      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

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

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

      if (!jc.hasSyntaxErrors())
      {
         java.saveJavaSource(jc);
      }
      else
      {
         writer.println(ShellColor.RED, "Syntax Errors:");
         for (SyntaxError error : jc.getSyntaxErrors())
         {
            writer.println(error.toString());
         }
         writer.println();

         if (prompt.promptBoolean("Your class has syntax errors, create anyway?", true))
         {
            java.saveJavaSource(jc);
         }
      }
      pickUp.fire(new PickupResource(java.getJavaResource(jc)));
   }
View Full Code Here

            @PipeIn final InputStream in,
            @Option(required = false, help = "the package in which to build this Interface", description = "source package", type = PromptType.JAVA_PACKAGE, name = "package") final String pckg,
            @Option(required = false, help = "the interface definition: surround with quotes", description = "interface definition") final String... def)
            throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
      JavaInterface jc = null;
      if (def != null)
      {
         String classDef = Strings.join(Arrays.asList(def), " ");
         jc = JavaParser.parse(JavaInterface.class, classDef);
      }
      else if (in != null)
      {
         jc = JavaParser.parse(JavaInterface.class, in);
      }
      else
      {
         throw new RuntimeException("arguments required");
      }
      if (pckg != null)
      {
         jc.setPackage(pckg);
      }
      if (!jc.hasSyntaxErrors())
      {
         java.saveJavaSource(jc);
      }
      else
      {
         writer.println(ShellColor.RED, "Syntax Errors:");
         for (SyntaxError error : jc.getSyntaxErrors())
         {
            writer.println(error.toString());
         }
         writer.println();
         if (prompt.promptBoolean(
                  "Your class has syntax errors, create anyway?", true))
         {
            java.saveJavaSource(jc);
         }
      }
      pickUp.fire(new PickupResource(java.getJavaResource(jc)));
   }
View Full Code Here

            @Option(required = false,
                     help = "the class definition: surround with quotes",
                     description = "class definition") final String... def) throws FileNotFoundException
   {

      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

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

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

      if (!je.hasSyntaxErrors())
      {
         java.saveEnumTypeSource(je);
      }
      else
      {
         writer.println(ShellColor.RED, "Syntax Errors:");
         for (SyntaxError error : je.getSyntaxErrors())
         {
            writer.println(error.toString());
         }
         writer.println();

         if (prompt.promptBoolean("Your class has syntax errors, create anyway?", true))
         {
            java.saveEnumTypeSource(je);
         }
      }

      pickUp.fire(new PickupResource(java.getEnumTypeResource(je)));
   }
View Full Code Here

            final PipeOut out,
            @Option(required = false,
                     help = "the enum field definition",
                     description = "enum field definition") final String... def) throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

      String enumConstDef = null;
      if (def != null)
      {
         enumConstDef = Strings.join(Arrays.asList(def), " ");
      }
      else if (in != null)
      {
         enumConstDef = in;
      }
      else
      {
         throw new RuntimeException("arguments required");
      }

      JavaEnum source = (JavaEnum) resource.getJavaSource();
      source.addEnumConstant(enumConstDef);
      java.saveEnumTypeSource(source);

   }
View Full Code Here

            final PipeOut out,
            @Option(required = false,
                     help = "the field definition: surround with single quotes",
                     description = "field definition") final String... def) throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

      String fieldDef = null;
      if (def != null)
      {
         fieldDef = Strings.join(Arrays.asList(def), " ");
      }
      else if (in != null)
      {
         fieldDef = in;
      }
      else
      {
         throw new RuntimeException("arguments required");
      }

      JavaSource<?> source = resource.getJavaSource();
      if (source instanceof FieldHolder)
      {
         FieldHolder<?> clazz = ((FieldHolder<?>) source);

         String name = JavaParser.parse(JavaClass.class, "public class Temp{}").addField(fieldDef).getName();
         if (clazz.hasField(name))
         {
            throw new IllegalStateException("Field named [" + name + "] already exists.");
         }

         clazz.addField(fieldDef);
         java.saveJavaSource(source);
      }
   }
View Full Code Here

            final PipeOut out,
            @Option(required = false,
                     help = "the method definition: surround with single quotes",
                     description = "method definition") final String... def) throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

      String methodDef = null;
      if (def != null)
      {
         methodDef = Strings.join(Arrays.asList(def), " ");
      }
      else if (in != null)
      {
         methodDef = in;
      }
      else
      {
         throw new RuntimeException("arguments required");
      }

      JavaSource<?> source = resource.getJavaSource();
      if (source instanceof MethodHolder)
      {
         MethodHolder<?> clazz = ((MethodHolder<?>) source);

         Method<JavaClass> method = JavaParser.parse(JavaClass.class, "public class Temp{}").addMethod(methodDef);
         if (clazz.hasMethodSignature(method))
         {
            throw new IllegalStateException("Method with signature [" + method.toSignature()
                     + "] already exists.");
         }

         clazz.addMethod(methodDef);
         java.saveJavaSource(source);
      }
   }
View Full Code Here

   }

   @Override
   public boolean isInstalled()
   {
      JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);

      if ((classPackage == null || className == null) && !findApplicationClass())
      {
         return false;
      }

      try
      {
         JavaResource javaResource = javaSourceFacet.getJavaResource(classPackage + "." + className);
         if (javaResource.exists() || findApplicationClass())
         {
            return true;
         }
View Full Code Here

      return false;
   }

   private boolean findApplicationClass()
   {
      JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);

      configuration.clearProperty(REST_APPLICATIONCLASS_NAME);
      configuration.clearProperty(REST_APPLICATIONCLASS_PACKAGE);

      javaSourceFacet.visitJavaSources(new JavaResourceVisitor()
      {
         boolean found = false;

         @Override
         public void visit(JavaResource javaResource)
View Full Code Here

TOP

Related Classes of org.jboss.forge.project.facets.JavaSourceFacet

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.