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 String
SERIAL_VERSION_UID
-
Constructor Summary
Constructors Constructor Description GeneratorUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
computeSerialVersionUID(ObjectModelClass clazz)
Deprecated.since 2.4, prefer use the methodgenerateSerialVersionUID(ObjectModelClassifier)
static String
convertConstantNameToVariableName(String constantName)
Convertit un nom de constante en nom de variable.static String
convertVariableNameToConstantName(String variableName)
Convertit un nom de variable en nom de constante.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...)
static long
generateSerialVersionUID(ObjectModelClassifier classifier)
Generates the serialVersionUID of the givenclassifier
.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'associationstatic String
getCastValue(String type, String o)
static Collection<ObjectModelClassifier>
getClassifiers(ObjectModel model, String packageName)
return all classifiers belonging to the given package recursively.static String
getClassNameFromQualifiedName(String qualifiedName)
static String
getFilenameFromQualifiedName(String qualifiedName)
static String
getFormatingExpression(String type, String attributeStringName)
static String
getHashCodeExpression(String type, String o)
static String
getInitValue(String type)
static String
getInitValue(ObjectModelAttribute attribute)
return an init value for the specified attributestatic String
getOperationParametersListName(ObjectModelOperation operation)
Used to return theoperation
parameter names as a string separated by a comma.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.eugenestatic String
getParsingExpression(String type, String attributeStringName)
static String
getPrimitiveWrapType(String type)
static String
getSimpleName(String str)
Suppress packageName from a fullQualifiedName, even if it contains List, Map or other generics.static String
getSimpleName(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 boolean
hasDocumentation(ObjectModelElement element)
Indique si l'élément spécifié dispose de documentationstatic boolean
hasStereotype(ObjectModelElement element, String stereotype)
static boolean
isBooleanPrimitive(String type)
Tests if an type is a boolean primitive.static boolean
isBooleanPrimitive(ObjectModelAttribute attribute)
Tests if an attribute is a boolean primitive.static boolean
isComposition(ObjectModelAttribute attribute)
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).static boolean
isNMultiplicity(int multiplicity)
static boolean
isNMultiplicity(ObjectModelAttribute attribute)
static boolean
isOneMultiplicity(ObjectModelAttribute attribute)
static boolean
isPrimitiveAttributeType(ObjectModelAttribute attribute)
Indicates if the specified attribute has a primitive type (byte, boolean, ...)static boolean
isPrimitiveType(String type)
Tests if the given type is a primitive type.static boolean
notEmpty(String s)
Deprecated.since 2.3, use the methodStringUtils.isNotEmpty(CharSequence)
static String
removeAnyGenericDefinition(String str)
Remove any generics definition at the beginning of a string.static String
removeGenericDefinition(String str)
Remove any generics definition at the beginning of a string.static String[]
splitGenericDefinition(String str)
static String
toLowerCaseFirstLetter(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:
true
if 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:
true
if 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:
true
if 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 theoperation
parameter 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
s
n'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
-
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
-
-