当前位置: 首页>>代码示例>>Java>>正文


Java Parser.Factory方法代码示例

本文整理汇总了Java中com.sun.tools.javac.parser.Parser.Factory方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.Factory方法的具体用法?Java Parser.Factory怎么用?Java Parser.Factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.parser.Parser的用法示例。


在下文中一共展示了Parser.Factory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseType

import com.sun.tools.javac.parser.Parser; //导入方法依赖的package包/类
/**
 * For internal use by Sun Microsystems only.  This method will be
 * removed without warning.
 */
public Type parseType(String expr, TypeElement scope) {
    if (expr == null || expr.equals(""))
        throw new IllegalArgumentException();
    compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(null);
    Scanner.Factory scannerFactory = Scanner.Factory.instance(context);
    Parser.Factory parserFactory = Parser.Factory.instance(context);
    Attr attr = Attr.instance(context);
    try {
        Scanner scanner = scannerFactory.newScanner((expr+"\u0000").toCharArray(),
                                                    expr.length());
        Parser parser = parserFactory.newParser(scanner, false, false);
        JCTree tree = parser.type();
        return attr.attribType(tree, (Symbol.TypeSymbol)scope);
    } finally {
        compiler.log.useSource(prev);
    }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:23,代码来源:JavacTaskImpl.java

示例2: parseType

import com.sun.tools.javac.parser.Parser; //导入方法依赖的package包/类
/**
 * For internal use only.  This method will be
 * removed without warning.
 */
public Type parseType(String expr, TypeElement scope) {
    if (expr == null || expr.equals(""))
        throw new IllegalArgumentException();
    compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(null);
    Scanner.Factory scannerFactory = Scanner.Factory.instance(context);
    Parser.Factory parserFactory = Parser.Factory.instance(context);
    Attr attr = Attr.instance(context);
    try {
        Scanner scanner = scannerFactory.newScanner((expr+"\u0000").toCharArray(),
                                                    expr.length());
        Parser parser = parserFactory.newParser(scanner, false, false);
        JCTree tree = parser.type();
        return attr.attribType(tree, (Symbol.TypeSymbol)scope);
    } finally {
        compiler.log.useSource(prev);
    }
}
 
开发者ID:lucasicf,项目名称:metricgenerator-jdk-compiler,代码行数:23,代码来源:JavacTaskImpl.java

示例3: test

import com.sun.tools.javac.parser.Parser; //导入方法依赖的package包/类
static void test(boolean genEndPos) throws IOException {
    Context context = new Context();

    Options options = Options.instance(context);
    options.put("diags", "%b:%s/%o/%e:%_%t%m|%p%m");

    Log log = Log.instance(context);
    log.multipleErrors = true;

    JavacFileManager.preRegister(context);
    Scanner.Factory sfac = Scanner.Factory.instance(context);
    Parser.Factory pfac = Parser.Factory.instance(context);

    final String text =
          "public class Foo {\n"
        + "  public static void main(String[] args) {\n"
        + "    if (args.length == 0)\n"
        + "      System.out.println(\"no args\");\n"
        + "    else\n"
        + "      System.out.println(args.length + \" args\");\n"
        + "  }\n"
        + "}\n";
    JavaFileObject fo = new StringJavaFileObject("Foo", text);
    log.useSource(fo);

    Scanner s = sfac.newScanner(fo.getCharContent(true));
    Parser parser = pfac.newParser(s, false, genEndPos);
    JCTree.JCCompilationUnit tree = parser.compilationUnit();
    log.setEndPosTable(fo, tree.endPositions);

    TreeScanner ts = new LogTester(log, tree.endPositions);
    ts.scan(tree);

    check(log.nerrors, 4, "errors");
    check(log.nwarnings, 4, "warnings");
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:37,代码来源:TestLog.java

示例4: CommentCollectingParser

import com.sun.tools.javac.parser.Parser; //导入方法依赖的package包/类
protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments) {
	super(fac, S, keepDocComments);
	lexer = S;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:5,代码来源:CommentCollectingParser.java

示例5: key

import com.sun.tools.javac.parser.Parser; //导入方法依赖的package包/类
static Context.Key<Parser.Factory> key() {
	return parserFactoryKey;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:4,代码来源:CommentCollectingParserFactory.java

示例6: CommentCollectingParser

import com.sun.tools.javac.parser.Parser; //导入方法依赖的package包/类
protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) {
	super(fac, S, keepDocComments);
	lexer = S;
	this.commentsMap = commentsMap;
}
 
开发者ID:redundent,项目名称:lombok,代码行数:6,代码来源:CommentCollectingParser.java


注:本文中的com.sun.tools.javac.parser.Parser.Factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。