Examples of Filer


Examples of javax.annotation.processing.Filer

     */
    protected void processFile(String packageName, String scheme, String fileName, Func1<PrintWriter, Void> handler) {
        PrintWriter writer = null;
        try {
            Writer out = null;
            Filer filer = processingEnv.getFiler();
            FileObject resource;
            try {
                resource = filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, fileName);
            } catch (Throwable e) {
                //resource = filer.createResource(StandardLocation.CLASS_OUTPUT, "org.apache.camel", "CamelAPT2.txt", rootElements.toArray(new Element[rootElements.size()]));
                resource = filer.createResource(StandardLocation.CLASS_OUTPUT, packageName, fileName, new Element[0]);
            }
            URI uri = resource.toUri();
            File file = null;
            if (uri != null) {
                try {
View Full Code Here

Examples of javax.annotation.processing.Filer

        {

            return true;
        }

        Filer filer = processingEnv.getFiler();

        try
        {

            for (Element e : roundEnv.getElementsAnnotatedWith(SystemConfigFactoryConstructor.class))
View Full Code Here

Examples of javax.annotation.processing.Filer

        {

            return true;
        }

        Filer filer = processingEnv.getFiler();

        try
        {

            for (Element e : roundEnv.getElementsAnnotatedWith(ManagedObjectFactoryConstructor.class))
View Full Code Here

Examples of javax.annotation.processing.Filer

                            + GenerateRepositoryAndTableResource.class.getSimpleName()
                            + " annotation is missing a javax.ws.rs.Path annotation: " + element.toString());
                }
                String jaxRsPath = pathAnnotation.value();

                Filer filer = processingEnv.getFiler();
                String packageName = element.getEnclosingElement().toString();
                String className = element.getSimpleName().toString();

                generators.get(annotation.getQualifiedName().toString())
                        .generateResourceClass(packageName, className, jaxRsPath, filer);
View Full Code Here

Examples of javax.annotation.processing.Filer

   private final Properties all = new Properties();

   @Override
   public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
   {
      Filer filer = processingEnv.getFiler();

      //
      if (roundEnv.processingOver())
      {
         // Testsuite
         try
         {
            FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "suite.properties");
            OutputStream out = file.openOutputStream();
            all.store(out, null);
            out.close();
         }
         catch (IOException e)
         {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create test case for package " + e.getMessage());
         }
      }

      //
      reporter.process(annotations, roundEnv);

      //
      Map<PackageElement, List<TypeElement>> map = new HashMap<PackageElement, List<TypeElement>>();
      for (Element annotated : roundEnv.getElementsAnnotatedWith(TestCase.class))
      {
         TestCase tc = annotated.getAnnotation(TestCase.class);
         if (tc.enabled())
         {
            if (annotated instanceof TypeElement)
            {
               PackageElement pkg = processingEnv.getElementUtils().getPackageOf(annotated);
               List<TypeElement> types = map.get(pkg);
               if (types == null)
               {
                  map.put(pkg, types = new ArrayList<TypeElement>());
               }
               types.add((TypeElement)annotated);
            }
         }
      }

      // Generate tests
      for (Map.Entry<PackageElement, List<TypeElement>> entry : map.entrySet())
      {
         PackageElement pkg = entry.getKey();
         Matcher m = P.matcher(pkg.getQualifiedName());
         if (m.matches())
         {
            String version = m.group(1);
            String type = m.group(2);
            String suite = m.group(3);
            String testPkg = version + '.' + type + '.' + suite;

            //
            ClassLoader old = Thread.currentThread().getContextClassLoader();
            try
            {
               Thread.currentThread().setContextClassLoader(WebArchive.class.getClassLoader());
               WebArchive archive = AbstractWarTestCase.createDeployment(version,  type, suite);
               FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT, testPkg, "suite.war");
               OutputStream out = file.openOutputStream();
               archive.as(ZipExporter.class).exportTo(out);
               out.close();
            }
            catch (Exception e)
            {
               processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create war file for package " + e.getMessage(), pkg);
            }
            finally
            {
               Thread.currentThread().setContextClassLoader(old);
            }

            // Suite properties
            try
            {
               FileObject file = filer.createResource(StandardLocation.CLASS_OUTPUT, testPkg, "suite.properties");
               OutputStream out = file.openOutputStream();
               Properties props = new Properties();
               for (TypeElement annotated : entry.getValue())
               {
                  props.put(annotated.getQualifiedName().toString(), "testcase");
               }
               props.store(out, null);
               out.close();
            }
            catch (IOException e)
            {
               processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create test case for package " + e.getMessage(), pkg);
            }

            // Ear test cases
            for (TypeElement annotated : entry.getValue())
            {
               String name = annotated.getSimpleName().toString();
               try
               {
                  String baseFQN = testPkg + "." + name;

                  //
                  all.put(baseFQN, "fqn");

                  //
                  JavaFileObject file = filer.createSourceFile(baseFQN + "EarTestCase");
                  PrintWriter writer = new PrintWriter(file.openWriter());

                  // Package
                  writer.append("package ").append(testPkg).println(";");

                  // Open class
                  writer.append('@').append(RunWith.class.getName()).append('(').append(Arquillian.class.getName()).println(".class)");
                  writer.append("public class ").append(name).println("EarTestCase extends org.gatein.pc.test.unit.AbstractEarTestCase {");

                  // List of deployments
                  List<String[]> deployments = new ArrayList<String[]>();

                  // Add implicit deployment
                  deployments.add(new String[]{version,type,suite});

                  // Additional deployment
                  TestCase annotation = annotated.getAnnotation(TestCase.class);
                  for (Archive deployment : annotation.deployments())
                  {
                     deployments.add(deployment.value());
                  }

                  //
                  writer.append('@').append(Deployment.class.getName()).append("(name = \"deployment").println("\", testable = false)");
                  writer.append("public static ").append(EnterpriseArchive.class.getName()).append(" createDeployment").println("() throws Exception {");
                  writer.append("return ").append(AbstractEarTestCase.class.getName()).append(".createDeployment(");
                  for (int i = 0;i < deployments.size();i++)
                  {
                     if (i > 0)
                     {
                        writer.append(',');
                     }
                     writer.append("new String[]{");
                     String[] deployment = deployments.get(i);
                     for (int j = 0;j < deployment.length;j++)
                     {
                        if (j > 0)
                        {
                           writer.append(',');
                        }
                        writer.append('"').append(deployment[j]).append('"');
                     }
                     writer.append("}");
                  }
                  writer.println(");");
                  writer.println("}");

                  // Constructor
                  writer.append("public ").append(name).println("EarTestCase() {");
                  writer.append("super(\"").append(version).append("\",\"").append(type).append("\",\"").append(suite).append("").append("\",\"").append(name).println("\");");
                  writer.println("}");

                  // URL
                  writer.append('@').append(ArquillianResource.class.getName()).append("(").append(PortalTestServlet.class.getName()).println(".class)");
                  writer.println("java.net.URL deploymentURL;");
                  writer.println("protected java.net.URL getBaseURL() {");
                  writer.println("return deploymentURL;");
                  writer.println("}");

                  // Close class
                  writer.println("}");

                  // Close writer
                  writer.close();
               }
               catch (IOException e)
               {
                  processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not create test case for package " + e.getMessage(), pkg);
               }
            }

            // War test cases
            for (TypeElement annotated : entry.getValue())
            {
               String name = annotated.getSimpleName().toString();
               try
               {
                  JavaFileObject file = filer.createSourceFile(testPkg + "." + name + "WarTestCase");
                  PrintWriter writer = new PrintWriter(file.openWriter());

                  // Package
                  writer.append("package ").append(testPkg).println(";");
View Full Code Here

Examples of javax.annotation.processing.Filer

@SupportedAnnotationTypes("TestMe")
public class T6413690 extends AbstractProcessor {
    public boolean process(Set<? extends TypeElement> annotations,
                           RoundEnvironment roundEnvironment) {
        Elements elements = processingEnv.getElementUtils();
        Filer filer = processingEnv.getFiler();
        TypeElement testMe = elements.getTypeElement(TestMe.class.getName());
        Set<? extends Element> supers = roundEnvironment.getElementsAnnotatedWith(testMe);
        try {
            for (Element sup : supers) {
                Writer sub = filer.createSourceFile(sup.getSimpleName() + "_GENERATED").openWriter();
                sub.write(String.format("class %s_GENERATED extends %s {}",
                                        sup.getSimpleName(),
                                        ((TypeElement)sup).getQualifiedName()));
                sub.close();
            }
View Full Code Here

Examples of javax.annotation.processing.Filer

                        elementList.add(target);
                    }
                }
            }

            Filer filer = processingEnv.getFiler();

            JAXBContext context = JAXBContext.newInstance(MountPoint.class);
            MountPoint mountPoint = readExistingData(filer, context);

            FileObject file = createXmlFile(filer, messager, elementList);
View Full Code Here

Examples of javax.annotation.processing.Filer

      providers.put(providerTypeName, providerImplementerName);
    }
  }

  private void generateConfigFiles() {
    Filer filer = processingEnv.getFiler();

    for (String providerInterface : providers.keySet()) {
      String resourceFile = "META-INF/services/" + providerInterface;
      log("Working on resource file: " + resourceFile);
      try {
        SortedSet<String> allServices = Sets.newTreeSet();
        try {
          // would like to be able to print the full path
          // before we attempt to get the resource in case the behavior
          // of filer.getResource does change to match the spec, but there's
          // no good way to resolve CLASS_OUTPUT without first getting a resource.
          FileObject existingFile = filer.getResource(StandardLocation.CLASS_OUTPUT, "",
              resourceFile);
          log("Looking for existing resource file at " + existingFile.toUri());
          Set<String> oldServices = ServicesFiles.readServiceFile(existingFile.openInputStream());
          log("Existing service entries: " + oldServices);
          allServices.addAll(oldServices);
        } catch (IOException e) {
          // According to the javadoc, Filer.getResource throws an exception
          // if the file doesn't already exist.  In practice this doesn't
          // appear to be the case.  Filer.getResource will happily return a
          // FileObject that refers to a non-existent file but will throw
          // IOException if you try to open an input stream for it.
          log("Resource file did not already exist.");
        }

        Set<String> newServices = new HashSet<String>(providers.get(providerInterface));
        if (allServices.containsAll(newServices)) {
          log("No new service entries being added.");
          return;
        }

        allServices.addAll(newServices);
        log("New service file contents: " + allServices);
        FileObject fileObject = filer.createResource(StandardLocation.CLASS_OUTPUT, "",
            resourceFile);
        OutputStream out = fileObject.openOutputStream();
        ServicesFiles.writeServiceFile(allServices, out);
        out.close();
        log("Wrote to: " + fileObject.toUri());
View Full Code Here

Examples of javax.annotation.processing.Filer

  @Override
  public boolean process(Set<? extends TypeElement> type, RoundEnvironment env) {

    Elements elementUtils = processingEnv.getElementUtils();
    Types typeUtils = processingEnv.getTypeUtils();
    Filer filer = processingEnv.getFiler();
    TypeElement fragmentType = elementUtils.getTypeElement("android.app.Fragment");
    TypeElement supportFragmentType =
        elementUtils.getTypeElement("android.support.v4.app.Fragment");
    Map<TypeElement, Set<Element>> fieldsByType = new HashMap<TypeElement, Set<Element>>(100);

    Element[] origHelper = null;

    for (Element element : env.getElementsAnnotatedWith(Arg.class)) {
      TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();

      // Check if its a fragment
      if (!((fragmentType != null && typeUtils.isSubtype(enclosingElement.asType(),
          fragmentType.asType())) || (supportFragmentType != null && typeUtils.isSubtype(
          enclosingElement.asType(), supportFragmentType.asType())))) {
        error(element, "@Arg can only be used on fragment fields (%s.%s)",
            enclosingElement.getQualifiedName(), element);
        continue;
      }

      if (element.getModifiers().contains(Modifier.FINAL) || element.getModifiers()
          .contains(Modifier.STATIC) || element.getModifiers().contains(Modifier.PRIVATE) || element
          .getModifiers()
          .contains(Modifier.PROTECTED)) {
        error(element, "@Arg fields must not be private, protected, final or static (%s.%s)",
            enclosingElement.getQualifiedName(), element);
        continue;
      }

      Set<Element> fields = fieldsByType.get(enclosingElement);
      if (fields == null) {
        fields = new LinkedHashSet<Element>(10);
        fieldsByType.put(enclosingElement, fields);
      }
      fields.add(element);
    }

    // Store the key - value for the generated FragmentArtMap class
    Map<String, String> autoMapping = new HashMap<String, String>();

    for (Map.Entry<TypeElement, Set<Element>> entry : fieldsByType.entrySet()) {
      try {
        // Skip abstract classes
        if (entry.getKey().getModifiers().contains(Modifier.ABSTRACT)) {
          continue;
        }

        String builder = entry.getKey().getSimpleName() + "Builder";
        List<Element> originating = new ArrayList<Element>(10);
        originating.add(entry.getKey());
        TypeMirror superClass = entry.getKey().getSuperclass();
        while (superClass.getKind() != TypeKind.NONE) {
          TypeElement element = (TypeElement) typeUtils.asElement(superClass);
          if (element.getQualifiedName().toString().startsWith("android.")) {
            break;
          }
          originating.add(element);
          superClass = element.getSuperclass();
        }

        String qualifiedFragmentName = entry.getKey().getQualifiedName().toString();
        String qualifiedBuilderName = qualifiedFragmentName + "Builder";

        Element[] orig = originating.toArray(new Element[originating.size()]);
        origHelper = orig;
        JavaFileObject jfo = filer.createSourceFile(qualifiedBuilderName, orig);
        Writer writer = jfo.openWriter();
        JavaWriter jw = new JavaWriter(writer);
        writePackage(jw, entry.getKey());
        jw.emitImports("android.os.Bundle");
        jw.beginType(builder, "class", EnumSet.of(Modifier.PUBLIC, Modifier.FINAL));
View Full Code Here

Examples of javax.annotation.processing.Filer

            final MustacheFactory factory = new DefaultMustacheFactory();
            final Mustache mustache = factory.compile("templates/template.mustache");

            try {
                final Filer filer = processingEnv.getFiler();
                final JavaFileObject file = filer.createSourceFile(type.getName().getQualified());

                try (Writer writer = file.openWriter()) {
                    mustache.execute(writer, type).flush();
                }
            } catch (IOException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.