Package com.nomagic.magicdraw.uml
Class ClassifierFinder
- java.lang.Object
-
- com.nomagic.magicdraw.uml.ClassifierFinder
-
@OpenApiAll public class ClassifierFinder extends java.lang.Object
Utility class for finding and creating classifiers by simple or qualified name.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClassifierFinder.SimpleNameResolver
A resolver of simple classifier name.
-
Constructor Summary
Constructors Constructor Description ClassifierFinder()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Classifier
createClassifier(java.lang.String qualifiedName, java.lang.Class<? extends Classifier> type, Namespace root)
Creates a classifier and packages for classifier according qualified classifier name.static Classifier
createClassifier(java.lang.String elementName, java.lang.Class<? extends Classifier> type, java.util.List suggestedByDSL, Namespace root)
static Classifier
findClassifier(Project project, java.lang.String name, java.lang.Class[] types, java.util.Collection restricted, Namespace root)
Looks for a classifier by a given name (simple or qualified).static Classifier
findClassifier(java.lang.String name, java.lang.Class<? extends Classifier>[] types, java.util.Collection restricted, java.util.Collection<Namespace> root)
Looks for a classifier of type by a given name (simple or qualified)static Classifier
findClassifierOrDataType(Project project, java.lang.String name, java.lang.Class<? extends Classifier>[] types, java.util.Collection restricted, Namespace root)
Looks for a classifier of type or standard data type by a given name (simple or qualified).static Classifier
findClassifierOrDataType(Project project, java.lang.String name, java.util.Collection restricted, Namespace root)
Looks for a classifier or standard data type by the given name (simple or qualified).static Classifier
findOrCreateClassifier(Project project, Element context, java.lang.String name, ClassifierFinder.SimpleNameResolver simpleNameResolver)
Searches for a classifier or standard data type with a given name (qualified or simple).static Classifier
findOrCreateClassifier(Project project, Element context, java.lang.String name, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound)
Searches for a classifier or standard data type with a given name (qualified or simple).static Classifier
findOrCreateClassifier(Project project, Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType)
Searches for a classifier or standard data type with a given name (qualified or simple).static Classifier
findOrCreateClassifier(Project project, Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType, java.util.Collection<java.lang.Class<? extends Classifier>> searchType, ClassifierFinder.SimpleNameResolver simpleNameResolver)
Searches for a classifier or standard data type with a given name (qualified or simple)static Classifier
findOrCreateClassifier(Project project, Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType, java.util.Collection<java.lang.Class<? extends Classifier>> searchType, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound)
Searches for a classifier or standard data type with a given name (qualified or simple)static Classifier
findOrCreateClassifier(Project project, Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType, java.util.Collection<java.lang.Class<? extends Classifier>> searchType, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound, PresentationElement contextView)
Searches for a classifier with given name (simple or qualified).static Namespace
findOrCreateNamespaceForElement(java.lang.String qualifiedElementName, java.lang.Class<? extends Namespace> searchType, java.lang.Class<? extends Namespace> createType, Namespace root)
Returns namespace according given qualified element name.static Namespace
findOrCreatePackageForElement(java.lang.String qualifiedElementName, Namespace root)
Creates or finds packages using a qualified name of element in the given root.static Classifier
findStandardDataType(Project project, java.lang.String name, java.util.Collection restricted)
Searches for a standard DataType from UMLStandardProfile or MagicDrawProfile modules.static boolean
isQualifiedName(java.lang.String elementName)
Check if given element name is a qualified name
-
-
-
Method Detail
-
findClassifier
@CheckForNull public static Classifier findClassifier(Project project, java.lang.String name, @CheckForNull java.lang.Class[] types, @CheckForNull java.util.Collection restricted, @CheckForNull Namespace root)
Looks for a classifier by a given name (simple or qualified).- Parameters:
project
- projectname
- classifier name (simple or qualified)types
- classifier typesrestricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root element. Null means whole project- Returns:
- found classifier
-
findClassifier
@CheckForNull public static Classifier findClassifier(java.lang.String name, @CheckForNull java.lang.Class<? extends Classifier>[] types, @CheckForNull java.util.Collection restricted, java.util.Collection<Namespace> root)
Looks for a classifier of type by a given name (simple or qualified)- Parameters:
name
- classifier name (simple or qualified)types
- classifier typesrestricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root elements. Empty means whole project- Returns:
- found classifier
-
findStandardDataType
@CheckForNull public static Classifier findStandardDataType(Project project, java.lang.String name, @CheckForNull java.util.Collection restricted)
Searches for a standard DataType from UMLStandardProfile or MagicDrawProfile modules.- Parameters:
project
- projectname
- data type namerestricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)- Returns:
- found data type or null
-
findClassifierOrDataType
@CheckForNull public static Classifier findClassifierOrDataType(Project project, java.lang.String name, @CheckForNull java.util.Collection restricted, @CheckForNull Namespace root)
Looks for a classifier or standard data type by the given name (simple or qualified).- Parameters:
project
- projectname
- classifier name simple or qualified)restricted
- allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root element. Null means whole project- Returns:
- found classifier
- See Also:
UML2DataTypes.CORE_CLASSIFIERS
-
findClassifierOrDataType
@CheckForNull public static Classifier findClassifierOrDataType(Project project, java.lang.String name, @CheckForNull java.lang.Class<? extends Classifier>[] types, @CheckForNull java.util.Collection restricted, @CheckForNull Namespace root)
Looks for a classifier of type or standard data type by a given name (simple or qualified).- Parameters:
project
- projectname
- classifier nametypes
- classifier typesrestricted
- Allowed DSL elements. Collection should contain stereotypes and/or metaclass classes (java.lang.Class)root
- root element. Null means whole project- Returns:
- found classifier
- See Also:
UML2DataTypes.CORE_CLASSIFIERS
-
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, java.lang.String name, ClassifierFinder.SimpleNameResolver simpleNameResolver)
Searches for a classifier or standard data type with a given name (qualified or simple). Creates UML Class if not found.
-
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, java.lang.String name, ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound)
Searches for a classifier or standard data type with a given name (qualified or simple). Creates UML Class if not found.
-
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType)
Searches for a classifier or standard data type with a given name (qualified or simple). Creates classifier of given type.
-
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(Project project, @CheckForNull Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType, java.util.Collection<java.lang.Class<? extends Classifier>> searchType, @CheckForNull ClassifierFinder.SimpleNameResolver simpleNameResolver)
Searches for a classifier or standard data type with a given name (qualified or simple)
-
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(@CheckForNull Project project, @CheckForNull Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType, java.util.Collection<java.lang.Class<? extends Classifier>> searchType, @CheckForNull ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound)
Searches for a classifier or standard data type with a given name (qualified or simple)
-
findOrCreateClassifier
@CheckForNull public static Classifier findOrCreateClassifier(@CheckForNull Project project, @CheckForNull Element context, java.lang.String name, java.lang.Class<? extends Classifier> createType, java.util.Collection<java.lang.Class<? extends Classifier>> searchType, @CheckForNull ClassifierFinder.SimpleNameResolver simpleNameResolver, boolean createIfNotFound, @CheckForNull PresentationElement contextView)
Searches for a classifier with given name (simple or qualified). If such does not exist, creates a classifier with given name. Priorities:- 1. if qualified name is specified, searching by qualified name
- 2. if context is not null, using context to find nearest Package and searching in it
- 3. Searching in all packages
- 4. Searching for standard data type
- getClassifierFor(root, "java::lang::String", Class.class)
- getClassifierFor(javaLangPackage, "String", Class.class)
- getClassifierFor(ioPackage, "Serializable", Interface.class)
- Parameters:
context
- element used to find nearest Package and use it as rootname
- name of classifier. If classifier contains "::" then assuming that name is qualifiedcreateType
- a classifier type to create if not found (for example Class.class or Interface.class)searchType
- a collection of classifier types to search for (for example Class.class or Interface.class)simpleNameResolver
- simple name resolvercontextView
- context viewcreateIfNotFound
- should new classifier be created if existing is not found
-
createClassifier
@CheckForNull public static Classifier createClassifier(java.lang.String elementName, java.lang.Class<? extends Classifier> type, @CheckForNull java.util.List suggestedByDSL, Namespace root)
-
createClassifier
@CheckForNull public static Classifier createClassifier(java.lang.String qualifiedName, java.lang.Class<? extends Classifier> type, Namespace root)
Creates a classifier and packages for classifier according qualified classifier name.- Parameters:
qualifiedName
- qualifiedNametype
- classifier typeroot
- root namespace- Returns:
- create classifier ir null
-
findOrCreatePackageForElement
@CheckForNull public static Namespace findOrCreatePackageForElement(java.lang.String qualifiedElementName, Namespace root)
Creates or finds packages using a qualified name of element in the given root.- Parameters:
qualifiedElementName
- qualified name of element (not the package!) from a given root elementroot
- parent package where packages will be created- Returns:
- leaf package
-
findOrCreateNamespaceForElement
@CheckForNull public static Namespace findOrCreateNamespaceForElement(java.lang.String qualifiedElementName, java.lang.Class<? extends Namespace> searchType, @CheckForNull java.lang.Class<? extends Namespace> createType, @Nonnull Namespace root)
Returns namespace according given qualified element name.- Parameters:
qualifiedElementName
- qualified name of element inside a namespace (not namespace itself!!!)searchType
- class type of namespace to findcreateType
- class type of namespace to create. Null if do not want to create a namespaceroot
- root- Returns:
- found or created namespace element
-
isQualifiedName
public static boolean isQualifiedName(java.lang.String elementName)
Check if given element name is a qualified name- Parameters:
elementName
- name- Returns:
- true if name is a qualified
-
-