Class ImportsManager


  • public class ImportsManager
    extends Object
    Class used in generators that allows to manage easily imports. A first-pass allow to register imports, and in a second-pass, returns the type to use in generated code.
    Since:
    2.0.0
    Author:
    athimel (Code Lutin), Tony Chemit - chemit@codelutin.com
    • Constructor Detail

      • ImportsManager

        public ImportsManager()
    • Method Detail

      • addImport

        public boolean addImport​(Class<?> clazz)
        From the given class, add it to the imports list.
        Parameters:
        clazz - the class to import
        Returns:
        true if import add was successful
        See Also:
        addImport(String)
      • addImport

        public boolean addImport​(String fqn)
        From the given fqn (fully qualified name), add it to the imports list. If there is a conflict adding this import, will return false. If reading of the imports has started, this method will return false, unless type does not need to be imported.
        Parameters:
        fqn - the fully qualified name to import
        Returns:
        true if import add was successful
      • getType

        public String getType​(Class<?> clazz)
        Accorging to the already added types, returns the type to write in file. If there is a conflict, returns the fully qualified name, otherwise returns the simple name
        Parameters:
        clazz - the clazz to add
        Returns:
        the fqn or simple name according to in-place imports
        Since:
        2.3.2
      • getType

        public String getType​(String fqn)
        Accorging to the already added types, returns the type to write in file. If there is a conflict, returns the fully qualified name, otherwise returns the simple name
        Parameters:
        fqn - the fully qualified name to add
        Returns:
        the fqn or simple name according to in-place imports
      • getReturnType

        public String getReturnType​(String returnType)
      • getImports

        public List<String> getImports​(String packageName)
        List the imports. This method will remove the useless imports according to the given packageName (no need to import a class in the same package)
        Parameters:
        packageName - the current package name (to avoid useless imports)
        Returns:
        the imports alphabeticaly sorted
      • clearImports

        public void clearImports()
        Method to reset imports list. If imports has been listed, it becomes back possible to add imports.
      • getLastDotIndex

        public int getLastDotIndex​(String fqn)
        Obtains the last dot index in the given fqn.
        Parameters:
        fqn - the fqn to test
        Returns:
        the last index of a dot in given fqn
        Since:
        2.3.2