use of com.sun.tools.javac.parser.JavacParser in project error-prone by google.
the class GuardedByUtils method parseString.
public static JCTree.JCExpression parseString(String guardedByString, Context context) {
JavacParser parser = ParserFactory.instance(context).newParser(guardedByString, false, true, false);
JCTree.JCExpression exp;
try {
exp = parser.parseExpression();
} catch (Throwable e) {
throw new IllegalGuardedBy(e.getMessage());
}
int len = (parser.getEndPos(exp) - exp.getStartPosition());
if (len != guardedByString.length()) {
throw new IllegalGuardedBy("Didn't parse entire string.");
}
return exp;
}
use of com.sun.tools.javac.parser.JavacParser in project bazel by bazelbuild.
the class TreePrunerTest method parseLines.
JCCompilationUnit parseLines(String... lines) {
Context context = new Context();
try (JavacFileManager fm = new JavacFileManager(context, true, UTF_8)) {
ParserFactory parserFactory = ParserFactory.instance(context);
String input = Joiner.on('\n').join(lines);
JavacParser parser = parserFactory.newParser(input, /*keepDocComments=*/
false, /*keepEndPos=*/
false, /*keepLineMap=*/
false);
return parser.parseCompilationUnit();
} catch (IOException e) {
throw new IOError(e);
}
}
use of com.sun.tools.javac.parser.JavacParser 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.
}
Aggregations