Package org.nuiton.eugene.java.extension
Class ImportsManager
- java.lang.Object
-
- org.nuiton.eugene.java.extension.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 Summary
Constructors Constructor Description ImportsManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addImport(Class<?> clazz)
From the given class, add it to the imports list.boolean
addImport(String fqn)
From the given fqn (fully qualified name), add it to the imports list.void
clearImports()
Method to reset imports list.List<String>
getImports(String packageName)
List the imports.int
getLastDotIndex(String fqn)
Obtains the last dot index in the given fqn.String
getReturnType(String returnType)
String
getType(Class<?> clazz)
Accorging to the already added types, returns the type to write in file.String
getType(String fqn)
Accorging to the already added types, returns the type to write in file.
-
-
-
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
-
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
-
-