Class ImportsTracker

java.lang.Object
org.jibx.schema.codegen.ImportsTracker

public class ImportsTracker extends Object
Organizer for imports to a source file. This is a state-based organizer, which allows tentative imports to be overridden up until the point where the map from fully-qualified class names to unqualified names is constructed by calling getNameMap(), then further non-conflicting imports are allowed until the final import list is constructed by calling freeze(String).
Author:
Dennis M. Sosnoski
  • Field Details

    • m_packageName

      private final String m_packageName
      Package name for classes in source.
    • m_importedTypes

      private final TreeSet m_importedTypes
      Set of imported classes.
    • m_unqualifiedNameType

      private final Map m_unqualifiedNameType
      Map from simple names of unqualified types to full names.
    • m_localTypeName

      private final Map m_localTypeName
      Set of unqualified type full names.
    • m_nameMap

      private Map m_nameMap
      Map from class names in imports set to names used (null until getNameMap() called).
    • m_frozen

      private boolean m_frozen
      Further imports blocked flag.
  • Constructor Details

    • ImportsTracker

      public ImportsTracker(String pkgname)
      Constructor.
      Parameters:
      pkgname - containing package name
  • Method Details

    • addLocalType

      public void addLocalType(String name, String fqname)
      Add local definition name to those visible in class. If the name conflicts with an import, the import is removed to force fully-qualified references.
      Parameters:
      name - simple class name
      fqname - fully qualified class name
    • addImport

      protected boolean addImport(String fqname, boolean force)
      Add import for class. If the requested import doesn't conflict with the current set it's added.
      Parameters:
      fqname - fully qualified class name
      force - force replacement of current import
      Returns:
      true if added as import
    • isQualified

      public boolean isQualified(String fqname)
      Check if type needs qualified references.
      Parameters:
      fqname - fully qualified class name
      Returns:
      true if needs qualification
    • getNameMap

      public Map getNameMap()
      Get map from imported fully-qualified class names to short names. Once this method is called, overrides of existing imports are blocked (since the existing imports may have been used), though added non-conflicting imports can still be added.
      Returns:
      map
    • getName

      public String getName(String type)
      Get the name to be used for a type. If the type has been imported this returns the short form of the name; otherwise it just returns the fully-qualified name. This method forces a call to getNameMap(), which in turn blocks removing any imports later.
      Parameters:
      type - fully-qualified type name
      Returns:
      name
    • freeze

      public List freeze(String cname)
      Freeze imports and return a list of imports.
      Parameters:
      cname - simple name of class (used to identify inner class references)
      Returns:
      list