Class PackageDeclaration

java.lang.Object
org.eclipse.jdt.core.dom.ASTNode
org.eclipse.jdt.core.dom.PackageDeclaration

public class PackageDeclaration extends ASTNode
Package declaration AST node type.
 PackageDeclaration:
    [ Javadoc ] { Annotation } package Name ;
 
Note that the standard AST parser only recognizes a Javadoc comment immediately preceding the package declaration when it occurs in the special package-info.java compilation unit (JLS3 7.4.1.1). The Javadoc comment in that file contains the package description.
Since:
2.0
Restriction:
This class is not intended to be instantiated by clients.
  • Field Details

    • JAVADOC_PROPERTY

      public static final ChildPropertyDescriptor JAVADOC_PROPERTY
      The "javadoc" structural property of this node type (child type: Javadoc) (added in JLS3 API).
      Since:
      3.0
    • ANNOTATIONS_PROPERTY

      public static final ChildListPropertyDescriptor ANNOTATIONS_PROPERTY
      The "annotations" structural property of this node type (element type: Annotation) (added in JLS3 API).
      Since:
      3.1
    • NAME_PROPERTY

      public static final ChildPropertyDescriptor NAME_PROPERTY
      The "name" structural property of this node type (child type: Name).
      Since:
      3.0
  • Method Details

    • propertyDescriptors

      public static List propertyDescriptors(int apiLevel)
      Returns a list of structural property descriptors for this node type. Clients must not modify the result.
      Parameters:
      apiLevel - the API level; one of the AST.JLS* constants
      Returns:
      a list of property descriptors (element type: StructuralPropertyDescriptor)
      Since:
      3.0
    • annotations

      public List annotations()
      Returns the live ordered list of annotations of this package declaration (added in JLS3 API).
      Returns:
      the live list of annotations (element type: Annotation)
      Throws:
      UnsupportedOperationException - if this operation is used in a JLS2 AST
      Since:
      3.1
    • getJavadoc

      public Javadoc getJavadoc()
      Returns the doc comment node (added in JLS3 API).
      Returns:
      the doc comment node, or null if none
      Throws:
      UnsupportedOperationException - if this operation is used in a JLS2 AST
      Since:
      3.0
    • setJavadoc

      public void setJavadoc(Javadoc docComment)
      Sets or clears the doc comment node (added in JLS3 API).
      Parameters:
      docComment - the doc comment node, or null if none
      Throws:
      IllegalArgumentException - if the doc comment string is invalid
      UnsupportedOperationException - if this operation is used in a JLS2 AST
      Since:
      3.0
    • getName

      public Name getName()
      Returns the package name of this package declaration.
      Returns:
      the package name node
    • setName

      public void setName(Name name)
      Sets the package name of this package declaration to the given name.
      Parameters:
      name - the new package name
      Throws:
      IllegalArgumentException - if`:
      • the node belongs to a different AST
      • the node already has a parent
    • resolveBinding

      public IPackageBinding resolveBinding()
      Resolves and returns the binding for the package declared in this package declaration.

      Note that bindings are generally unavailable unless requested when the AST is being built.

      Returns:
      the binding, or null if the binding cannot be resolved