Class ASTFactory
java.lang.Object
org.fife.rsta.ac.java.rjc.parser.ASTFactory
- All Implemented Interfaces:
TokenTypes
Generates an abstract syntax tree for a Java source file.
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate booleanWhether the next member (or class, interface or enum) is deprecated.Fields inherited from interface TokenTypes
ANNOTATION_START, ASSIGNMENT_OPERATOR, COMMENT, DATA_TYPE, DOC_COMMENT, ELIPSIS, IDENTIFIER, KEYWORD, KEYWORD_ABSTRACT, KEYWORD_ASSERT, KEYWORD_BOOLEAN, KEYWORD_BREAK, KEYWORD_BYTE, KEYWORD_CASE, KEYWORD_CATCH, KEYWORD_CHAR, KEYWORD_CLASS, KEYWORD_CONST, KEYWORD_CONTINUE, KEYWORD_DEFAULT, KEYWORD_DO, KEYWORD_DOUBLE, KEYWORD_ELSE, KEYWORD_ENUM, KEYWORD_EXTENDS, KEYWORD_FINAL, KEYWORD_FINALLY, KEYWORD_FLOAT, KEYWORD_FOR, KEYWORD_GOTO, KEYWORD_IF, KEYWORD_IMPLEMENTS, KEYWORD_IMPORT, KEYWORD_INSTANCEOF, KEYWORD_INT, KEYWORD_INTERFACE, KEYWORD_LONG, KEYWORD_NATIVE, KEYWORD_NEW, KEYWORD_PACKAGE, KEYWORD_PRIVATE, KEYWORD_PROTECTED, KEYWORD_PUBLIC, KEYWORD_RETURN, KEYWORD_SHORT, KEYWORD_STATIC, KEYWORD_STRICTFP, KEYWORD_SUPER, KEYWORD_SWITCH, KEYWORD_SYNCHRONIZED, KEYWORD_THIS, KEYWORD_THROW, KEYWORD_THROWS, KEYWORD_TRANSIENT, KEYWORD_TRY, KEYWORD_VOID, KEYWORD_VOLATILE, KEYWORD_WHILE, LITERAL, LITERAL_BOOLEAN, LITERAL_CHAR, LITERAL_FP, LITERAL_INT, LITERAL_NULL, LITERAL_STRING, OPERATOR, OPERATOR_BITWISE_AND, OPERATOR_BITWISE_AND_EQUALS, OPERATOR_BITWISE_NOT, OPERATOR_BITWISE_OR, OPERATOR_BITWISE_OR_EQUALS, OPERATOR_BITWISE_XOR, OPERATOR_BITWISE_XOR_EQUALS, OPERATOR_COLON, OPERATOR_DECREMENT, OPERATOR_DIVIDE, OPERATOR_DIVIDE_EQUALS, OPERATOR_EQUALS, OPERATOR_EQUALS_EQUALS, OPERATOR_GT, OPERATOR_GTE, OPERATOR_INCREMENT, OPERATOR_LOGICAL_AND, OPERATOR_LOGICAL_NOT, OPERATOR_LOGICAL_OR, OPERATOR_LSHIFT, OPERATOR_LSHIFT_EQUALS, OPERATOR_LT, OPERATOR_LTE, OPERATOR_MINUS, OPERATOR_MINUS_EQUALS, OPERATOR_MOD, OPERATOR_MOD_EQUALS, OPERATOR_NE, OPERATOR_PLUS, OPERATOR_PLUS_EQUALS, OPERATOR_QUESTION, OPERATOR_RSHIFT, OPERATOR_RSHIFT_EQUALS, OPERATOR_RSHIFT2, OPERATOR_RSHIFT2_EQUALS, OPERATOR_TIMES, OPERATOR_TIMES_EQUALS, SEPARATOR, SEPARATOR_COMMA, SEPARATOR_DOT, SEPARATOR_LBRACE, SEPARATOR_LBRACKET, SEPARATOR_LPAREN, SEPARATOR_RBRACE, SEPARATOR_RBRACKET, SEPARATOR_RPAREN, SEPARATOR_SEMICOLON, WHITESPACE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanprivate voidcheckForDuplicateLocalVarNames(CompilationUnit cu, Token lVar, CodeBlock block, Method m) Checks whether a local variable's name collides with a local variable defined earlier.private AnnotationgetAnnotation(CompilationUnit cu, Scanner s) Assumes t is the actual '@foobar' annotation token.private CodeBlockgetBlock(CompilationUnit cu, CodeBlock parent, Method m, Scanner s, boolean isStatic) private CodeBlockgetBlock(CompilationUnit cu, CodeBlock parent, Method m, Scanner s, boolean isStatic, int depth) Parses a block of code.private voidgetClassBody(CompilationUnit cu, Scanner s, NormalClassDeclaration classDec) private TypeDeclarationgetClassOrInterfaceDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo, Modifiers modList) getCompilationUnit(String name, Scanner scanner) Reads tokens for a Java source file from the specified lexer and returns the structure of the source as an AST.private EnumBodygetEnumBody(CompilationUnit cu, Scanner s, EnumDeclaration enumDec) private EnumDeclarationgetEnumDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo) private List<FormalParameter> getFormalParameters(CompilationUnit cu, List<Token> tokenList) private voidgetInterfaceBody(CompilationUnit cu, Scanner s, NormalInterfaceDeclaration iDec) private voidgetInterfaceMemberDecl(CompilationUnit cu, Scanner s, NormalInterfaceDeclaration iDec, Modifiers modList) private voidgetMemberDecl(CompilationUnit cu, Scanner s, NormalClassDeclaration classDec, Modifiers modList) private Modifiersprivate NormalClassDeclarationprivate NormalInterfaceDeclarationprivate StringgetQualifiedIdentifier(Scanner scanner) private TypegetType(CompilationUnit cu, Scanner s) private TypegetType(CompilationUnit cu, Scanner s, boolean pushbackOnUnexpected) private TypeArgumentprivate List<TypeArgument> private TypeDeclarationprivate TypeParameterprivate List<TypeParameter> private static booleanisDebug()private intisModifier(Token t) private static void
-
Field Details
-
DEBUG
private static final boolean DEBUG- See Also:
-
nextMemberDeprecated
private boolean nextMemberDeprecatedWhether the next member (or class, interface or enum) is deprecated.
-
-
Constructor Details
-
ASTFactory
public ASTFactory()
-
-
Method Details
-
checkDeprecated
private boolean checkDeprecated() -
checkForDuplicateLocalVarNames
private void checkForDuplicateLocalVarNames(CompilationUnit cu, Token lVar, CodeBlock block, Method m) Checks whether a local variable's name collides with a local variable defined earlier. Note that this method assumes that it is called immediately whenever a variable is parsed, thus any other variables declared in a code block were declared before the one being checked.- Parameters:
cu- The compilation unit.lVar- The just-scanned local variable.block- The code block the variable is in.m- The method the (possibly nested) code blockblockis in, ornullfor none.
-
getAnnotation
Assumes t is the actual '@foobar' annotation token.- Parameters:
cu- The compilation unit.s- The scanner.- Returns:
- The annotation.
- Throws:
IOException- If an IO error occurs.
-
getBlock
private CodeBlock getBlock(CompilationUnit cu, CodeBlock parent, Method m, Scanner s, boolean isStatic) throws IOException - Throws:
IOException
-
getBlock
private CodeBlock getBlock(CompilationUnit cu, CodeBlock parent, Method m, Scanner s, boolean isStatic, int depth) throws IOException Parses a block of code. This should not be called.- Parameters:
parent- The parent code block, ornullif none (i.e. this is the body of a method, a static initializer block, etc.).m- The method containing this block, ornullif this block is not part of a method.s- The scanner.isStatic- Whether this is a static code block.depth- The nested depth of this code block.- Throws:
IOException
-
getClassBody
private void getClassBody(CompilationUnit cu, Scanner s, NormalClassDeclaration classDec) throws IOException - Throws:
IOException
-
getClassOrInterfaceDeclaration
private TypeDeclaration getClassOrInterfaceDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo, Modifiers modList) throws IOException - Throws:
IOException
-
getCompilationUnit
Reads tokens for a Java source file from the specified lexer and returns the structure of the source as an AST.- Parameters:
name- The name of the compilation unit.scanner- The scanner to read from.- Returns:
- The root node of the AST.
-
getEnumBody
private EnumBody getEnumBody(CompilationUnit cu, Scanner s, EnumDeclaration enumDec) throws IOException - Throws:
IOException
-
getEnumDeclaration
private EnumDeclaration getEnumDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo) throws IOException - Throws:
IOException
-
getFormalParameters
private List<FormalParameter> getFormalParameters(CompilationUnit cu, List<Token> tokenList) throws IOException - Throws:
IOException
-
getInterfaceBody
private void getInterfaceBody(CompilationUnit cu, Scanner s, NormalInterfaceDeclaration iDec) throws IOException - Throws:
IOException
-
getInterfaceMemberDecl
private void getInterfaceMemberDecl(CompilationUnit cu, Scanner s, NormalInterfaceDeclaration iDec, Modifiers modList) throws IOException - Throws:
IOException
-
getMemberDecl
private void getMemberDecl(CompilationUnit cu, Scanner s, NormalClassDeclaration classDec, Modifiers modList) throws IOException - Throws:
IOException
-
getModifierList
- Throws:
IOException
-
getNormalClassDeclaration
private NormalClassDeclaration getNormalClassDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo) throws IOException - Throws:
IOException
-
getNormalInterfaceDeclaration
private NormalInterfaceDeclaration getNormalInterfaceDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo) throws IOException - Throws:
IOException
-
getQualifiedIdentifier
- Throws:
IOException
-
getThrownTypeNames
- Throws:
IOException
-
getType
- Throws:
IOException
-
getType
private Type getType(CompilationUnit cu, Scanner s, boolean pushbackOnUnexpected) throws IOException - Throws:
IOException
-
getTypeArgument
- Throws:
IOException
-
getTypeArguments
- Throws:
IOException
-
getTypeDeclaration
- Throws:
IOException
-
getTypeParameter
- Throws:
IOException
-
getTypeParameters
- Throws:
IOException
-
isDebug
private static boolean isDebug() -
isModifier
-
log
-