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 - dev@tchemit.fr
-
-
Constructor Summary
Constructors Constructor Description ImportsManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExcludedPattern(String excludePattern)Add the given excluded pattern.booleanaddImport(Class<?> clazz)From the given class, add it to the imports list.booleanaddImport(String fqn)From the given fqn (fully qualified name), add it to the imports list.voidclearImports()Method to reset imports list.booleanexclude(String fqn)Test if the given fully qualified name should be excluded.List<String>getImports(String packageName)List the imports.intgetLastDotIndex(String fqn)Obtains the last dot index in the given fqn.StringgetReturnType(String returnType)StringgetType(Class<?> clazz)Accorging to the already added types, returns the type to write in file.StringgetType(String fqn)Accorging to the already added types, returns the type to write in file.StringimportAndSimplify(String fqn)From the given fqn, add it to import list, then try to give back a simplified version of it.
-
-
-
Method Detail
-
addExcludedPattern
public void addExcludedPattern(String excludePattern)
Add the given excluded pattern.- Parameters:
excludePattern- the excluded pattern- See Also:
exclude(String)
-
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)
-
exclude
public boolean exclude(String fqn)
Test if the given fully qualified name should be excluded.- Parameters:
fqn- fully qualified name to test- Returns:
trueif was excluded by a registeredexcludedPattern,falseotherwise.- See Also:
addExcludedPattern(String)
-
importAndSimplify
public String importAndSimplify(String fqn)
From the given fqn, add it to import list, then try to give back a simplified version of it. If there is a conflict adding this import, will return the fully qualified name.- Parameters:
fqn- the fully qualified name to import and simplify- Returns:
- the simplified import or the fully version if a conflict occurs while adding it
-
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
-
-