⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javacprocessingenvironment.java

📁 是一款用JAVA 编写的编译器 具有很强的编译功能
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            Name.Table names = Name.Table.instance(context);            assert names != null;            next.put(Name.Table.namesKey, names);        }        DiagnosticListener dl = context.get(DiagnosticListener.class);        if (dl != null)            next.put(DiagnosticListener.class, dl);        TaskListener tl = context.get(TaskListener.class);        if (tl != null)            next.put(TaskListener.class, tl);        JavaFileManager jfm = context.get(JavaFileManager.class);        assert jfm != null;        next.put(JavaFileManager.class, jfm);        if (jfm instanceof JavacFileManager) {            ((JavacFileManager)jfm).setContext(next);        }        Name.Table names = Name.Table.instance(context);        assert names != null;        next.put(Name.Table.namesKey, names);        Keywords keywords = Keywords.instance(context);        assert(keywords != null);        next.put(Keywords.keywordsKey, keywords);        JavaCompiler oldCompiler = JavaCompiler.instance(context);        JavaCompiler nextCompiler = JavaCompiler.instance(next);        nextCompiler.initRound(oldCompiler);        JavacTaskImpl task = context.get(JavacTaskImpl.class);        if (task != null) {            next.put(JavacTaskImpl.class, task);            task.updateContext(next);        }        context.clear();        return next;    }    /*     * Called retroactively to determine if a class loader was required,     * after we have failed to create one.     */    private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) {        if (procNames != null)            return true;	String procPath;	URL[] urls = new URL[1]; 	for(File pathElement : workingpath) {	    try {		urls[0] = pathElement.toURI().toURL();		if (ServiceProxy.hasService(Processor.class, urls))		    return true;	    } catch (MalformedURLException ex) {		throw new AssertionError(ex);	    }	    catch (ServiceProxy.ServiceConfigurationError e) {		log.error("proc.bad.config.file", e.getLocalizedMessage());		return true;	    }	}        return false;    }    private class AnnotationCollector extends TreeScanner {        List<JCTree> path = List.nil();        static final boolean verbose = false;        List<JCAnnotation> annotations = List.nil();        public List<JCAnnotation> findAnnotations(List<? extends JCTree> nodes) {            annotations = List.nil();            scan(nodes);            List<JCAnnotation> found = annotations;            annotations = List.nil();            return found.reverse();        }        public void scan(JCTree node) {            if (node == null)                return;            Symbol sym = TreeInfo.symbolFor(node);            if (sym != null)                path = path.prepend(node);            super.scan(node);            if (sym != null)                path = path.tail;        }        public void visitAnnotation(JCAnnotation node) {            annotations = annotations.prepend(node);            if (verbose) {                StringBuilder sb = new StringBuilder();                for (JCTree tree : path.reverse()) {                    System.err.print(sb);                    System.err.println(TreeInfo.symbolFor(tree));                    sb.append("  ");                }                System.err.print(sb);                System.err.println(node);            }        }    }    private static <T extends JCTree> List<T> cleanTrees(List<T> nodes) {        for (T node : nodes)            treeCleaner.scan(node);        return nodes;    }    private static TreeScanner treeCleaner = new TreeScanner() {            public void scan(JCTree node) {                super.scan(node);                if (node != null)                    node.type = null;            }            public void visitTopLevel(JCCompilationUnit node) {                node.packge = null;                super.visitTopLevel(node);            }            public void visitClassDef(JCClassDecl node) {                node.sym = null;                super.visitClassDef(node);            }            public void visitMethodDef(JCMethodDecl node) {                node.sym = null;                super.visitMethodDef(node);            }            public void visitVarDef(JCVariableDecl node) {                node.sym = null;                super.visitVarDef(node);            }            public void visitNewClass(JCNewClass node) {                node.constructor = null;                super.visitNewClass(node);            }            public void visitAssignop(JCAssignOp node) {                node.operator = null;                super.visitAssignop(node);            }            public void visitUnary(JCUnary node) {                node.operator = null;                super.visitUnary(node);            }            public void visitBinary(JCBinary node) {                node.operator = null;                super.visitBinary(node);            }            public void visitSelect(JCFieldAccess node) {                node.sym = null;                super.visitSelect(node);            }            public void visitIdent(JCIdent node) {                node.sym = null;                super.visitIdent(node);            }        };    private boolean moreToDo() {        return filer.newFiles();    }    /**     * {@inheritdoc}     *     * Command line options suitable for presenting to annotation     * processors.  "-Afoo=bar" should be "-Afoo" => "bar".     */    public Map<String,String> getOptions() {        return processorOptions;    }    public Messager getMessager() {        return messager;    }    public Filer getFiler() {        return filer;    }    public JavacElements getElementUtils() {        return elementUtils;    }    public JavacTypes getTypeUtils() {        return typeUtils;    }    public SourceVersion getSourceVersion() {        return Source.toSourceVersion(source);    }    public Locale getLocale() {	return Locale.getDefault();    }    public Set<Symbol.PackageSymbol> getSpecifiedPackages() {        return specifiedPackages;    }    // Borrowed from DocletInvoker and apt    // TODO: remove from apt's Main    /**     * Utility method for converting a search path string to an array     * of directory and JAR file URLs.     *     * @param path the search path string     * @return the resulting array of directory and JAR file URLs     */    public static URL[] pathToURLs(String path) {        StringTokenizer st = new StringTokenizer(path, File.pathSeparator);        URL[] urls = new URL[st.countTokens()];        int count = 0;        while (st.hasMoreTokens()) {            URL url = fileToURL(new File(st.nextToken()));            if (url != null) {                urls[count++] = url;            }        }        if (urls.length != count) {            URL[] tmp = new URL[count];            System.arraycopy(urls, 0, tmp, 0, count);            urls = tmp;        }        return urls;    }    /**     * Returns the directory or JAR file URL corresponding to the specified     * local file name.     *     * @param file the File object     * @return the resulting directory or JAR file URL, or null if unknown     */    private static URL fileToURL(File file) {        String name;        try {            name = file.getCanonicalPath();        } catch (IOException e) {            name = file.getAbsolutePath();        }        name = name.replace(File.separatorChar, '/');        if (!name.startsWith("/")) {            name = "/" + name;        }        // If the file does not exist, then assume that it's a directory        if (!file.isFile()) {            name = name + "/";        }        try {            return new URL("file", "", name);        } catch (MalformedURLException e) {            throw new IllegalArgumentException("file");        }    }    private static final Pattern allMatches = Pattern.compile(".*");    private static final Pattern noMatches  = Pattern.compile("(\\P{all})+");    /**     * Convert import-style string to regex matching that string.  If     * the string is a valid import-style string, return a regex that     * won't match anything.     */    // TODO: remove version in Apt.java    public static Pattern importStringToPattern(String s, Processor p, Log log) {        if (s.equals("*")) {            return allMatches;        } else {            String t = s;            boolean star = false;            /*             * Validate string from factory is legal.  If the string             * has more than one asterisks or the asterisks does not             * appear as the last character (preceded by a period),             * the string is not legal.             */            boolean valid = true;            int index = t.indexOf('*');            if (index != -1) {                // '*' must be last character...                if (index == t.length() -1) {                     // ... and preceeding character must be '.'                    if ( index-1 >= 0 ) {                        valid = t.charAt(index-1) == '.';                        // Strip off ".*$" for identifier checks                        t = t.substring(0, t.length()-2);                    }                } else                    valid = false;            }            // Verify string is off the form (javaId \.)+ or javaId            if (valid) {                String[] javaIds = t.split("\\.", t.length()+2);                for(String javaId: javaIds)                    valid &= SourceVersion.isIdentifier(javaId);            }            if (!valid) {                log.warning("proc.malformed.supported.string", s, p.getClass().getName());                return noMatches; // won't match any valid identifier            }            String s_prime = s.replaceAll("\\.", "\\\\.");            if (s_prime.endsWith("*")) {                s_prime =  s_prime.substring(0, s_prime.length() - 1) + ".+";            }            return Pattern.compile(s_prime);        }    }    /**     * For internal use by Sun Microsystems only.  This method will be     * removed without warning.     */    public Context getContext() {        return context;    }    public String toString() {        return "javac ProcessingEnvironment";    }    public static boolean isValidOptionName(String optionName) {        for(String s : optionName.split("\\.", -1)) {            if (!SourceVersion.isIdentifier(s))                return false;        }        return true;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -