Package javax.tools

Examples of javax.tools.JavaFileObject.openWriter()


    }

    public void writeTo(String className) {
      try {
        JavaFileObject jfo = filer.createSourceFile(className, (Element[]) null);
        Writer w = jfo.openWriter();
        w.write(p.toString());
        //在com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing中会调用filer.warnIfUnclosedFiles()
        //所以必需要close,否则JavacProcessingEnvironment会出错
        w.close();
      } catch (IOException e) {
View Full Code Here


                                               null);
        if (inputFiles.contains(outFile)) {
            log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile);
            return null;
        } else {
            BufferedWriter out = new BufferedWriter(outFile.openWriter());
            try {
                new Pretty(out, true).printUnit(env.toplevel, cdef);
                if (verbose)
                    log.printVerbose("wrote.file", outFile);
            } finally {
View Full Code Here

        }
        if (elements.isEmpty() == false) {
            try {
                JavaFileObject file =
                    processingEnv.getFiler().createSourceFile("Generated");
                Writer writer = file.openWriter();
                PrintWriter pw = new PrintWriter(writer);
                pw.println("public class Generated {");
                pw.println("    public static final String[] ELEMENTS = {");
                for (Element element : elements) {
                    pw.println("        \"" + element.getSimpleName() + "\",");
View Full Code Here

            name.append("package-info");
        } else {
            name.append(primary.getName());
        }
        JavaFileObject source = filer.createSourceFile(name, originatingElements);
        Writer writer = source.openWriter();
        try {
            PrintWriter output = new PrintWriter(writer);
            Models.emit(unit, output);
            output.close();
        } finally {
View Full Code Here

                }
                replace(body, "$PROPERTIES$", properties.toString());
                try {
                    JavaFileObject f = processingEnv.getFiler().
                            createSourceFile(dockPackage + "." + dockShortName);
                    Writer w = f.openWriter();
                    PrintWriter pw = new PrintWriter(w);
                    pw.print(body);
                    pw.flush();
                    pw.close();
                } catch (IOException ex) {
View Full Code Here

 
  private void generateSourceFile(FactoryModel model) {
    try {
      String factoryName = model.declaration.getQualifiedName() + "Impl";
      JavaFileObject src = filer.createSourceFile(factoryName, model.declaration);
      PrintWriter writer = new PrintWriter(src.openWriter());
      writer.println(formatter.generate(model));
      writer.flush();
      writer.close();
    } catch (IOException e) {
      messager.printMessage(Kind.ERROR, e.getMessage(), model.declaration);
View Full Code Here

     */
    private PrintWriter createSourceFile(String originalClass, String metaClass, TypeElement e)
        throws IOException {
        JavaFileObject javaFile = processingEnv.getFiler().createSourceFile(metaClass, e);
        logger.info(_loc.get("mmg-process", javaFile.toUri().normalize()));
        return new PrintWriter(javaFile.openWriter());
    }
   
    /**
     * Get the value for the given keys, whoever matches first, in the current available options.
     */
 
View Full Code Here

     */
    private PrintWriter createSourceFile(String originalClass, String metaClass, TypeElement e)
        throws IOException {
        JavaFileObject javaFile = processingEnv.getFiler().createSourceFile(metaClass, e);
        logger.info(_loc.get("mmg-process", javaFile.toUri().normalize()));
        return new PrintWriter(javaFile.openWriter());
    }
   
    /**
     * Get the value for the given keys, whoever matches first, in the current available options.
     */
 
View Full Code Here

     */
    private PrintWriter createSourceFile(String originalClass, String metaClass, TypeElement e)
        throws IOException {
        JavaFileObject javaFile = processingEnv.getFiler().createSourceFile(metaClass, e);
        logger.info(_loc.get("mmg-process", javaFile.toUri().normalize()));
        return new PrintWriter(javaFile.openWriter());
    }
   
    /**
     * Get the value for the given keys, whoever matches first, in the current available options.
     */
 
View Full Code Here

   public void write(final String data) {
     Writer writer = null;
     try {
       clearOldVersions(packageName, className);
       JavaFileObject file = processingEnv.getFiler().createSourceFile(packageName + "." + className);
       writer = file.openWriter();
       writer.append(data).flush();
     } catch (IOException e) {
       throw new IllegalStateException(e);
     } finally {
       if (writer != null) {
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.