Package org.jibx.schema.codegen
Class ImportsTracker
java.lang.Object
org.jibx.schema.codegen.ImportsTracker
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 Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Further imports blocked flag.private final TreeSet
Set of imported classes.private final Map
Set of unqualified type full names.private Map
Map from class names in imports set to names used (null
untilgetNameMap()
called).private final String
Package name for classes in source.private final Map
Map from simple names of unqualified types to full names. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Add import for class.void
addLocalType
(String name, String fqname) Add local definition name to those visible in class.Freeze imports and return a list of imports.Get the name to be used for a type.Get map from imported fully-qualified class names to short names.boolean
isQualified
(String fqname) Check if type needs qualified references.
-
Field Details
-
m_packageName
Package name for classes in source. -
m_importedTypes
Set of imported classes. -
m_unqualifiedNameType
Map from simple names of unqualified types to full names. -
m_localTypeName
Set of unqualified type full names. -
m_nameMap
Map from class names in imports set to names used (null
untilgetNameMap()
called). -
m_frozen
private boolean m_frozenFurther imports blocked flag.
-
-
Constructor Details
-
ImportsTracker
Constructor.- Parameters:
pkgname
- containing package name
-
-
Method Details
-
addLocalType
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 namefqname
- fully qualified class name
-
addImport
Add import for class. If the requested import doesn't conflict with the current set it's added.- Parameters:
fqname
- fully qualified class nameforce
- force replacement of current import- Returns:
true
if added as import
-
isQualified
Check if type needs qualified references.- Parameters:
fqname
- fully qualified class name- Returns:
true
if needs qualification
-
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
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 togetNameMap()
, which in turn blocks removing any imports later.- Parameters:
type
- fully-qualified type name- Returns:
- name
-
freeze
Freeze imports and return a list of imports.- Parameters:
cname
- simple name of class (used to identify inner class references)- Returns:
- list
-