Class ClassifierFinder


  • @OpenApiAll
    public class ClassifierFinder
    extends java.lang.Object
    Utility class for finding and creating classifiers by simple or qualified name.
    • Constructor Detail

      • ClassifierFinder

        public ClassifierFinder()
    • 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 - project
        name - classifier name (simple or qualified)
        types - classifier types
        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
      • 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 types
        restricted - 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 - project
        name - data type name
        restricted - 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 - project
        name - 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 - project
        name - classifier name
        types - classifier types
        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
      • 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
        Usage:
        • 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 root
        name - name of classifier. If classifier contains "::" then assuming that name is qualified
        createType - 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 resolver
        contextView - context view
        createIfNotFound - 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 - qualifiedName
        type - classifier type
        root - 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 element
        root - 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 find
        createType - class type of namespace to create. Null if do not want to create a namespace
        root - 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