Class GeneratorUtil

  • Direct Known Subclasses:
    JavaGeneratorUtil

    public class GeneratorUtil
    extends Object
    GeneratorUtil. Created: 25 aout 2003
    Author:
    Benjamin Poussin - poussin@codelutin.com
    • Constructor Detail

      • GeneratorUtil

        public GeneratorUtil()
    • 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 at
        packageName - 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
      • getInitValue

        public static String getInitValue​(String type)
      • getHashCodeExpression

        public static String getHashCodeExpression​(String type,
                                                   String o)
      • 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 the operation 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 method StringUtils.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
      • computeSerialVersionUID

        @Deprecated
        public static String computeSerialVersionUID​(ObjectModelClass clazz)
        Deprecated.
        since 2.4, prefer use the method generateSerialVersionUID(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 given classifier.
        Parameters:
        classifier - the classifier
        Returns:
        the value of the serialVersionUID