Examples of Filer


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

            config.setLocalizedLookup(false);

            final Template template = config.getTemplate("templates/template.ftl");

            for (Type type : types) {
                final Filer filer = processingEnv.getFiler();
                final JavaFileObject file = filer.createSourceFile(type.getName().getQualified());

                try (Writer writer = file.openWriter()) {
                    //mustache.execute(writer, type).flush();
                    template.process(type, writer);
                }
View Full Code Here

Examples of javax.annotation.processing.Filer

    if (annotations.isEmpty()) {
      return true;
    }

    try {
      Filer filer = processingEnv.getFiler();
      Map<String, MessageBundleInfo> messageBundles = new HashMap<String, MessageBundleInfo>();

      for (Element e : roundEnv
          .getElementsAnnotatedWith(MessageBundle.class)) {
        if (e instanceof TypeElement) {
          TypeElement messageBundleElement = (TypeElement) e;
          String messageBundle = messageBundleElement
              .getQualifiedName().toString();
          String messageBundleSimpleName = messageBundleElement.getSimpleName().toString();
          String messageBundleEnumName = messageBundle + "Enum";
          Set<String> messages = new HashSet<String>();

          for (Element messageBundleChild : messageBundleElement
              .getEnclosedElements()) {
            if (messageBundleChild instanceof ExecutableElement) {
              messages.add(getKey((ExecutableElement) messageBundleChild));
            }
          }

          if (!messages.isEmpty()) {
            String baseName = messageBundle.replaceAll("\\.", "/");
            FileObject javaFileObject;
           
            try {
              javaFileObject = filer.getResource(
                StandardLocation.SOURCE_PATH, "", baseName
                    + ".java");
            } catch(FileNotFoundException ex) {
              throw new IllegalArgumentException("Could not find the source file '" + baseName + ".java' that actually triggered the enum generation process", ex);
            }
           
            long lastModified = javaFileObject.getLastModified();
            Set<Locale> locales = new TreeSet<Locale>(LOCALE_COMPARATOR);
            URI baseUri = null;

            // Here we assume that the resources are present in the
            // source output location

            try {
              // Normally there is an english properties file
              try {
                baseUri = filer.getResource(
                    StandardLocation.CLASS_PATH, "",
                    baseName + "_en.properties").toUri();
              } catch (FileNotFoundException ex1) {
                try {
                  baseUri = filer.getResource(
                      StandardLocation.CLASS_OUTPUT, "",
                      baseName + "_en.properties").toUri();
                } catch (FileNotFoundException ex2) {
                  baseUri = filer.getResource(
                      StandardLocation.SOURCE_PATH, "",
                      baseName + "_en.properties").toUri();
                }
              }
            } catch (FileNotFoundException ex1) {
              // Otherwise we have to go through all available
              // locales
              for (Locale l : Locale.getAvailableLocales()) {
                String path;

                try {
                  path = baseName + "_" + l.getLanguage()
                      + ".properties";
                  baseUri = filer.getResource(
                      StandardLocation.CLASS_PATH, "",
                      path).toUri();
                  break;
                } catch (FileNotFoundException ex2) {
                  try {
                    path = baseName + "_" + l.getLanguage()
                        + ".properties";
                    baseUri = filer.getResource(
                        StandardLocation.CLASS_OUTPUT, "",
                        path).toUri();
                    break;
                  } catch (FileNotFoundException ex3) {
                    try {
                      path = baseName + "_" + l.getLanguage()
                          + ".properties";
                      baseUri = filer.getResource(
                          StandardLocation.SOURCE_PATH, "",
                          path).toUri();
                      break;
                    } catch (FileNotFoundException ex4) {
                      // Nothing we can do about it
                    }
                  }
                }

                if (l.getCountry() != null
                    && !l.getCountry().isEmpty()) {


                  try {
                    path = baseName + "_" + l.getLanguage()
                        + "_" + l.getCountry()
                        + ".properties";
                    baseUri = filer.getResource(
                        StandardLocation.CLASS_PATH,
                        "", path).toUri();
                    break;
                  } catch (FileNotFoundException ex2) {
                    try {
                      path = baseName + "_" + l.getLanguage()
                          + "_" + l.getCountry()
                          + ".properties";
                      baseUri = filer.getResource(
                          StandardLocation.CLASS_OUTPUT,
                          "", path).toUri();
                      break;
                    } catch (FileNotFoundException ex3) {
                      try {
                        path = baseName + "_" + l.getLanguage()
                            + "_" + l.getCountry()
                            + ".properties";
                        baseUri = filer.getResource(
                            StandardLocation.SOURCE_PATH,
                            "", path).toUri();
                        break;
                      } catch (FileNotFoundException ex4) {
                        // Nothing we can do about it
                      }
                    }
                  }
                }
              }
            }

            if (baseUri == null) {
              throw new IllegalArgumentException(
                  "No properties files could be found for '"
                      + messageBundle + "'");
            }

            File baseDir = new File(baseUri).getParentFile();
           
            if(!baseDir.exists() || !baseDir.isDirectory()) {
              throw new IllegalArgumentException("The base directory for the properties files could not be found!");
            }

            for (File propertiesFile : baseDir.listFiles()) {
                // Only check properties files that belong to the message bundle
                if(propertiesFile.getName().startsWith(messageBundleSimpleName + "_") || propertiesFile.getName().equals(messageBundleSimpleName + ".properties")) {
                  checkPropertiesFile(propertiesFile, messages);
                  String name = propertiesFile.getName();
                  int index = name.indexOf('_');
                  int dotIndex = name.lastIndexOf('.');
   
                  if (index > -1 && dotIndex > -1) {
                    locales.add(LocaleUtils.getLocale(name
                        .substring(index + 1, dotIndex)));
                  }
                }
            }

            MessageBundleInfo info = new MessageBundleInfo(
                baseName, lastModified, locales, messages);
            messageBundles.put(messageBundleEnumName, info);
          }
        }
      }

      for (Map.Entry<String, MessageBundleInfo> entry : messageBundles
          .entrySet()) {
        String className = entry.getKey();
        JavaFileObject jfo = filer.createSourceFile(className);

        if (jfo.getLastModified() == entry.getValue().getLastModified()) {
          // Skip unchanged files
          continue;
        }
View Full Code Here

Examples of javax.annotation.processing.Filer

{

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

        Elements elementUtils = processingEnv.getElementUtils();

        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith( SimpleAnnotation.class );

        for ( Element element : elements )
        {
            Name name = element.getSimpleName();

            PackageElement packageElement = elementUtils.getPackageOf( element );

            try
            {
                FileObject resource =
                    filer.createResource( StandardLocation.SOURCE_OUTPUT, packageElement.getQualifiedName(), name
                        + ".txt", element );

                Writer writer = resource.openWriter();
                writer.write( name.toString() );
                writer.close();
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

Examples of javax.annotation.processing.Filer

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
      if (roundEnv.processingOver()) {
        try {
          Filer filer = processingEnv.getFiler();
          FileObject o = filer.getResource(location, key.packageFQN, key.name);
          result = o.getCharContent(false);
        }
        catch (IOException e) {
          result = e;
        }
View Full Code Here

Examples of javax.annotation.processing.Filer

      }

      //
      if (!done) {
        try {
          Filer filer = processingEnv.getFiler();
          JavaFileObject b = filer.createSourceFile("compiler.processor.B");
          PrintWriter writer = new PrintWriter(b.openWriter());
          writer.println("package compiler.processor; public class B { }");
          writer.close();
          done = true;
        }
View Full Code Here

Examples of javax.annotation.processing.Filer

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
      if (!done) {

        try {
          Filer filer = processingEnv.getFiler();
          FileObject foo = filer.getResource(StandardLocation.CLASS_OUTPUT, "", "foo.txt");
          deleted = foo.delete();
          done = true;
        }
        catch (IOException e) {
          e.printStackTrace();
View Full Code Here

Examples of javax.annotation.processing.Filer

    if (key == null) {
      throw new NullPointerException("No null path accepted");
    }
    try {
      log.info("Attempt to resolve " + key + " from classpath");
      Filer classPath = env.getFiler();
      FileObject object = classPath.getResource(StandardLocation.CLASS_PATH, key.packageFQN, key.name);
      if (object != null && object.getLastModified() > 0) {
        return object;
      }
    }
    catch (IOException e) {
View Full Code Here

Examples of javax.annotation.processing.Filer

     */
    protected void processFile(String packageName, 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
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.