Package javax.tools

Examples of javax.tools.JavaFileManager


        DiagnosticCollector<JavaFileObject> diagnostics =
                new DiagnosticCollector<JavaFileObject>();

        //the generated bytecode is fed to the class loader
        JavaFileManager jfm = new
                ForwardingJavaFileManager<StandardJavaFileManager>(
                        compiler.getStandardFileManager(diagnostics, null, null)) {

                    @Override
                    public JavaFileObject getJavaFileForOutput(Location location,
View Full Code Here


            units.add(new CompilationUnit(sourcePath, pReader));
        }

        final JavaCompilerTool compiler = ToolProvider.getSystemJavaCompilerTool();
//        final JavaFileManager fileManager = compiler.getStandardFileManager(diagnostics);
        final JavaFileManager fileManager = new JciJavaFileManager(units, pStore);
        final DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();


        compiler.getTask(null, fileManager, diagnostics, null, null, units).run();

        try {
            fileManager.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
View Full Code Here

      c = Class.forName("org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl"); //$NON-NLS-1$
    } catch (ClassNotFoundException e) {
      // ignore
    }
    Field field = null;
    JavaFileManager javaFileManager = null;
    if (c != null) {
      try {
        field = c.getField("fileManager"); //$NON-NLS-1$
      } catch (SecurityException e) {
        // ignore
      } catch (IllegalArgumentException e) {
        // ignore
      } catch (NoSuchFieldException e) {
        // ignore
      }
    }
    if (field != null) {
      try {
        javaFileManager = (JavaFileManager) field.get(batchCompiler);
      } catch (IllegalArgumentException e) {
        // ignore
      } catch (IllegalAccessException e) {
        // ignore
      }
    }
    if (javaFileManager != null) {
      _fileManager = javaFileManager;
    } else {
      String encoding = (String) batchCompiler.options.get(CompilerOptions.OPTION_Encoding);
      Charset charset = encoding != null ? Charset.forName(encoding) : null;
      JavaFileManager manager = new EclipseFileManager(batchCompiler.compilerLocale, charset);
      ArrayList<String> options = new ArrayList<String>();
      for (String argument : commandLineArguments) {
        options.add(argument);
      }
      for (Iterator<String> iterator = options.iterator(); iterator.hasNext(); ) {
        manager.handleOption(iterator.next(), iterator);
      }
      _fileManager = manager;
    }
    _processorOptions = Collections.unmodifiableMap(parseProcessorOptions(commandLineArguments));
    _filer = new BatchFilerImpl(_dispatchManager, this);
View Full Code Here

      c = Class.forName("org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl"); //$NON-NLS-1$
    } catch (ClassNotFoundException e) {
      // ignore
    }
    Field field = null;
    JavaFileManager javaFileManager = null;
    if (c != null) {
      try {
        field = c.getField("fileManager"); //$NON-NLS-1$
      } catch (SecurityException e) {
        // ignore
      } catch (IllegalArgumentException e) {
        // ignore
      } catch (NoSuchFieldException e) {
        // ignore
      }
    }
    if (field != null) {
      try {
        javaFileManager = (JavaFileManager) field.get(batchCompiler);
      } catch (IllegalArgumentException e) {
        // ignore
      } catch (IllegalAccessException e) {
        // ignore
      }
    }
    if (javaFileManager != null) {
      _fileManager = javaFileManager;
    } else {
      String encoding = (String) batchCompiler.options.get(CompilerOptions.OPTION_Encoding);
      Charset charset = encoding != null ? Charset.forName(encoding) : null;
      JavaFileManager manager = new EclipseFileManager(batchCompiler.compilerLocale, charset);
      ArrayList<String> options = new ArrayList<String>();
      for (String argument : commandLineArguments) {
        options.add(argument);
      }
      for (Iterator<String> iterator = options.iterator(); iterator.hasNext(); ) {
        manager.handleOption(iterator.next(), iterator);
      }
      _fileManager = manager;
    }
    _processorOptions = Collections.unmodifiableMap(parseProcessorOptions(commandLineArguments));
    _filer = new BatchFilerImpl(_dispatchManager, this);
View Full Code Here

        try {
            stdFileManager.setLocation(StandardLocation.CLASS_PATH, this.cpath);
        } catch (IOException e) {
        }

        JavaFileManager javaFileManager = getJavaFileManager(stdFileManager);
        javax.tools.JavaCompiler.CompilationTask ct =
            javac.getTask(null,
                          javaFileManager,
                          diagnostics,
                          options,
                          null,
                          Arrays.asList(sourceFiles));

        try {
            javaFileManager.close();
        } catch (IOException ex) {
        }

        if (ct.call()) {
            for (BytecodeFile bytecodeFile: classFiles) {
View Full Code Here

    }
  }
 
  public static JavaFileManager getStringSourceJavaFileManager(JavaCompiler compiler, DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) {
   
    JavaFileManager fileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(compiler.getStandardFileManager(diagnosticListener, locale,charset)) {
      @Override
      public JavaFileObject getJavaFileForOutput(Location location,
          String className, Kind kind, FileObject sibling)
          throws IOException {
        JavaFileObject jfo = new ByteJavaObject(className, kind);
View Full Code Here

            + "return \"world\";"
            + "}"
        + "}";

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileManager fileManager = CompilerUtils.getStringSourceJavaFileManager(compiler, null, null, Charset.forName("UTF-8"));
    boolean result = false;
    try {
      CompilationTask task = compiler.getTask(null, fileManager, null, null, null,Arrays.asList(new JavaSourceFromString("com.test.Say", source)));
      result = task.call();
    } finally {
      fileManager.close();
    }

    if (!result)
      return;
View Full Code Here

          会判断是不是Factory的实例,是,再用相应的实例替换掉Factory
          */
            public JavaFileManager make() {
                //return new JavacFileManager(context, true, null);
              DEBUG.P(this,"make()");
                JavaFileManager myJavaFileManager=new JavacFileManager(context, true, null);
                DEBUG.P(0,this,"make()");
                return myJavaFileManager;
            }
            //我加上的
            //public String toString() {
View Full Code Here

            FSInfo fsInfo = context.get(FSInfo.class);
            if (fsInfo != null)
                next.put(FSInfo.class, fsInfo);

            JavaFileManager jfm = context.get(JavaFileManager.class);
            Assert.checkNonNull(jfm);
            next.put(JavaFileManager.class, jfm);
            if (jfm instanceof JavacFileManager) {
                ((JavacFileManager)jfm).setContext(next);
            }
View Full Code Here

            }
        } else if (processors != null) {
            processorIterator = processors.iterator();
        } else {
            String processorNames = options.get(PROCESSOR);
            JavaFileManager fileManager = context.get(JavaFileManager.class);
            try {
                // If processorpath is not explicitly set, use the classpath.
                processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
                    ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
                    : fileManager.getClassLoader(CLASS_PATH);

                /*
                 * If the "-processor" option is used, search the appropriate
                 * path for the named class.  Otherwise, use a service
                 * provider mechanism to create the processor iterator.
View Full Code Here

TOP

Related Classes of javax.tools.JavaFileManager

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.