Package org.fife.rsta.ac.java.rjc.parser
Class ASTFactory
- java.lang.Object
-
- org.fife.rsta.ac.java.rjc.parser.ASTFactory
-
- All Implemented Interfaces:
TokenTypes
public class ASTFactory extends java.lang.Object implements TokenTypes
Generates an abstract syntax tree for a Java source file.- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private static booleanDEBUGprivate booleannextMemberDeprecatedWhether the next member (or class, interface or enum) is deprecated.-
Fields inherited from interface org.fife.rsta.ac.java.rjc.lexer.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 Constructor Description ASTFactory()
-
Method Summary
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
nextMemberDeprecated
private boolean nextMemberDeprecated
Whether the next member (or class, interface or enum) is deprecated.
-
-
Method Detail
-
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
private Annotation getAnnotation(CompilationUnit cu, Scanner s) throws java.io.IOException
Assumes t is the actual '@foobar' annotation token.- Parameters:
cu- The compilation unit.s- The scanner.- Returns:
- The annotation.
- Throws:
java.io.IOException- If an IO error occurs.
-
getBlock
private CodeBlock getBlock(CompilationUnit cu, CodeBlock parent, Method m, Scanner s, boolean isStatic) throws java.io.IOException
- Throws:
java.io.IOException
-
getBlock
private CodeBlock getBlock(CompilationUnit cu, CodeBlock parent, Method m, Scanner s, boolean isStatic, int depth) throws java.io.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:
java.io.IOException
-
getClassBody
private void getClassBody(CompilationUnit cu, Scanner s, NormalClassDeclaration classDec) throws java.io.IOException
- Throws:
java.io.IOException
-
getClassOrInterfaceDeclaration
private TypeDeclaration getClassOrInterfaceDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo, Modifiers modList) throws java.io.IOException
- Throws:
java.io.IOException
-
getCompilationUnit
public CompilationUnit getCompilationUnit(java.lang.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.- 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 java.io.IOException
- Throws:
java.io.IOException
-
getEnumDeclaration
private EnumDeclaration getEnumDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo) throws java.io.IOException
- Throws:
java.io.IOException
-
getFormalParameters
private java.util.List<FormalParameter> getFormalParameters(CompilationUnit cu, java.util.List<Token> tokenList) throws java.io.IOException
- Throws:
java.io.IOException
-
getInterfaceBody
private void getInterfaceBody(CompilationUnit cu, Scanner s, NormalInterfaceDeclaration iDec) throws java.io.IOException
- Throws:
java.io.IOException
-
getInterfaceMemberDecl
private void getInterfaceMemberDecl(CompilationUnit cu, Scanner s, NormalInterfaceDeclaration iDec, Modifiers modList) throws java.io.IOException
- Throws:
java.io.IOException
-
getMemberDecl
private void getMemberDecl(CompilationUnit cu, Scanner s, NormalClassDeclaration classDec, Modifiers modList) throws java.io.IOException
- Throws:
java.io.IOException
-
getModifierList
private Modifiers getModifierList(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
getNormalClassDeclaration
private NormalClassDeclaration getNormalClassDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo) throws java.io.IOException
- Throws:
java.io.IOException
-
getNormalInterfaceDeclaration
private NormalInterfaceDeclaration getNormalInterfaceDeclaration(CompilationUnit cu, Scanner s, TypeDeclarationContainer addTo) throws java.io.IOException
- Throws:
java.io.IOException
-
getQualifiedIdentifier
private java.lang.String getQualifiedIdentifier(Scanner scanner) throws java.io.IOException
- Throws:
java.io.IOException
-
getThrownTypeNames
private java.util.List<java.lang.String> getThrownTypeNames(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
getType
private Type getType(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
getType
private Type getType(CompilationUnit cu, Scanner s, boolean pushbackOnUnexpected) throws java.io.IOException
- Throws:
java.io.IOException
-
getTypeArgument
private TypeArgument getTypeArgument(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
getTypeArguments
private java.util.List<TypeArgument> getTypeArguments(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
getTypeDeclaration
private TypeDeclaration getTypeDeclaration(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
getTypeParameter
private TypeParameter getTypeParameter(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
getTypeParameters
private java.util.List<TypeParameter> getTypeParameters(CompilationUnit cu, Scanner s) throws java.io.IOException
- Throws:
java.io.IOException
-
isDebug
private static boolean isDebug()
-
isModifier
private int isModifier(Token t)
-
log
private static void log(java.lang.String msg)
-
-