/**
  * Provides custom completion for a path, taking into account the path which has already been
  * specified
  *
  * @see
  *     org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completeQualifiedName_Remaining(org.eclipse.emf.ecore.EObject,
  *     org.eclipse.xtext.Assignment,
  *     org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext,
  *     org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor)
  */
 @Override
 public void completeQualifiedName_Remaining(
     EObject model,
     Assignment assignment,
     ContentAssistContext context,
     ICompletionProposalAcceptor acceptor) {
   QualifiedName path = (QualifiedName) model;
   for (NamedElement n : path.getPath().getOwnedMembers()) {
     if (n instanceof Package) {
       if (n.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) {
         String completionString = n.getName() + "::";
         String displayString = n.getName() + "::";
         CustomCompletionProposal completionProposal =
             CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix(
                 n, completionString, displayString, context);
         acceptor.accept(completionProposal);
       }
     }
   }
   for (Package p : path.getPath().getImportedPackages()) {
     if (p.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) {
       String completionString = p.getName() + "::";
       String displayString = p.getName() + "::";
       CustomCompletionProposal completionProposal =
           CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix(
               p, completionString, displayString, context);
       acceptor.accept(completionProposal);
     }
   }
 }
  /**
   * Returns the qualified name of the given type.
   *
   * @param type The type
   * @return The qualified name of the given type.
   */
  private String qualifiedName(Type type) {
    String result = null;
    if (type != null && !(type instanceof PrimitiveType)) {
      List<String> packagesName = new ArrayList<String>();

      EObject eContainer = type.eContainer();
      while (eContainer != null
          && eContainer instanceof Package
          && !(eContainer instanceof Model)) {
        Package umlPackage = (Package) eContainer;
        packagesName.add(umlPackage.getName());

        eContainer = umlPackage.eContainer();
      }

      Collections.reverse(packagesName);

      StringBuilder stringBuilder = new StringBuilder();
      for (String packageName : packagesName) {
        stringBuilder.append(packageName);
        stringBuilder.append('.');
      }

      stringBuilder.append(type.getName());

      result = stringBuilder.toString();
      if (JAVA_LANG_TYPES.contains(type.getName())) {
        result = null;
      } else if (JAVA_UTIL_TYPES.contains(type.getName())) {
        result = "java.util." + type.getName();
      }
    }
    return result;
  }
 @Override
 protected org.edna.datamodel.datamodel.Package configure(
     org.eclipse.uml2.uml.Package source,
     org.edna.datamodel.datamodel.Package newInstance) {
   newInstance.setName(NamingUtil.normalize(source.getName()));
   return null;
 }
 private String getModelName(Model existingModel, InstanceSpecification node) {
   String modelName = existingModel.getName() + "_" + node.getName(); // $NON-NLS-1$
   if (configuration != null) {
     modelName += "_" + configuration.getBase_Class().getName(); // $NON-NLS-1$
   } else {
     modelName += "_" + srcModelComponentDeploymentPlan.getName(); // $NON-NLS-1$
   }
   return modelName;
 }
 /** @generated */
 private String getPackage_1000Text(View view) {
   Package domainModelElement = (Package) view.getElement();
   if (domainModelElement != null) {
     return String.valueOf(domainModelElement.getName());
   } else {
     UMLDiagramEditorPlugin.getInstance()
         .logError("No domain element for view with visualID = " + 1000); // $NON-NLS-1$
     return ""; //$NON-NLS-1$
   }
 }
  /**
   * Provides custom completion for the root element in a qualified name
   *
   * @see
   *     org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completeTypeRule_Path(org.eclipse.emf.ecore.EObject,
   *     org.eclipse.xtext.Assignment,
   *     org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext,
   *     org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor)
   */
  @Override
  public void completeTypeRule_Path(
      EObject model,
      Assignment assignment,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    Namespace root =
        (Namespace)
            EcoreUtil.getRootContainer(ContextElementUtil.getContextElement(model.eResource()));

    if (root == null) {
      return;
    }

    // first accept the root Model
    String completionString = root.getName() + "::";
    String displayString = root.getName() + "::";
    // String displayString = c.getName() ;
    CustomCompletionProposal completionProposal =
        CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix(
            root, completionString, displayString, context);
    acceptor.accept(completionProposal);

    // then accepts all packages imported by Model
    List<Package> importedPackages = root.getImportedPackages();
    for (Package p : importedPackages) {
      if (p.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) {
        completionString = p.getName() + "::";
        displayString = p.getName() + "::";
        // String displayString = c.getName() ;
        completionProposal =
            CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix(
                root, completionString, displayString, context);
        acceptor.accept(completionProposal);
      }
    }
  }
Beispiel #7
0
  protected String getViewName(Property property) {
    if (!(generator instanceof ProfileGenerator)) {
      return "";
    }

    org.eclipse.uml2.uml.Property attribute = ((ProfileGenerator) generator).getAttribute(property);

    Package nearestPackage = attribute.getType().getNearestPackage();
    Package rootPackage = nearestPackage;
    while (rootPackage.getNestingPackage() != null) {
      rootPackage = rootPackage.getNestingPackage();
    }

    // TODO : We're assuming the rootPackage has the same name as the context...
    // This layout generator is really only compatible with ProfileGenerator
    return rootPackage.getName() + ":Single " + attribute.getType().getName();
  }
Beispiel #8
0
 /**
  * Get an element via its qualified name. Will find elements from the root model and elements in
  * imported models. Also supports target model in which imports have been copied (while keeping
  * the top-level name)
  *
  * @param root
  * @param qualifiedName
  * @return
  */
 public static NamedElement getQualifiedElement(Package root, String qualifiedName) {
   NamedElement namedElement = null;
   int index = qualifiedName.indexOf(nsSep);
   if (index != -1) {
     // first try using a path without top element (since
     // getQualifiedElement is typically used for
     // imported elements)
     String remainder = qualifiedName.substring(index + 2);
     namedElement = getQualifiedElement(root, remainder, qualifiedName);
   }
   if (namedElement == null) {
     // try with complete name as path name, but assume that the element
     // has been copied into the model,
     // i.e. qualifiedName is prefixed by model name
     namedElement =
         getQualifiedElement(root, qualifiedName, root.getName() + nsSep + qualifiedName);
   }
   return namedElement;
 }
  /**
   * Create a new empty model from an existing model that applies the same profiles and has the same
   * imports
   *
   * @param existingModel
   * @return
   */
  public ModelManagement createTargetModel(Model existingModel, String name, boolean copyImports)
      throws TransformationException {
    ModelManagement mm = new ModelManagement();
    Model newModel = mm.getModel();
    newModel.setName(name);

    try {
      // copy profile application
      for (Profile profile : existingModel.getAppliedProfiles()) {
        // reload profile in resource of new model
        monitor.subTask(Messages.InstantiateDepPlan_InfoApplyProfile + profile.getQualifiedName());

        if (profile.eResource() == null) {
          String profileName = profile.getQualifiedName();
          if (profileName == null) {
            if (profile instanceof MinimalEObjectImpl.Container) {
              URI uri = ((MinimalEObjectImpl.Container) profile).eProxyURI();
              if (uri != null) {
                throw new TransformationException(
                    String.format(Messages.InstantiateDepPlan_CheckInputModelProfileNoRes, uri));
              }
            }
            throw new TransformationException(
                Messages.InstantiateDepPlan_CheckInputModelProfileNoResNoName);
          }
          throw new TransformationException(
              String.format(Messages.InstantiateDepPlan_CheckInputModelProfile3, profileName));
        }

        Resource profileResource = null;
        try {
          profileResource =
              ModelManagement.getResourceSet().getResource(profile.eResource().getURI(), true);
        } catch (WrappedException e) {
          // read 2nd time (some diagnostic errors are raised only
          // once)
          Log.log(
              IStatus.WARNING,
              Log.DEPLOYMENT,
              "Warning: exception in profile.eResource() " + e.getMessage()); // $NON-NLS-1$
          profileResource =
              ModelManagement.getResourceSet().getResource(profile.eResource().getURI(), true);
        }
        Profile newProfileTop = (Profile) profileResource.getContents().get(0);
        Profile newProfile;
        String qname = profile.getQualifiedName();
        if ((qname != null) && qname.contains("::")) { // $NON-NLS-1$
          // profile is a sub-profile within same resource
          // TODO: should Copy class copy profile applications?
          // Should be handled in shallowContainer class.
          // if we put profile/newProfile pair into copy map, copy
          // would find (and copy profile
          // applications in sub-folders
          qname = qname.substring(qname.indexOf("::") + 2); // $NON-NLS-1$
          newProfile = (Profile) Utils.getQualifiedElement(newProfileTop, qname);
        } else {
          newProfile = newProfileTop;
        }
        newProfile.getMember("dummy"); // force profile loading //$NON-NLS-1$
        newModel.applyProfile(newProfile);
      }
    } catch (IllegalArgumentException e) {
      throw new TransformationException(
          Messages.InstantiateDepPlan_IllegalArgumentDuringCopy + e.toString());
    }

    // copy imports (and load resources associated - TODO: might not be
    // necessary)
    // While this is useful in general, it implies that code for imported
    // models
    // has been generated and compiled (for the right target) into a
    // library. This may be
    // quite tedious, unless automatically managed.
    // Therefore we do not activate this option in a first pass of the model
    // transformations.
    if (copyImports) {
      for (Package importedPackage : existingModel.getImportedPackages()) {
        if (importedPackage == null) {
          throw new TransformationException(Messages.InstantiateDepPlan_CheckInputImportPkg);
        }
        if (importedPackage.eResource() == null) {
          String errorMsg = Messages.InstantiateDepPlan_CheckInputImportPkgNoRes;
          if (importedPackage instanceof MinimalEObjectImpl.Container) {
            URI uri = ((MinimalEObjectImpl.Container) importedPackage).eProxyURI();
            if (uri != null) {
              errorMsg += " - URI: " + uri.devicePath(); // $NON-NLS-1$
            }
          }
          throw new TransformationException(errorMsg);
        }
        newModel.createPackageImport(importedPackage);
        monitor.subTask(
            String.format(
                Messages.InstantiateDepPlan_InfoImportPackage, importedPackage.getName()));

        try {
          importedPackage.eResource().load(null);
          newModel.getMember("dummy"); // force loading of model //$NON-NLS-1$
        } catch (IOException e) {
          throw new TransformationException(e.getMessage());
        }
      }
    }

    StUtils.copyStereotypes(existingModel, newModel);

    return mm;
  }