java.lang.Object
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding
org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ModuleBinding
All Implemented Interfaces:
IUpdatableModule
Direct Known Subclasses:
BinaryModuleBinding, ModuleBinding.UnNamedModule, SourceModuleBinding

public class ModuleBinding extends Binding implements IUpdatableModule
This class serves a dual purpose

First, it canonically represents modules in the world of bindings.

Secondly, it adds a graph layer on top of LookupEnvironment: ModuleBindins are linked through "read" edges as per JPMS (see java.lang.module.Configuration). Additionally, each ModuleBinding holds its own instance of LookupEnviroment, capturing all packages and types that are visible to the current module. As a subset of all visible types, the ModuleBinding knows the set of packages locally declared in this module.

  • Field Details

    • UNNAMED

      public static final char[] UNNAMED
      Name of the unnamed module.
    • ALL_UNNAMED

      public static final char[] ALL_UNNAMED
      Name to represent unnamed modules in --add-exports & --add-reads options.
    • ANY

      public static final char[] ANY
      Module name for package/type lookup that doesn't care about modules.
    • ANY_NAMED

      public static final char[] ANY_NAMED
      Module name for package/type lookup that should look into all named modules.
    • UNOBSERVABLE

      public static final char[] UNOBSERVABLE
      Module name for an unobservable module
    • moduleName

      public char[] moduleName
    • requires

      protected ModuleBinding[] requires
    • requiresTransitive

      protected ModuleBinding[] requiresTransitive
    • exportedPackages

      protected PlainPackageBinding[] exportedPackages
    • openedPackages

      protected PlainPackageBinding[] openedPackages
    • uses

      protected TypeBinding[] uses
    • services

      protected TypeBinding[] services
    • implementations

      public Map<TypeBinding,​TypeBinding[]> implementations
    • mainClassName

      public char[] mainClassName
    • modifiers

      public int modifiers
    • environment

      public LookupEnvironment environment
    • tagBits

      public long tagBits
    • defaultNullness

      public int defaultNullness
    • declaredPackages

      public HashtableOfPackage<PlainPackageBinding> declaredPackages
      Packages declared in this module (indexed by qualified name). We consider a package as declared in a module, if a compilation unit associated with the module declares the package or a subpackage thereof.

      A package in this structures is always represented by a PlainPackageBinding, as opposed to SplitPackageBinding, which are only maintained in the trees below LookupEnvironment.knownPackages.

      This structure is populated early during compilation with all packages that are referenced in exports and opens directives, plus their parent packages.

  • Constructor Details

    • ModuleBinding

      protected ModuleBinding(char[] moduleName, LookupEnvironment existingEnvironment)
  • Method Details

    • getExports

      public PlainPackageBinding[] getExports()
    • getExportRestrictions

      public String[] getExportRestrictions(PackageBinding pack)
    • getOpens

      public PlainPackageBinding[] getOpens()
    • getOpenRestrictions

      public String[] getOpenRestrictions(PackageBinding pack)
    • getImplementations

      public TypeBinding[] getImplementations(TypeBinding binding)
    • getRequires

      public ModuleBinding[] getRequires()
    • getRequiresTransitive

      public ModuleBinding[] getRequiresTransitive()
    • getUses

      public TypeBinding[] getUses()
    • getServices

      public TypeBinding[] getServices()
    • addReads

      public void addReads(char[] requiredModuleName)
      Description copied from interface: IUpdatableModule
      Perform an --add-reads update on the module.
      Specified by:
      addReads in interface IUpdatableModule
    • addExports

      public void addExports(char[] packageName, char[][] targetModules)
      Description copied from interface: IUpdatableModule
      Perform an --add-exports update on the module.
      Specified by:
      addExports in interface IUpdatableModule
    • setMainClassName

      public void setMainClassName(char[] mainClassName)
      Description copied from interface: IUpdatableModule
      Define the ModuleMainClass to be recorded in the generated module-info.class.
      Specified by:
      setMainClassName in interface IUpdatableModule
    • setPackageNames

      public void setPackageNames(SimpleSetOfCharArray packageNames)
      Description copied from interface: IUpdatableModule
      Passes names of packages to be recorded in the ModulePackages classfile attribute.
      Specified by:
      setPackageNames in interface IUpdatableModule
    • getPackageNamesForClassFile

      public char[][] getPackageNamesForClassFile()
      Returns:
      array of names, which may contain nulls.
    • getOrCreateDeclaredPackage

      public PlainPackageBinding getOrCreateDeclaredPackage(char[][] compoundName)
    • addResolvedExport

      public void addResolvedExport(PlainPackageBinding declaredPackage, char[][] targetModules)
    • addResolvedOpens

      public void addResolvedOpens(PlainPackageBinding declaredPackage, char[][] targetModules)
    • recordExportRestrictions

      protected void recordExportRestrictions(PlainPackageBinding exportedPackage, char[][] targetModules)
    • recordOpensRestrictions

      protected void recordOpensRestrictions(PlainPackageBinding openedPackage, char[][] targetModules)
    • dependencyGraphCollector

      public Supplier<Collection<ModuleBinding>> dependencyGraphCollector()
    • dependencyCollector

      public Supplier<Collection<ModuleBinding>> dependencyCollector()
    • getAllRequiredModules

      public ModuleBinding[] getAllRequiredModules()
      Get all the modules required by this module All required modules include modules explicitly specified as required in the module declaration as well as implicit dependencies - those specified as ' requires transitive ' by one of the dependencies
      Returns:
      An array of all required modules
    • name

      public char[] name()
      Answer the name of this module. The unnamed module is identified by UNNAMED.
      Specified by:
      name in interface IUpdatableModule
    • nameForLookup

      public char[] nameForLookup()
      Answer the name of this module as it should be used for package or type lookup. Unnamed and automatic modules answer ANY or ANY_NAMED resp., to signal that lookup should search in all accessible (named) modules.
    • nameForCUCheck

      public char[] nameForCUCheck()
      Answer the name of this module as it should be used for hasCompilationUnit() checks.
    • isPackageExportedTo

      public boolean isPackageExportedTo(PackageBinding pkg, ModuleBinding client)
      Check if the specified package is owned by the current module and exported to the client module. True if the package appears in the list of exported packages and when the export is targeted, the module appears in the targets of the exports statement.
      Parameters:
      pkg - - the package whose visibility is to be checked
      client - - the module that wishes to use the package
      Returns:
      true if the package is visible to the client module, false otherwise
    • getTopLevelPackage

      public PackageBinding getTopLevelPackage(char[] name)
      Return a package binding if there exists a package named name in this module's context and it can be seen by this module. A package can be seen by this module if it is declared in this module or any other module read by this module (JLS 7.4.3 for packages based on JLS 7.3 for compilation units). Package exports are not considered for visibility check (only when checking "uniquely visible" (JLS 7.4.3)).

      The returned package may be a SplitPackageBinding, if more than one package of the given name is visible.

      When asked via the unnamed module or an automatic module all other named modules are considered visible.

    • getVisiblePackage

      public PackageBinding getVisiblePackage(char[][] qualifiedPackageName)
      Answer the package of the given qualified name and visible in this module, or null if no such package exists. Accessibility (based on package exports) is not checked.

      May answer a SplitPackageBinding.

    • canAccess

      public boolean canAccess(PackageBinding pkg)
      Check if the given package is accessible by this module. True when the package is declared in this module or exported by some required module to this module. See isPackageExportedTo(PackageBinding, ModuleBinding)
      Parameters:
      pkg -
      Returns:
      True, if the package is accessible by this module, false otherwise
    • computeUniqueKey

      public char[] computeUniqueKey(boolean isLeaf)
      Overrides:
      computeUniqueKey in class Binding
    • kind

      public int kind()
      Specified by:
      kind in class Binding
    • readableName

      public char[] readableName()
      Specified by:
      readableName in class Binding
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isUnnamed

      public boolean isUnnamed()
    • isAutomatic

      public boolean isAutomatic()
    • isOpen

      public boolean isOpen()
    • isDeprecated

      public boolean isDeprecated()
    • hasUnstableAutoName

      public boolean hasUnstableAutoName()
    • isTransitivelyRequired

      public boolean isTransitivelyRequired(ModuleBinding otherModule)
    • getDefaultNullness

      public int getDefaultNullness()
    • retrieveAnnotationHolder

      public AnnotationHolder retrieveAnnotationHolder(Binding binding, boolean forceInitialization)
    • setAnnotations

      public void setAnnotations(AnnotationBinding[] annotations, boolean forceStore)
      Overrides:
      setAnnotations in class Binding