Search in sources :

Example 1 with ScannerFactory

use of com.sun.tools.javac.parser.ScannerFactory in project lombok by rzwitserloot.

the class CommentCollectingParserFactory method newParser.

public Parser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) {
    ScannerFactory scannerFactory = ScannerFactory.instance(context);
    Lexer lexer = scannerFactory.newScanner(input, true);
    Object x = new CommentCollectingParser(this, lexer, true, keepLineMap);
    return (Parser) x;
// CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either
//javac6's EndPosParser which extends Parser, or javac7's EndPosParser which implements Parser.
//Either way this will work out.
}
Also used : Lexer(com.sun.tools.javac.parser.Lexer) ScannerFactory(com.sun.tools.javac.parser.ScannerFactory) Parser(com.sun.tools.javac.parser.Parser)

Example 2 with ScannerFactory

use of com.sun.tools.javac.parser.ScannerFactory in project error-prone by google.

the class ErrorProneTokens method getTokens.

/** Returns the tokens for the given source text, including comments. */
public static ImmutableList<ErrorProneToken> getTokens(String source, Context context) {
    if (source == null) {
        return ImmutableList.of();
    }
    ScannerFactory fac = ScannerFactory.instance(context);
    char[] buffer = source.toCharArray();
    Scanner scanner = new AccessibleScanner(fac, new CommentSavingTokenizer(fac, buffer, buffer.length));
    ImmutableList.Builder<ErrorProneToken> tokens = ImmutableList.builder();
    do {
        scanner.nextToken();
        tokens.add(new ErrorProneToken(scanner.token()));
    } while (scanner.token().kind != TokenKind.EOF);
    return tokens.build();
}
Also used : Scanner(com.sun.tools.javac.parser.Scanner) ImmutableList(com.google.common.collect.ImmutableList) ScannerFactory(com.sun.tools.javac.parser.ScannerFactory)

Example 3 with ScannerFactory

use of com.sun.tools.javac.parser.ScannerFactory in project lombok by rzwitserloot.

the class CommentCollectingParserFactory method newParser.

public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) {
    ScannerFactory scannerFactory = ScannerFactory.instance(context);
    Lexer lexer = scannerFactory.newScanner(input, true);
    Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, keepEndPos);
    return (JavacParser) x;
// CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either
//javac6's EndPosParser which extends Parser, or javac8's JavacParser which implements Parser.
//Either way this will work out.
}
Also used : Lexer(com.sun.tools.javac.parser.Lexer) JavacParser(com.sun.tools.javac.parser.JavacParser) ScannerFactory(com.sun.tools.javac.parser.ScannerFactory)

Aggregations

ScannerFactory (com.sun.tools.javac.parser.ScannerFactory)3 Lexer (com.sun.tools.javac.parser.Lexer)2 ImmutableList (com.google.common.collect.ImmutableList)1 JavacParser (com.sun.tools.javac.parser.JavacParser)1 Parser (com.sun.tools.javac.parser.Parser)1 Scanner (com.sun.tools.javac.parser.Scanner)1