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


Java Scanner类代码示例

本文整理汇总了Java中com.sun.tools.javac.parser.Scanner的典型用法代码示例。如果您正苦于以下问题:Java Scanner类的具体用法?Java Scanner怎么用?Java Scanner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Scanner类属于com.sun.tools.javac.parser包,在下文中一共展示了Scanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseType

import com.sun.tools.javac.parser.Scanner; //导入依赖的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.Scanner; //导入依赖的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: parseExpression

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
private static JCExpression parseExpression(Context context, CharSequence expr, boolean onlyFullInput, SourcePositions[] pos, final List<Diagnostic<? extends JavaFileObject>> errors) {
    if (expr == null || (pos != null && pos.length != 1))
        throw new IllegalArgumentException();
    JavaCompiler compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(new DummyJFO());
    Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(compiler.log) {
        @Override
        public void report(JCDiagnostic diag) {
            errors.add(diag);
        }            
    };
    try {
        CharBuffer buf = CharBuffer.wrap((expr+"\u0000").toCharArray(), 0, expr.length());
        ParserFactory factory = ParserFactory.instance(context);
        ScannerFactory scannerFactory = ScannerFactory.instance(context);
        Names names = Names.instance(context);
        Scanner scanner = scannerFactory.newScanner(buf, false);
        Parser parser = new JackpotJavacParser(context, (NBParserFactory) factory, scanner, false, false, CancelService.instance(context), names);
        if (parser instanceof JavacParser) {
            if (pos != null)
                pos[0] = new ParserSourcePositions((JavacParser)parser);
            JCExpression result = parser.parseExpression();

            if (!onlyFullInput || scanner.token().kind == TokenKind.EOF) {
                return result;
            }
        }
        return null;
    } finally {
        compiler.log.useSource(prev);
        compiler.log.popDiagnosticHandler(discardHandler);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:Utilities.java

示例4: comment

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
private Comment comment(String docString) {
    StringBuilder docComment = new StringBuilder()
                               .append("/**")
                               .append(docString)
                               .append("*/");
    Scanner scanner = scanners.newScanner(docComment, true);
    scanner.nextToken();
    Token token = scanner.token();
    return token.comment(CommentStyle.JAVADOC);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:Documentifier.java

示例5: verifyTreeSpans

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
public void verifyTreeSpans(File file, List<int[]> spans,
                            String updatedContent, int semicolon) throws IOException {
    JCCompilationUnit updated = read(file.toURI(), updatedContent);
    Iterator<int[]> nextSpan = spans.iterator();
    new TreePathScanner<Void, Void>() {
        @Override
        public Void scan(Tree tree, Void p) {
            if (tree != null) {
                int start = ((JCTree) tree).getStartPosition();
                int end = ((JCTree) tree).getEndPosition(updated.endPositions);

                if (tree.getKind() != Kind.ERRONEOUS) {
                    int[] expected = nextSpan.next();
                    int expectedEnd = expected[1];

                    if (expectedEnd == semicolon + 1) {
                        Scanner scanner = scannerFactory.newScanner(updatedContent, true);
                        scanner.nextToken();
                        while (scanner.token().pos < expectedEnd)
                            scanner.nextToken();
                        expectedEnd = scanner.token().pos;
                    }

                    if (expected[0] != start || expectedEnd != end) {
                        error(updatedContent + "; semicolon: " + semicolon + "; expected: " +
                              expected[0] + "-" + expectedEnd + "; found=" + start + "-" + end +
                              ";" + tree);
                    }
                }
            }
            return super.scan(tree, p);
        }
    }.scan(updated, null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:MissingSemicolonTest.java

示例6: scan

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
CaInfo scan(String s) {
    try {
        Scanner scanner = scannerFactory.newScanner(s, false);
        Matched in = new Matched(scanner);
        Parser parser = new Parser(in, proc, s);
        Completeness stat = parser.parseUnit();
        int endPos = stat == Completeness.UNKNOWN
                ? s.length()
                : in.prevCT.endPos;
        return new CaInfo(stat, endPos);
    } catch (SyntaxException ex) {
        return new CaInfo(error(), s.length());
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:15,代码来源:CompletenessAnalyzer.java

示例7: newScanner

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
@Override
public Scanner newScanner(CharSequence input, boolean keepDocComments) {
	if (input instanceof CharBuffer) {
		CharBuffer buf = (CharBuffer) input;
		return new CommentCollectingScanner(this, new CommentCollectingTokenizer(this, buf));
	}
	char[] array = input.toString().toCharArray();
	return newScanner(array, array.length, keepDocComments);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:10,代码来源:CommentCollectingScannerFactory.java

示例8: preRegister

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
@SuppressWarnings("all")
public static void preRegister(final Context context) {
	if (context.get(scannerFactoryKey) == null) {
		// Careful! There is voodoo magic here!
		//
		// Context.Factory is parameterized. make() is for javac6 and below; make(Context) is for javac7 and up.
		// this anonymous inner class definition is intentionally 'raw' - the return type of both 'make' methods is 'T',
		// which means the compiler will only generate the correct "real" override method (with returntype Object, which is
		// the lower bound for T, as a synthetic accessor for the make with returntype ScannerFactory) for that make method which
		// is actually on the classpath (either make() for javac6-, or make(Context) for javac7+).
		//
		// We normally solve this issue via src/stubs, with BOTH make methods listed, but for some reason the presence of a stubbed out
		// Context (or even a complete copy, it doesn't matter) results in a really strange eclipse bug, where any mention of any kind
		// of com.sun.tools.javac.tree.TreeMaker in a source file disables ALL usage of 'go to declaration' and auto-complete in the entire
		// source file.
		//
		// Thus, in short:
		// * Do NOT parameterize the anonymous inner class literal.
		// * Leave the return types as 'j.l.Object'.
		// * Leave both make methods intact; deleting one has no effect on javac6- / javac7+, but breaks the other. Hard to test for.
		// * Do not stub com.sun.tools.javac.util.Context or any of its inner types, like Factory.
		@SuppressWarnings("all")
		class MyFactory implements Context.Factory {
			// This overrides the javac6- version of make.
			public Object make() {
				return new CommentCollectingScannerFactory(context);
			}
			
			// This overrides the javac7+ version of make.
			public Object make(Context c) {
				return new CommentCollectingScannerFactory(c);
			}
		}
		
		@SuppressWarnings("unchecked") Context.Factory<Scanner.Factory> factory = new MyFactory();
		context.put(scannerFactoryKey, factory);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:39,代码来源:CommentCollectingScannerFactory.java

示例9: newScanner

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
@Override
public Scanner newScanner(CharSequence input) {
	if (input instanceof CharBuffer) {
		return new CommentCollectingScanner(this, (CharBuffer)input);
	}
	char[] array = input.toString().toCharArray();
	return newScanner(array, array.length);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:9,代码来源:CommentCollectingScannerFactory.java

示例10: newScanner

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
@Override
public Scanner newScanner(CharSequence input, boolean keepDocComments) {
	if (input instanceof CharBuffer) {
		return new CommentCollectingScanner(this, (CharBuffer)input);
	}
	char[] array = input.toString().toCharArray();
	return newScanner(array, array.length, keepDocComments);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:9,代码来源:CommentCollectingScannerFactory.java

示例11: test

import com.sun.tools.javac.parser.Scanner; //导入依赖的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

示例12: getTokens

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
public ImmutableList<ErrorProneToken> getTokens() {
  Scanner scanner = new AccessibleScanner(scannerFactory, commentSavingTokenizer);
  ImmutableList.Builder<ErrorProneToken> tokens = ImmutableList.builder();
  do {
    scanner.nextToken();
    tokens.add(new ErrorProneToken(scanner.token()));
  } while (scanner.token().kind != TokenKind.EOF);
  return tokens.build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:10,代码来源:ErrorProneTokens.java

示例13: readTokens

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
private static int readTokens(Scanner scanner, Token limitingToken, String unclosedError) {
	scanner.nextToken();
	while (scanner.token() != limitingToken) {
		if (scanner.token() == Token.SEMI) {
			throw new RuntimeException(unclosedError);
		}
		scanner.nextToken();
	}
	
	return scanner.pos();
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:12,代码来源:JCSqlQuery.java

示例14: getTokens

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
public List<? extends Pair<String, Integer>> getTokens(int start, int end) {
    if (!hasSource()) {
        throw new IllegalStateException ();
    }
    if (start < end) {
        try {
            ArrayList<Pair<String, Integer>> ret = new ArrayList<>();
            ScannerFactory sf = ScannerFactory.instance(getJavacTask().getContext());
            Scanner s = sf.newScanner(this.jfo.getCharContent(false).subSequence(start, end), false);
            while(true) {
                s.nextToken();
                Tokens.Token t = s.token();
                if (t == null || t.kind == Tokens.TokenKind.EOF)
                    break;
                switch (t.kind) {
                    case DOT: case COMMA: case SEMI: case LPAREN: case RPAREN:
                    case LBRACKET: case RBRACKET: case LBRACE: case RBRACE:
                        ret.add(new Pair(t.kind.name, start + t.pos));
                        break;
                    default:
                        ret.add(new Pair(t.kind.toString(), start + t.pos));
                }
            }
            return ret;
        } catch (IOException ioe) {}
    }
    return null;
}
 
开发者ID:jtulach,项目名称:dew,代码行数:29,代码来源:CompilationInfo.java

示例15: preRegister

import com.sun.tools.javac.parser.Scanner; //导入依赖的package包/类
public static void preRegister(final Context context) {
	if (context.get(scannerFactoryKey) == null) {
		context.put(scannerFactoryKey, new Context.Factory<Scanner.Factory>() {
			public CommentCollectingScanner.Factory make() {
				return new CommentCollectingScannerFactory(context);
			}
			
			public CommentCollectingScanner.Factory make(Context c) {
				return new CommentCollectingScannerFactory(c);
			}
		});
	}
}
 
开发者ID:redundent,项目名称:lombok,代码行数:14,代码来源:CommentCollectingScannerFactory.java


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