Package org.nuiton.eugene
Class GeneratorUtil
- java.lang.Object
-
- org.nuiton.eugene.GeneratorUtil
-
- Direct Known Subclasses:
JavaGeneratorUtil
public class GeneratorUtil extends Object
GeneratorUtil.Created: 25 aout 2003
- Author:
- Benjamin Poussin - poussin@codelutin.com
-
-
Field Summary
Fields Modifier and Type Field Description static StringSERIAL_VERSION_UID
-
Constructor Summary
Constructors Constructor Description GeneratorUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static FilechangeExtension(File file, String newExtension)Recupère le fichier dans le même répertoire que le fichier donné et dont on a changé l'extension.static StringchangeExtension(String name, String newExtension)Change l'extension du fichier en entrée avec la nouvelle extensionstatic StringcomputeSerialVersionUID(ObjectModelClass clazz)Deprecated.since 2.4, prefer use the methodgenerateSerialVersionUID(ObjectModelClassifier)static StringconvertConstantNameToVariableName(String constantName)Convertit un nom de constante en nom de variable.static StringconvertVariableNameToConstantName(String variableName)Convertit un nom de variable en nom de constante.static StringfindTagValue(String tagName, ObjectModelElement element, Model model)Deprecated.since 2.9 (will be remove in version 3.0), prefer use nowTagValueUtil.findTagValue(TagValueMetadata, WithTagValuesOrStereotypes...)static longgenerateSerialVersionUID(ObjectModelClassifier classifier)Generates the serialVersionUID of the givenclassifier.static StringgetAssocAttrName(ObjectModelAttribute attr)Renvoie le nom de l'attribut de classe d'association en fonction des cas: Si l'attribut porte le même nom que le type (extrémité inverse de l'association), on lui ajoute le nom de la classe d'associationstatic StringgetCastValue(String type, String o)static Collection<ObjectModelClassifier>getClassifiers(ObjectModel model, String packageName)return all classifiers belonging to the given package recursively.static StringgetClassNameFromQualifiedName(String qualifiedName)static StringgetFilenameFromQualifiedName(String qualifiedName)static StringgetFormatingExpression(String type, String attributeStringName)static StringgetHashCodeExpression(String type, String o)static StringgetInitValue(String type)static StringgetInitValue(ObjectModelAttribute attribute)return an init value for the specified attributestatic StringgetOperationParametersListName(ObjectModelOperation operation)Used to return theoperationparameter names as a string separated by a comma.static StringgetParentPackageName(String packageName)return parent package of given package (return given package if it is a root package) eg : org.nuiton.eugene.models -> org.nuiton.eugene eg : org -> org warning : org.nuiton.eugenestatic StringgetParsingExpression(String type, String attributeStringName)static StringgetPrimitiveWrapType(String type)static FilegetRelativeFile(File inputDirectory, File outputDirectory, File file)Recupère le fichier mirroir du fichierfiledonnée qui est dans l'arborescence deinputDirectorydans le répertoireouputDirectory.static StringgetSimpleName(String str)Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics.static StringgetSimpleName(String str, boolean removeGenericDefinition)Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics.static Set<String>getTypesList(String str)Parse a fully qualified generic java type, and extract each imbricated types.static booleanhasDocumentation(ObjectModelElement element)Indique si l'élément spécifié dispose de documentationstatic booleanhasStereotype(ObjectModelElement element, String stereotype)static booleanisBooleanPrimitive(String type)Tests if an type is a boolean primitive.static booleanisBooleanPrimitive(ObjectModelAttribute attribute)Tests if an attribute is a boolean primitive.static booleanisComposition(ObjectModelAttribute attribute)static booleanisFirstAttribute(ObjectModelAttribute attr)Renvoie si l'attribut passé en paramètre est premier lexicographiquement par rapport à son attribut inverse (si celui ci existe).static booleanisNMultiplicity(int multiplicity)static booleanisNMultiplicity(ObjectModelAttribute attribute)static booleanisOneMultiplicity(ObjectModelAttribute attribute)static booleanisPrimitiveAttributeType(ObjectModelAttribute attribute)Indicates if the specified attribute has a primitive type (byte, boolean, ...)static booleanisPrimitiveType(String type)Tests if the given type is a primitive type.static booleannotEmpty(String s)Deprecated.since 2.3, use the methodStringUtils.isNotEmpty(CharSequence)static StringremoveAnyGenericDefinition(String str)Remove any generics definition at the beginning of a string.static StringremoveGenericDefinition(String str)Remove any generics definition at the beginning of a string.static booleansimpleNamesEquals(String first, String second)Check if simple name are equals (removing any generic definition)static String[]splitGenericDefinition(String str)static StringtoLowerCaseFirstLetter(String word)
-
-
-
Field Detail
-
SERIAL_VERSION_UID
public static final String SERIAL_VERSION_UID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getParentPackageName
public static String getParentPackageName(String packageName)
return parent package of given package (return given package if it is a root package) eg : org.nuiton.eugene.models -> org.nuiton.eugene eg : org -> org warning : org.nuiton.eugene. -> org.nuiton.eugene- Parameters:
packageName- package- Returns:
- parent package of given package
-
getClassNameFromQualifiedName
public static String getClassNameFromQualifiedName(String qualifiedName)
- Parameters:
qualifiedName- the fully qualified name to test- Returns:
- class name fr given fully qualified name (return given name if it is not fully qualified) eg : org.nuiton.eugene.models.ObjectClass -> ObjectClass eg : ObjectClass-> ObjectClass
-
getFilenameFromQualifiedName
public static String getFilenameFromQualifiedName(String qualifiedName)
- Parameters:
qualifiedName- the fully qualified name to test- Returns:
- the filename for the given qualified name.
-
getClassifiers
public static Collection<ObjectModelClassifier> getClassifiers(ObjectModel model, String packageName)
return all classifiers belonging to the given package recursively. The Collection may be empty.- Parameters:
model- the model where to look atpackageName- the package name to set for classifiers- Returns:
- a Collection containing all classifiers belonging to the given package recursively.
- See Also:
ObjectModelClassifier
-
isPrimitiveAttributeType
public static boolean isPrimitiveAttributeType(ObjectModelAttribute attribute)
Indicates if the specified attribute has a primitive type (byte, boolean, ...)- Parameters:
attribute- the attribute to test- Returns:
- true if the attribute has a primitive type
-
isPrimitiveType
public static boolean isPrimitiveType(String type)
Tests if the given type is a primitive type.- Parameters:
type- the type to test- Returns:
trueif given type is primitive.- Since:
- 2.3.2
-
getPrimitiveWrapType
public static String getPrimitiveWrapType(String type)
- Parameters:
type- primitive type- Returns:
- the wrap primitive type
- Since:
- 3.0
-
getInitValue
public static String getInitValue(ObjectModelAttribute attribute)
return an init value for the specified attribute- Parameters:
attribute- the attribute to test- Returns:
- a String with the corresponding attribute init value
-
isNMultiplicity
public static boolean isNMultiplicity(ObjectModelAttribute attribute)
- Parameters:
attribute- the attribute to test- Returns:
- vrai si la cardinalite de l'attribut est superieur a 1, c-a-d si MaxMultiplicity == -1 ou > 1
-
isNMultiplicity
public static boolean isNMultiplicity(int multiplicity)
-
isOneMultiplicity
public static boolean isOneMultiplicity(ObjectModelAttribute attribute)
- Parameters:
attribute- the attribute to test- Returns:
- true is the multiplicity of the given attribute is exactly 1
-
toLowerCaseFirstLetter
public static String toLowerCaseFirstLetter(String word)
- Parameters:
word- the word to decapitalize- Returns:
- the decapitalized word
-
isComposition
public static boolean isComposition(ObjectModelAttribute attribute)
- Parameters:
attribute- the attribute to test- Returns:
- true if the given attribute is a composition (composant of the reverse attribute)
-
isBooleanPrimitive
public static boolean isBooleanPrimitive(ObjectModelAttribute attribute)
Tests if an attribute is a boolean primitive.- Parameters:
attribute- the attribute to test- Returns:
trueif attribute is a primitive boolean- Since:
- 2.4.1
-
isBooleanPrimitive
public static boolean isBooleanPrimitive(String type)
Tests if an type is a boolean primitive.- Parameters:
type- the type to test- Returns:
trueif type is a primitive boolean- Since:
- 2.11
-
getParsingExpression
public static String getParsingExpression(String type, String attributeStringName)
-
getFormatingExpression
public static String getFormatingExpression(String type, String attributeStringName)
-
getOperationParametersListName
public static String getOperationParametersListName(ObjectModelOperation operation)
Used to return theoperationparameter names as a string separated by a comma. Usefull for operation call in templates writing.- Parameters:
operation- to treate- Returns:
- the string corresponding to the list of operation parameter names separated by a ', '.
-
isFirstAttribute
public static boolean isFirstAttribute(ObjectModelAttribute attr)
Renvoie si l'attribut passé en paramètre est premier lexicographiquement par rapport à son attribut inverse (si celui ci existe).- Parameters:
attr- L'attribut dont on veut savoir s'il est le premier- Returns:
- true, si l'attribut est premier (lexico ou pas de reverse attribute), false dans les autres cas
-
hasDocumentation
public static boolean hasDocumentation(ObjectModelElement element)
Indique si l'élément spécifié dispose de documentation- Parameters:
element- l'élément à tester- Returns:
- true s'il y a documentation, false sinon
-
notEmpty
@Deprecated public static boolean notEmpty(String s)
Deprecated.since 2.3, use the methodStringUtils.isNotEmpty(CharSequence)Indique si la chaine de caratère n'est pas vide (null ou "")- Parameters:
s- la chaine de caractères à tester- Returns:
- true si
sn'est pas vide
-
findTagValue
@Deprecated public static String findTagValue(String tagName, ObjectModelElement element, Model model)
Deprecated.since 2.9 (will be remove in version 3.0), prefer use nowTagValueUtil.findTagValue(TagValueMetadata, WithTagValuesOrStereotypes...)Cherches et renvoie la valeur du tagvalue indique sur cet element, sinon sur le model.- Parameters:
tagName- le nom du tagelement- l'élément à testermodel- le modele utilisé- Returns:
- la valeur du tagValue ou null
-
hasStereotype
public static boolean hasStereotype(ObjectModelElement element, String stereotype)
-
computeSerialVersionUID
@Deprecated public static String computeSerialVersionUID(ObjectModelClass clazz)
Deprecated.since 2.4, prefer use the methodgenerateSerialVersionUID(ObjectModelClassifier)For the given class and its attributes, this method computes a serialVersionUID. Exemple, returns "123456789L". This id will change only if the type or the order of an attribute changes.- Parameters:
clazz- the class to use- Returns:
- the generated serialVersionUID
-
getSimpleName
public static String getSimpleName(String str)
Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics.See JUnit test for matching expressions.
- Parameters:
str- FullQualifiedName for an attribute type (for exemple)- Returns:
- the simple name associated to the str given
-
getSimpleName
public static String getSimpleName(String str, boolean removeGenericDefinition)
Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics.See JUnit test for matching expressions.
- Parameters:
str- fullQualifiedName for an attribute type (for exemple)removeGenericDefinition- a flag to remove any generic definition at the beginning of the expression- Returns:
- the simple name associated to the str given
- Since:
- 2.3
-
removeGenericDefinition
public static String removeGenericDefinition(String str)
Remove any generics definition at the beginning of a string.For example :
<T> T -> T
- Parameters:
str- the string to parse- Returns:
- the string without any
- Since:
- 2.3
-
removeAnyGenericDefinition
public static String removeAnyGenericDefinition(String str)
Remove any generics definition at the beginning of a string.For example :
<T> T -> T
- Parameters:
str- the string to parse- Returns:
- the string without any
- Since:
- 2.6.3
-
splitGenericDefinition
public static String[] splitGenericDefinition(String str)
- Parameters:
str- the string to parse- Returns:
- the string without any
- Since:
- 2.3.2
-
getTypesList
public static Set<String> getTypesList(String str)
Parse a fully qualified generic java type, and extract each imbricated types.- Parameters:
str- string to parse- Returns:
- set of found types
-
simpleNamesEquals
public static boolean simpleNamesEquals(String first, String second)
Check if simple name are equals (removing any generic definition)- Parameters:
first- first simple name to checksecond- second simple name to check- Returns:
trueif there are equals,falseotherwise
-
convertVariableNameToConstantName
public static String convertVariableNameToConstantName(String variableName)
Convertit un nom de variable en nom de constante.- Parameters:
variableName- le nom de variable a convertir- Returns:
- le nom de la constante à partir du nom de la variable
-
convertConstantNameToVariableName
public static String convertConstantNameToVariableName(String constantName)
Convertit un nom de constante en nom de variable.- Parameters:
constantName- le nom de constante a convertir- Returns:
- le nom de la variable à partir du nom de la constante
- Since:
- 3.0
-
getAssocAttrName
public static String getAssocAttrName(ObjectModelAttribute attr)
Renvoie le nom de l'attribut de classe d'association en fonction des cas: Si l'attribut porte le même nom que le type (extrémité inverse de l'association), on lui ajoute le nom de la classe d'association- Parameters:
attr- l'attribut a traiter- Returns:
- le nom de l'attribut de classe d'association
- Since:
- 2.0.2
-
generateSerialVersionUID
public static long generateSerialVersionUID(ObjectModelClassifier classifier)
Generates the serialVersionUID of the givenclassifier.- Parameters:
classifier- the classifier- Returns:
- the value of the serialVersionUID
-
getRelativeFile
public static File getRelativeFile(File inputDirectory, File outputDirectory, File file)
Recupère le fichier mirroir du fichierfiledonnée qui est dans l'arborescence deinputDirectorydans le répertoireouputDirectory.- Parameters:
inputDirectory- le répertoire de départoutputDirectory- le répertoire ciblefile- le fichier- Returns:
- le fichier mirroir dans le répertoire cible
- Since:
- 1.4.2
-
changeExtension
public static File changeExtension(File file, String newExtension) throws IOException
Recupère le fichier dans le même répertoire que le fichier donné et dont on a changé l'extension.- Parameters:
file- le fichier d'originenewExtension- la nouvelle extension à utiliser- Returns:
- le fichier dont on a changé l'extension
- Throws:
IOException- si aucune extension trouvé dans le fichier d'origine- Since:
- 1.4.2
-
changeExtension
public static String changeExtension(String name, String newExtension) throws IOException
Change l'extension du fichier en entrée avec la nouvelle extension- Parameters:
name- le nom de fichier à transformernewExtension- la nouvelle extension à utiliser- Returns:
- le nouveau nom de fichier
- Throws:
IOException- si aucune extension trouvé dans le fichier d'origine- Since:
- 1.4.2
-
-