/** * Parses the Java code contained in the {@link InputStream} and returns * a {@link japa.parser.ast.CompilationUnit} that represents it. * @param in {@link InputStream} containing Java source code * @param encoding encoding of the source code * @return CompilationUnit representing the Java source code * @throws ParseException if the source code has parser errors */ public static CompilationUnit parse(InputStream in, String encoding) throws ParseException { if (cacheParser) { if (parser == null) { parser = new ASTParser(in, encoding); } else { parser.reset(in, encoding); } return parser.CompilationUnit(); } return new ASTParser(in, encoding).CompilationUnit(); }
final public PackageDeclaration PackageDeclaration() throws ParseException { List annotations = null; AnnotationExpr ann; NameExpr name; int line; int column; label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AT: ; break; default: jj_la1[3] = jj_gen; break label_3; } ann = Annotation(); annotations = add(annotations, ann); } jj_consume_token(PACKAGE); line=token.beginLine; column=token.beginColumn; name = Name(); jj_consume_token(SEMICOLON); {if (true) return new PackageDeclaration(line, column, token.endLine, token.endColumn,annotations, name);} throw new Error("Missing return statement in function"); }
final public List AnnotationTypeBody() throws ParseException { List ret = null; BodyDeclaration member; jj_consume_token(LBRACE); label_49: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ABSTRACT: case BOOLEAN: break label_49; member = AnnotationBodyDeclaration(); ret = add(ret, member); jj_consume_token(RBRACE); {if (true) return ret;} throw new Error("Missing return statement in function");
final public AnnotationDeclaration AnnotationTypeDeclaration(Modifier modifier) throws ParseException { String name; List members; int line = modifier.beginLine; int column = modifier.beginColumn; jj_consume_token(AT); if (line == -1) {line=token.beginLine; column=token.beginColumn;} jj_consume_token(INTERFACE); jj_consume_token(IDENTIFIER); name = token.image; members = AnnotationTypeBody(); {if (true) return new AnnotationDeclaration(line, column, token.endLine, token.endColumn,popJavadoc(), modifier.modifiers, modifier.annotations, name, members);} throw new Error("Missing return statement in function"); }
/** * Parses the Java body declaration(e.g fields or methods) contained in a * {@link String} and returns a {@link BodyDeclaration} that represents it. * * @param body * {@link String} containing Java body declaration * @return BodyDeclaration representing the Java annotation * @throws ParseException * if the source code has parser errors * @throws IOException */ public static BodyDeclaration parseBodyDeclaration(final String body) throws ParseException { StringReader sr = new StringReader(body); BodyDeclaration bd = new ASTParser(sr).AnnotationBodyDeclaration(); sr.close(); return bd; }
if (jj_2_6(2)) { ret = InitializerDeclaration(); if (isInterface) throwParseException(token, "An interface cannot have initializers"); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ABSTRACT: case BOOLEAN: case AT: case LT: modifier = Modifiers(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case CLASS: case INTERFACE: ret = ClassOrInterfaceDeclaration(modifier); break; case ENUM: ret = EnumDeclaration(modifier); break; case AT: ret = AnnotationTypeDeclaration(modifier); break; default: jj_la1[27] = jj_gen; if (jj_2_4(2147483647)) { ret = ConstructorDeclaration(modifier); } else if (jj_2_5(2147483647)) { ret = FieldDeclaration(modifier);
int line; int column; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case FALSE: case NULL: case CHARACTER_LITERAL: case STRING_LITERAL: ret = Literal(); break; case THIS: jj_consume_token(THIS); ret = new ThisExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, null); break; case SUPER: jj_consume_token(SUPER); ret = new SuperExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, null); jj_consume_token(DOT); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LT: typeArgs = TypeArguments(); typeArgs.remove(0); break; jj_consume_token(IDENTIFIER); name = token.image; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LPAREN: args = Arguments();
final public BodyDeclaration AnnotationBodyDeclaration() throws ParseException { Modifier modifier; BodyDeclaration ret; pushJavadoc(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON); ret = new EmptyTypeDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn, popJavadoc()); break; case ABSTRACT: case IDENTIFIER: case AT: modifier = Modifiers(); if (jj_2_43(2147483647)) { ret = AnnotationTypeMemberDeclaration(modifier); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case CLASS: case INTERFACE: ret = ClassOrInterfaceDeclaration(modifier); break; case ENUM: ret = EnumDeclaration(modifier); break; case AT: ret = AnnotationTypeDeclaration(modifier); break; case BOOLEAN:
Expression right; BinaryExpr.Operator op; ret = AdditiveExpression(); label_32: while (true) { if (jj_2_19(1)) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LSHIFT: jj_consume_token(LSHIFT); op = BinaryExpr.Operator.lShift; break; default: jj_la1[71] = jj_gen; if (jj_2_20(1)) { RSIGNEDSHIFT(); op = BinaryExpr.Operator.rSignedShift; } else if (jj_2_21(1)) { RUNSIGNEDSHIFT(); op = BinaryExpr.Operator.rUnsignedShift; } else { jj_consume_token(-1); throw new ParseException(); right = AdditiveExpression(); ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, op);
boolean hasArgs = false; String name; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DOT: jj_consume_token(DOT); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case THIS: jj_consume_token(THIS); ret = new ThisExpr(scope.getBeginLine(), scope.getBeginColumn(), token.endLine, token.endColumn, scope); break; case NEW: ret = AllocationExpression(scope); break; default: jj_la1[91] = jj_gen; if (jj_2_29(2147483647)) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LT: typeArgs = TypeArguments(); typeArgs.remove(0); break; jj_consume_token(IDENTIFIER); name = token.image; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LPAREN: args = Arguments(); hasArgs=true; break;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON); ret = new EmptyTypeDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn); break; case IDENTIFIER: case AT: modifier = Modifiers(); if (jj_2_45(2147483647)) { ret = AnnotationTypeMemberDeclaration(modifier); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case CLASS: case INTERFACE: ret = ClassOrInterfaceDeclaration(modifier); break; case ENUM: ret = EnumDeclaration(modifier); break; case AT: ret = AnnotationTypeDeclaration(modifier); break; case BOOLEAN: case SHORT: case IDENTIFIER: ret = FieldDeclaration(modifier); break;
final public TypeDeclaration TypeDeclaration() throws ParseException { Modifier modifier; TypeDeclaration ret; pushJavadoc(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON); ret = new EmptyTypeDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn, popJavadoc()); break; case ABSTRACT: case VOLATILE: case AT: modifier = Modifiers(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case CLASS: case INTERFACE: ret = ClassOrInterfaceDeclaration(modifier); break; case ENUM: ret = EnumDeclaration(modifier); break; case AT: ret = AnnotationTypeDeclaration(modifier); break; default: jj_la1[7] = jj_gen; jj_consume_token(-1); throw new ParseException();
int line = -1; int column = -1; pushJavadoc(); label_9: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AT: ann = Annotation(); annotations = add(annotations, ann); if(line==-1){line=ann.getBeginLine(); column=ann.getBeginColumn();} jj_consume_token(IDENTIFIER); name = token.image; if(line==-1){line=token.beginLine; column=token.beginColumn;} switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LPAREN: args = Arguments(); break; default: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LBRACE: classBody = ClassOrInterfaceBody(false); break; default: {if (true) return new EnumConstantDeclaration(line, column, token.endLine, token.endColumn,popJavadoc(), annotations, name, args, classBody);} throw new Error("Missing return statement in function");
label_4: while (true) { if (jj_2_2(2)) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case PUBLIC: jj_consume_token(PUBLIC); modifiers = addModifier(modifiers, ModifierSet.PUBLIC, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} break; case STATIC: jj_consume_token(STATIC); modifiers = addModifier(modifiers, ModifierSet.STATIC, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} break; case PROTECTED: jj_consume_token(PROTECTED); modifiers = addModifier(modifiers, ModifierSet.PROTECTED, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} break; case PRIVATE: jj_consume_token(PRIVATE); modifiers = addModifier(modifiers, ModifierSet.PRIVATE, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} break; case FINAL: jj_consume_token(FINAL); modifiers = addModifier(modifiers, ModifierSet.FINAL, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} break; case ABSTRACT: jj_consume_token(ABSTRACT); modifiers = addModifier(modifiers, ModifierSet.ABSTRACT, token); if(beginLine==-1) {beginLine=token.beginLine; beginColumn=token.beginColumn;} break;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AT: break label_9; ann = Annotation(); annotations = add(annotations, ann); if(line==-1){line=ann.getBeginLine(); column=ann.getBeginColumn();} jj_consume_token(IDENTIFIER); name = token.image; if(line==-1){line=token.beginLine; column=token.beginColumn;} switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LPAREN: args = Arguments(); break; default: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LBRACE: classBody = ClassOrInterfaceBody(false); break; default:
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON); ret = new EmptyTypeDeclaration(token.beginLine, token.beginColumn, token.endLine, token.endColumn); break; case VOLATILE: case AT: modifier = Modifiers(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case CLASS: case INTERFACE: ret = ClassOrInterfaceDeclaration(modifier); break; case ENUM: ret = EnumDeclaration(modifier); break; case AT: ret = AnnotationTypeDeclaration(modifier); break; default: jj_la1[7] = jj_gen; jj_consume_token(-1); throw new ParseException(); default: jj_la1[8] = jj_gen; jj_consume_token(-1); throw new ParseException();
final public Expression MemberValue() throws ParseException { Expression ret; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AT: ret = Annotation(); break; case LBRACE: ret = MemberValueArrayInitializer(); break; case BOOLEAN: case PLUS: case MINUS: ret = ConditionalExpression(); break; default: jj_la1[127] = jj_gen; jj_consume_token(-1); throw new ParseException();
final public Expression ExclusiveOrExpression() throws ParseException { Expression ret; Expression right; ret = AndExpression(); label_28: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case XOR: ; break; default: jj_la1[64] = jj_gen; break label_28; } jj_consume_token(XOR); right = AndExpression(); ret = new BinaryExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, right, BinaryExpr.Operator.xor); } {if (true) return ret;} throw new Error("Missing return statement in function"); }
final public List Arguments() throws ParseException { List ret = null; jj_consume_token(LPAREN); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BOOLEAN: case BYTE: case PLUS: case MINUS: ret = ArgumentList(); break; default: jj_consume_token(RPAREN); {if (true) return ret;} throw new Error("Missing return statement in function");
final public AnnotationDeclaration AnnotationTypeDeclaration(Modifier modifier) throws ParseException { NameExpr name; List members; int line = modifier.beginLine; int column = modifier.beginColumn; jj_consume_token(AT); if (line == -1) {line=token.beginLine; column=token.beginColumn;} jj_consume_token(INTERFACE); name = Name(); members = AnnotationTypeBody(); AnnotationDeclaration tmp = new AnnotationDeclaration(line, column, token.endLine, token.endColumn, modifier.modifiers, modifier.annotations, null, members); tmp.setNameExpr(name); {if (true) return tmp;} throw new Error("Missing return statement in function"); }