Class ImportDeclaration

java.lang.Object
com.github.javaparser.ast.Node
com.github.javaparser.ast.ImportDeclaration
All Implemented Interfaces:
NodeWithName<ImportDeclaration>, NodeWithRange<Node>, NodeWithTokenRange<Node>, Observable, Visitable, HasParentNode<Node>, Cloneable

public class ImportDeclaration extends Node implements NodeWithName<ImportDeclaration>
An import declaration.
import com.github.javaparser.JavaParser;
import com.github.javaparser.*;
import com.github.javaparser.JavaParser.*;
import static com.github.javaparser.JavaParser.*;
import static com.github.javaparser.JavaParser.parse;

The name does not include the asterisk or the static keyword.

  • Field Details

    • name

      private Name name
    • isStatic

      private boolean isStatic
    • isAsterisk

      private boolean isAsterisk
    • isModule

      private boolean isModule
  • Constructor Details

    • ImportDeclaration

      private ImportDeclaration()
    • ImportDeclaration

      public ImportDeclaration(String name, boolean isStatic, boolean isAsterisk, boolean isModule)
    • ImportDeclaration

      public ImportDeclaration(String name, boolean isStatic, boolean isAsterisk)
      This constructor is kept to avoid breaking existing code creating non-module imports.
    • ImportDeclaration

      public ImportDeclaration(Name name, boolean isStatic, boolean isAsterisk, boolean isModule)
    • ImportDeclaration

      public ImportDeclaration(Name name, boolean isStatic, boolean isAsterisk)
      This constructor is kept to avoid breaking existing code creating non-module imports.
    • ImportDeclaration

      public ImportDeclaration(TokenRange tokenRange, Name name, boolean isStatic, boolean isAsterisk, boolean isModule)
      This constructor is used by the parser and is considered private.
    • ImportDeclaration

      public ImportDeclaration(TokenRange tokenRange, Name name, boolean isStatic, boolean isAsterisk)
      This constructor is kept to avoid breaking existing code creating non-module imports.
  • Method Details

    • accept

      public <R,A> R accept(GenericVisitor<R,A> v, A arg)
      Description copied from interface: Visitable
      Accept method for visitor support.
      Specified by:
      accept in interface Visitable
      Type Parameters:
      R - the type of the return value of the visitor
      A - the type the user argument passed to the visitor
      Parameters:
      v - the visitor implementation
      arg - the argument passed to the visitor (of type A)
      Returns:
      the result of the visit (of type R)
    • accept

      public <A> void accept(VoidVisitor<A> v, A arg)
      Description copied from interface: Visitable
      Accept method for visitor support.
      Specified by:
      accept in interface Visitable
      Type Parameters:
      A - the type the argument passed for the visitor
      Parameters:
      v - the visitor implementation
      arg - any value relevant for the visitor (of type A)
    • isQualified

      private static boolean isQualified(String name)
      Returns true if the specified name is qualified
    • hasAsterisk

      private static boolean hasAsterisk(String name)
      Returns true if the specified name has an asterisk
    • getNameFromString

      private static Name getNameFromString(String name)
      Returns the name of the import. The name can have a qualifier. For example, the java.util.Map class would have a qualifier ‘java.util’ and an identifier ‘name’ and the qualifier would have a qualifier ‘java’ and an identifier ‘util’ and so on.
    • getName

      public Name getName()
      Retrieves the name of the import (.* is not included.)
      Specified by:
      getName in interface NodeWithName<ImportDeclaration>
    • isAsterisk

      public boolean isAsterisk()
      Return if the import ends with "*".
    • isModule

      public boolean isModule()
    • isStatic

      public boolean isStatic()
    • setAsterisk

      public ImportDeclaration setAsterisk(boolean isAsterisk)
    • setName

      public ImportDeclaration setName(Name name)
      Specified by:
      setName in interface NodeWithName<ImportDeclaration>
    • setStatic

      public ImportDeclaration setStatic(boolean isStatic)
    • clone

      public ImportDeclaration clone()
      Overrides:
      clone in class Node
    • getMetaModel

      public ImportDeclarationMetaModel getMetaModel()
      Overrides:
      getMetaModel in class Node
      Returns:
      get JavaParser specific node introspection information.
    • replace

      public boolean replace(Node node, Node replacementNode)
      Overrides:
      replace in class Node
    • setModule

      public ImportDeclaration setModule(boolean isModule)