Package javax.tools

Examples of javax.tools.JavaFileManager


        platformAnnotations.add("java.lang.annotation.Target");
        return Collections.unmodifiableSet(platformAnnotations);
    }

    private void initProcessorClassLoader() {
        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 (processorClassLoader != null && processorClassLoader instanceof Closeable) {
                JavaCompiler compiler = JavaCompiler.instance(context);
                compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader);
            }
View Full Code Here


     *
     * @param key The resource key to use to log an error message
     * @param e   If non-null, pass this exception to Abort
     */
    private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) {
        JavaFileManager fileManager = context.get(JavaFileManager.class);

        if (fileManager instanceof JavacFileManager) {
            StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
            Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
                ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
                : standardFileManager.getLocation(CLASS_PATH);

            if (needClassLoader(options.get(PROCESSOR), workingPath) )
                handleException(key, e);
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

            e.printStackTrace(System.err);
            exit();
        }


        JavaFileManager fileManager = context.get(JavaFileManager.class);
        setDocletInvoker(docletClass, fileManager, argv);

        compOpts = Options.instance(context);
        // Make sure no obsolete source/target messages are reported
        compOpts.put("-Xlint:-options", "-Xlint:-options");
View Full Code Here

    }

    // Don't spray files in random locations
    File tempFile = File.createTempFile(RfValidatorTest.class.getSimpleName(), ".jar");
    tempFile.deleteOnExit();
    JavaFileManager fileManager =
        new ValidationTool.JarOrDirectoryOutputFileManager(tempFile, compiler
            .getStandardFileManager(null, null, null));

    List<JavaFileObject> files = new ArrayList<JavaFileObject>(classes.length);
    for (Class<?> clazz : classes) {
View Full Code Here

            System.err.println("Invalid arg length " + args.length);
            System.exit(-1);
        }
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null);
        JavaFileManager fileManager = new CustomJavaFileManager(stdFileManager);
        System.out.println(new File(args[0]).getAbsolutePath());
        System.out.println(compiler.getTask(null, fileManager, null, null, null,
                                            stdFileManager.getJavaFileObjects(args[0])).call());
    }
View Full Code Here

     * configuration.
     */
    static synchronized DocFileFactory getFactory(Configuration configuration) {
        DocFileFactory f = factories.get(configuration);
        if (f == null) {
            JavaFileManager fm = configuration.getFileManager();
            if (fm instanceof StandardJavaFileManager)
                f = new StandardDocFileFactory(configuration);
            else {
                try {
                    Class<?> pathFileManagerClass =
                            Class.forName("com.sun.tools.javac.nio.PathFileManager");
                    if (pathFileManagerClass.isAssignableFrom(fm.getClass()))
                        f = new PathDocFileFactory(configuration);
                } catch (Throwable t) {
                    throw new IllegalStateException(t);
                }
            }
View Full Code Here

    }

    public void compile(String target, JavaSourceFromString... sources) {
        LOG.info("compiling java classes to "+target);
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        JavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();

        List<String> optionList = Lists.newArrayList();
        // Adds the current classpath to the compiler along with our generated code
        optionList.add("-classpath");
View Full Code Here

    String relativedName = className.substring(className.lastIndexOf('.') + 1, className.length());
    String patName = relativedName.replace("*", "(\\w+)");
    Pattern pat = Pattern.compile(patName);

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileManager fm = compiler.getStandardFileManager(
        new DiagnosticCollector<JavaFileObject>(), null, null);
    HashSet<JavaFileObject.Kind> kind = new HashSet<JavaFileObject.Kind>(){{
        add(JavaFileObject.Kind.CLASS);
    }};

    for (JavaFileObject f : fm.list(StandardLocation.PLATFORM_CLASS_PATH, packageName, kind, false)) {
      String relatived0 = f.getName();
      String name0 = relatived0.substring(0, relatived0.length() - ".class".length());
      Matcher m = pat.matcher(name0);
      if (m.matches()) {
        String name = packageName + '.' + name0;
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.