Class DependenciesElementScanner

All Implemented Interfaces:
ElementVisitor<Set<PackageDependency>,​String>

public class DependenciesElementScanner extends ElementScanner9<Set<PackageDependency>,​String>
JavaDoc ElementScanner to detect dependencies.

The packages of the dependencies are remembered and the result of the scan is a set of PackageDependency objects. Duplicate dependencies will be automatically removed because the result is a set.

Author:
Sjoerd Talsma
  • Constructor Details

    • DependenciesElementScanner

      public DependenciesElementScanner(DocletEnvironment docEnv, Configuration config)
      Constructor to create a new package dependencies scanner.

      The scanner is stateful, the set of package dependencies is collected in the (mutable) ElementScanner6.DEFAULT_VALUE set.

      Parameters:
      docEnv - The doclet environment (required, non-null). This is needed to evalutate whether visited elements are included in the documentation.
      config - The doclet configuration (required, non-null).
  • Method Details

    • visitPackage

      public Set<PackageDependency> visitPackage(PackageElement visitedPackage, String fromPackage)
      Visit a package to evalutate all dependencies from its elements to other packages.

      All elements within the package are visited, with the new fromPackage set to the qualified name of this visited package.

      Specified by:
      visitPackage in interface ElementVisitor<Set<PackageDependency>,​String>
      Overrides:
      visitPackage in class ElementScanner6<Set<PackageDependency>,​String>
      Parameters:
      visitedPackage - The visited package.
      fromPackage - The 'from' package (possibly from parent elements). Ignored in this method, as the scan will continue from the visited package.
      Returns:
      The found package dependencies after scanning the visited package.
    • visitType

      public Set<PackageDependency> visitType(TypeElement visitedType, String fromPackage)
      Visit a type element to add their package dependencies to the current set.

      First, the package of the superclass is added as a dependency. Then, the package of each implemented interface is added as a dependency. Finally, all contained elements within the type are visited for package dependencies.

      Please note, at the moment there is no metadata available in JavaDoc listing the imports of a type. So unfortunately the imports of a type are currently not included in the package dependencies.

      Specified by:
      visitType in interface ElementVisitor<Set<PackageDependency>,​String>
      Overrides:
      visitType in class ElementScanner6<Set<PackageDependency>,​String>
      Parameters:
      visitedType - The visited type.
      fromPackage - The current package (optional, will be resolved from the visited type if null).
      Returns:
      The found package dependencies after scanning the visited type.
    • visitVariable

      public Set<PackageDependency> visitVariable(VariableElement visitedVariable, String fromPackage)
      Visit a variable element (field, constant or method parameter) to add its package dependency to the current set.

      The package of the type of the variable is added as a package dependency.

      Specified by:
      visitVariable in interface ElementVisitor<Set<PackageDependency>,​String>
      Overrides:
      visitVariable in class ElementScanner7<Set<PackageDependency>,​String>
      Parameters:
      visitedVariable - The visited variable.
      fromPackage - The current package.
      Returns:
      The found package dependencies after scanning the visited type.
    • visitExecutable

      public Set<PackageDependency> visitExecutable(ExecutableElement visitedExecutable, String fromPackage)
      Visit an executable element (method, constructor or initializer) to add its package dependency to the current set.

      First, the package of the return type of the executable is added as a package dependency. Then, the packages of all thrown exception types are added as package dependencies. Finally, all child elements of the executable (e.g. parameters) are visited for package dependencies.

      Specified by:
      visitExecutable in interface ElementVisitor<Set<PackageDependency>,​String>
      Overrides:
      visitExecutable in class ElementScanner6<Set<PackageDependency>,​String>
      Parameters:
      visitedExecutable - The visited executable.
      fromPackage - The current package.
      Returns:
      The found package dependencies after scanning the visited executable.
    • visitTypeParameter

      public Set<PackageDependency> visitTypeParameter(TypeParameterElement visitedTypeParameter, String fromPackage)
      Visit a type parameter element (a generic) to add its package dependency to the current set.

      First, the package of the generic type is added as a package dependency. Then, the packages of all declared bounds are added as package dependencies.

      Specified by:
      visitTypeParameter in interface ElementVisitor<Set<PackageDependency>,​String>
      Overrides:
      visitTypeParameter in class ElementScanner6<Set<PackageDependency>,​String>
      Parameters:
      visitedTypeParameter - The visited parameter element.
      fromPackage - The current package.
      Returns:
      The found package dependencies after scanning the visited executable.
    • visitUnknown

      public Set<PackageDependency> visitUnknown(Element visitedUnknown, String fromPackage)
      Overrides visiting any unknown element.

      The default visitor throws exception on unknown elements, this visitor just returns the current package dependencies (without adding any).

      Specified by:
      visitUnknown in interface ElementVisitor<Set<PackageDependency>,​String>
      Overrides:
      visitUnknown in class AbstractElementVisitor6<Set<PackageDependency>,​String>
      Parameters:
      visitedUnknown - The visited unknown element.
      fromPackage - The current package (ignored, as unknown elements are not processed any further).
      Returns:
      The found package dependencies before the unknown element, without adding any.