Java Code Examples for com.sun.tools.javac.parser.Tokens.TokenKind#EOF

The following examples show how to use com.sun.tools.javac.parser.Tokens.TokenKind#EOF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocCommentParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
List<JCTree> parseParams(String s) throws ParseException {
    if (s.trim().isEmpty())
        return List.nil();

    JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
    ListBuffer<JCTree> paramTypes = new ListBuffer<JCTree>();
    paramTypes.add(p.parseType());

    if (p.token().kind == TokenKind.IDENTIFIER)
        p.nextToken();

    while (p.token().kind == TokenKind.COMMA) {
        p.nextToken();
        paramTypes.add(p.parseType());

        if (p.token().kind == TokenKind.IDENTIFIER)
            p.nextToken();
    }

    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");

    return paramTypes.toList();
}
 
Example 2
Source File: ReferenceParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private List<JCTree> parseParams(String s) throws ParseException {
    if (s.trim().isEmpty())
        return List.nil();

    JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
    ListBuffer<JCTree> paramTypes = new ListBuffer<>();
    paramTypes.add(p.parseType());

    if (p.token().kind == TokenKind.IDENTIFIER)
        p.nextToken();

    while (p.token().kind == TokenKind.COMMA) {
        p.nextToken();
        paramTypes.add(p.parseType());

        if (p.token().kind == TokenKind.IDENTIFIER)
            p.nextToken();
    }

    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");

    return paramTypes.toList();
}
 
Example 3
Source File: DocCommentParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
List<JCTree> parseParams(String s) throws ParseException {
    if (s.trim().isEmpty())
        return List.nil();

    JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
    ListBuffer<JCTree> paramTypes = new ListBuffer<>();
    paramTypes.add(p.parseType());

    if (p.token().kind == TokenKind.IDENTIFIER)
        p.nextToken();

    while (p.token().kind == TokenKind.COMMA) {
        p.nextToken();
        paramTypes.add(p.parseType());

        if (p.token().kind == TokenKind.IDENTIFIER)
            p.nextToken();
    }

    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");

    return paramTypes.toList();
}
 
Example 4
Source File: DocCommentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
List<JCTree> parseParams(String s) throws ParseException {
    if (s.trim().isEmpty())
        return List.nil();

    JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
    ListBuffer<JCTree> paramTypes = new ListBuffer<JCTree>();
    paramTypes.add(p.parseType());

    if (p.token().kind == TokenKind.IDENTIFIER)
        p.nextToken();

    while (p.token().kind == TokenKind.COMMA) {
        p.nextToken();
        paramTypes.add(p.parseType());

        if (p.token().kind == TokenKind.IDENTIFIER)
            p.nextToken();
    }

    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");

    return paramTypes.toList();
}
 
Example 5
Source File: DocCommentParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
List<JCTree> parseParams(String s) throws ParseException {
    if (s.trim().isEmpty())
        return List.nil();

    JavacParser p = fac.newParser(s.replace("...", "[]"), false, false, false);
    ListBuffer<JCTree> paramTypes = new ListBuffer<JCTree>();
    paramTypes.add(p.parseType());

    if (p.token().kind == TokenKind.IDENTIFIER)
        p.nextToken();

    while (p.token().kind == TokenKind.COMMA) {
        p.nextToken();
        paramTypes.add(p.parseType());

        if (p.token().kind == TokenKind.IDENTIFIER)
            p.nextToken();
    }

    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");

    return paramTypes.toList();
}
 
Example 6
Source File: ReferenceParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Name parseMember(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    Name name = p.ident();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return name;
}
 
Example 7
Source File: ReferenceParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private JCTree parseType(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    JCTree tree = p.parseType();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return tree;
}
 
Example 8
Source File: DocCommentParser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
JCTree parseType(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    JCTree tree = p.parseType();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return tree;
}
 
Example 9
Source File: DocCommentParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
Name parseMember(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    Name name = p.ident();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return name;
}
 
Example 10
Source File: DocCommentParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
JCTree parseType(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    JCTree tree = p.parseType();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return tree;
}
 
Example 11
Source File: DocCommentParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Name parseMember(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    Name name = p.ident();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return name;
}
 
Example 12
Source File: DocCommentParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
JCTree parseType(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    JCTree tree = p.parseType();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return tree;
}
 
Example 13
Source File: DocCommentParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
Name parseMember(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    Name name = p.ident();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return name;
}
 
Example 14
Source File: ReferenceParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private JCTree parseType(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    JCTree tree = p.parseType();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return tree;
}
 
Example 15
Source File: DocCommentParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
Name parseMember(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    Name name = p.ident();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return name;
}
 
Example 16
Source File: DocCommentParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
Name parseMember(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    Name name = p.ident();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return name;
}
 
Example 17
Source File: DocCommentParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
Name parseMember(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    Name name = p.ident();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return name;
}
 
Example 18
Source File: DocCommentParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
JCTree parseType(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    JCTree tree = p.parseType();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return tree;
}
 
Example 19
Source File: DocCommentParser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
JCTree parseType(String s) throws ParseException {
    JavacParser p = fac.newParser(s, false, false, false);
    JCTree tree = p.parseType();
    if (p.token().kind != TokenKind.EOF)
        throw new ParseException("dc.ref.unexpected.input");
    return tree;
}
 
Example 20
Source File: JavacTokens.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
/** Lex the input and return a list of {@link RawTok}s. */
public static ImmutableList<RawTok> getTokens(
    String source, Context context, Set<TokenKind> stopTokens) {
  if (source == null) {
    return ImmutableList.of();
  }
  ScannerFactory fac = ScannerFactory.instance(context);
  char[] buffer = (source + EOF_COMMENT).toCharArray();
  Scanner scanner =
      new AccessibleScanner(fac, new CommentSavingTokenizer(fac, buffer, buffer.length));
  ImmutableList.Builder<RawTok> tokens = ImmutableList.builder();
  int end = source.length();
  int last = 0;
  do {
    scanner.nextToken();
    Token t = scanner.token();
    if (t.comments != null) {
      for (Comment c : Lists.reverse(t.comments)) {
        if (last < c.getSourcePos(0)) {
          tokens.add(new RawTok(null, null, last, c.getSourcePos(0)));
        }
        tokens.add(
            new RawTok(null, null, c.getSourcePos(0), c.getSourcePos(0) + c.getText().length()));
        last = c.getSourcePos(0) + c.getText().length();
      }
    }
    if (stopTokens.contains(t.kind)) {
      if (t.kind != TokenKind.EOF) {
        end = t.pos;
      }
      break;
    }
    if (last < t.pos) {
      tokens.add(new RawTok(null, null, last, t.pos));
    }
    tokens.add(
        new RawTok(
            t.kind == TokenKind.STRINGLITERAL ? "\"" + t.stringVal() + "\"" : null,
            t.kind,
            t.pos,
            t.endPos));
    last = t.endPos;
  } while (scanner.token().kind != TokenKind.EOF);
  if (last < end) {
    tokens.add(new RawTok(null, null, last, end));
  }
  return tokens.build();
}