コード例 #1
0
 /**
  * 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);
     }
   }
 }
コード例 #2
0
  /**
   * Provides custom completion for specifying the type of a property, taking into account the path
   * if the name is qualified
   *
   * @see
   *     org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completeTypeRule_Type(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_Type(
      EObject model,
      Assignment assignment,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {

    Namespace namespace =
        ((Property) ContextElementUtil.getContextElement(model.eResource())).getNamespace();
    if (model instanceof TypeRule) {
      TypeRule typeRule = (TypeRule) model;
      QualifiedName path = typeRule.getPath();
      while (path.getRemaining() != null) {
        path = path.getRemaining();
      }
      namespace = path.getPath();
    } else if (!(model instanceof PortRule)) {
      return;
    }
    for (NamedElement n : namespace.getOwnedMembers()) {
      if (n instanceof Classifier) {
        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);
        }
      }
    }
  }