Class 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 Detail

      • nextMemberDeprecated

        private boolean nextMemberDeprecated
        Whether the next member (or class, interface or enum) is deprecated.
    • Constructor Detail

      • ASTFactory

        public ASTFactory()
    • 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 block block is in, or null for 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,
                                   int depth)
                            throws java.io.IOException
        Parses a block of code. This should not be called.
        Parameters:
        parent - The parent code block, or null if none (i.e. this is the body of a method, a static initializer block, etc.).
        m - The method containing this block, or null if 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
      • 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.
      • getFormalParameters

        private java.util.List<FormalParameter> getFormalParameters​(CompilationUnit cu,
                                                                    java.util.List<Token> tokenList)
                                                             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,
                             boolean pushbackOnUnexpected)
                      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)