Class ImportDecl

  • All Implemented Interfaces:
    ASTNode

    public final class ImportDecl
    extends Object
    implements ASTNode
    A single import declaration, either plain or static and either single-type or on-demand.
    • Constructor Detail

      • ImportDecl

        public ImportDecl​(String name,
                          boolean isStatic,
                          boolean isWildcard,
                          SourceLocation location)
        Creates an import.
        Parameters:
        name - the imported name
        isStatic - true for a static import
        isWildcard - true for an on-demand import
        location - the source location, null becomes UNKNOWN
      • ImportDecl

        public ImportDecl​(String name,
                          boolean isStatic,
                          boolean isWildcard)
        Creates an import at an unknown location.
        Parameters:
        name - the imported name
        isStatic - true for a static import
        isWildcard - true for an on-demand import
      • ImportDecl

        public ImportDecl​(String name)
        Creates a plain single-type import at an unknown location.
        Parameters:
        name - the imported name
    • Method Detail

      • getName

        public String getName()
        Returns:
        the name
      • setName

        public void setName​(String name)
        Parameters:
        name - the imported name
      • isStatic

        public boolean isStatic()
        Returns:
        whether static
      • isWildcard

        public boolean isWildcard()
        Returns:
        whether wildcard
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the location
      • getParent

        public ASTNode getParent()
        Description copied from interface: ASTNode
        Gets the parent node in the AST tree.
        Specified by:
        getParent in interface ASTNode
        Returns:
        the parent
      • setParent

        public void setParent​(ASTNode parent)
        Description copied from interface: ASTNode
        Sets the parent node in the AST tree.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the enclosing node
      • regular

        public static ImportDecl regular​(String name)
        Creates a single-type import.
        Parameters:
        name - the fully qualified type name
        Returns:
        the import
      • staticImport

        public static ImportDecl staticImport​(String name)
        Creates a single static member import.
        Parameters:
        name - the fully qualified member name
        Returns:
        the import
      • wildcard

        public static ImportDecl wildcard​(String packageName)
        Creates an on-demand import.
        Parameters:
        packageName - the package to import from
        Returns:
        the import
      • staticWildcard

        public static ImportDecl staticWildcard​(String className)
        Creates a static on-demand import.
        Parameters:
        className - the class whose static members are imported
        Returns:
        the import
      • getPackageName

        public String getPackageName()
        Returns:
        everything before the last dot, or "" if the name has no dot
      • getSimpleName

        public String getSimpleName()
        Returns:
        "*" for a wildcard import, otherwise the segment after the last dot
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor