示例#1
0
 /**
  * Retrieve an element via its qualified name within a package The segments of the package may be
  * non unique due to imports
  *
  * @return the found element, if it exists
  */
 public static NamedElement getQualifiedElement(
     Package root, String remainingPath, String qualifiedName) {
   if (root == null) {
     return null;
   }
   if (!remainingPath.contains(nsSep)) {
     for (NamedElement candidate : root.getMembers()) {
       String name = candidate.getName();
       if ((name != null) && name.equals(remainingPath)) {
         if (candidate.getQualifiedName().equals(qualifiedName)) {
           return candidate;
         }
       }
     }
   } else {
     String segment = remainingPath.split(nsSep)[0];
     String remainder = remainingPath.substring(segment.length() + 2);
     for (Element element : root.getMembers()) {
       if (element instanceof Package) {
         if (((NamedElement) element).getName().equals(segment)) {
           NamedElement foundElement =
               getQualifiedElement((Package) element, remainder, qualifiedName);
           // return, if not found
           if (foundElement != null) {
             return foundElement;
           }
         }
       }
     }
   }
   return null;
 }
  protected List<Type> getChoiceOfValues(org.eclipse.uml2.uml.Package package_) {
    List<Type> choiceOfValues = new ArrayList<Type>();

    Resource eResource = package_.eResource();
    ResourceSet resourceSet = eResource == null ? null : eResource.getResourceSet();

    if (resourceSet != null) {

      try {
        resourceSet.getResource(URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }

      try {
        resourceSet.getResource(URI.createURI(UMLResource.JAVA_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }

      try {
        resourceSet.getResource(URI.createURI(UMLResource.ECORE_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }

      try {
        resourceSet.getResource(URI.createURI(UMLResource.XML_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }
    }

    if (eResource != null) {
      EList<NamedElement> members = package_.getMembers();
      TreeIterator<?> allContents =
          resourceSet == null ? eResource.getAllContents() : resourceSet.getAllContents();

      while (allContents.hasNext()) {
        Object object = allContents.next();

        if (object instanceof Type && !members.contains(object)) {
          Type type = (Type) object;

          if (type.getNearestPackage().makesVisible(type)) {
            choiceOfValues.add(type);
          }
        }
      }
    }

    Collections.<Type>sort(choiceOfValues, new TextComparator<Type>());

    return choiceOfValues;
  }