/**
  * 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);
     }
   }
 }
  @Override
  public void complete_DOUBLE(
      EObject model,
      RuleCall ruleCall,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    ICompletionProposalAcceptor priorityOptimizer = getCustomAcceptor(model, "real", acceptor);

    String proposalText = "0.1";
    ICompletionProposal proposal =
        createCompletionProposal(
            proposalText, proposalText + " - " + ruleCall.getRule().getName(), null, context);
    priorityOptimizer.accept(proposal);
  }
  @Override
  public void complete_BOOL(
      EObject model,
      RuleCall ruleCall,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    ICompletionProposalAcceptor priorityOptimizer = getCustomAcceptor(model, "boolean", acceptor);

    for (String s : new String[] {"true", "false", "yes", "no"}) {
      ICompletionProposal proposal =
          createCompletionProposal(s, s + " - " + ruleCall.getRule().getName(), null, context);

      priorityOptimizer.accept(proposal);
    }
  }
  /**
   * 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);
        }
      }
    }
  }
 @Override
 public void completeMobaGeneratorIDFeature_GeneratorId(
     final EObject model,
     final Assignment assignment,
     final ContentAssistContext context,
     final ICompletionProposalAcceptor acceptor) {
   super.completeMobaGeneratorIDFeature_GeneratorId(model, assignment, context, acceptor);
   final String prefix = context.getPrefix();
   final Map<String, ExtensionGeneratorDelegate.Metadata> allGenerators =
       this.generatorDelegate.readExtentionsMetadataById(this.grammarName, prefix);
   Collection<ExtensionGeneratorDelegate.Metadata> _values = allGenerators.values();
   final Consumer<ExtensionGeneratorDelegate.Metadata> _function =
       (ExtensionGeneratorDelegate.Metadata it) -> {
         StringConcatenation _builder = new StringConcatenation();
         String _id = it.getId();
         String _version = it.getVersion();
         String _versionedIdWithWhitespace = MobaUtil.toVersionedIdWithWhitespace(_id, _version);
         _builder.append(_versionedIdWithWhitespace, "");
         StyledString _createStyledString = this.createStyledString(it);
         Image _image = this.getImage(model);
         ConfigurableCompletionProposal _doCreateProposal =
             this.doCreateProposal(
                 _builder.toString(), _createStyledString, _image, 1000, context);
         acceptor.accept(_doCreateProposal);
       };
   _values.forEach(_function);
 }
 @Override
 public void completeMobaTemplate_Template(
     final EObject model,
     final Assignment assignment,
     final ContentAssistContext context,
     final ICompletionProposalAcceptor acceptor) {
   super.completeMobaTemplate_Template(model, assignment, context, acceptor);
   final ITemplateRepositoryManager manager = this.getManager();
   boolean _notEquals = (!Objects.equal(manager, null));
   if (_notEquals) {
     List<MobaIndexEntry> _availableEntries = manager.getAvailableEntries();
     final Consumer<MobaIndexEntry> _function =
         (MobaIndexEntry it) -> {
           EObject _eContainer = it.eContainer();
           final MobaIndex index = ((MobaIndex) _eContainer);
           String _createProposalValue = this.createProposalValue(index, it);
           StyledString _createStyledString = this.createStyledString(index, it);
           Image _image = this.getImage(it);
           ConfigurableCompletionProposal _doCreateProposal =
               this.doCreateProposal(
                   _createProposalValue, _createStyledString, _image, 1000, context);
           acceptor.accept(_doCreateProposal);
         };
     _availableEntries.forEach(_function);
   }
 }
  @Override
  public void completeMultiplicityRule_Bounds(
      EObject model,
      Assignment assignment,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {

    if (!(model instanceof MultiplicityRule)) {
      return;
    }

    MultiplicityRule multiplicityRule = (MultiplicityRule) model;

    if (multiplicityRule.getBounds().size() == 2) {
      String value = multiplicityRule.getBounds().get(1).getValue();
      try {
        Integer.valueOf(value);
      } catch (Exception e) {
        if (!multiplicityRule.getBounds().get(0).getValue().equals("*")
            && !multiplicityRule.getBounds().get(1).getValue().equals("*")) {
          String completionString = "*";
          String displayString = "*";
          ICompletionProposal completionProposal =
              CompletionProposalUtils.createCompletionProposal(
                  completionString, displayString, context);
          acceptor.accept(completionProposal);
        }
      }
    }
  }
 public void accept(ICompletionProposal proposal) {
   if (proposal instanceof ConfigurableCompletionProposal) {
     Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
     keyword.setValue(proposal.getDisplayString());
     ((ConfigurableCompletionProposal) proposal).setAdditionalProposalInfo(keyword);
     ((ConfigurableCompletionProposal) proposal).setHover(STextProposalProvider.this.getHover());
   }
   delegate.accept(proposal);
 }
 @Override
 public void complete_YesNo(
     EObject model,
     RuleCall ruleCall,
     ContentAssistContext context,
     ICompletionProposalAcceptor acceptor) {
   acceptor.accept(createCompletionProposal("TAK", context));
   acceptor.accept(createCompletionProposal("NIE", context));
 }
 @Override
 public void completeMobaRESTAttribute_KeyString(
     final EObject model,
     final Assignment assignment,
     final ContentAssistContext context,
     final ICompletionProposalAcceptor acceptor) {
   StyledString _displayString_KeyString = this.getDisplayString_KeyString();
   Image _image = this.getImage(model);
   ConfigurableCompletionProposal _doCreateProposal =
       this.doCreateProposal("param1", _displayString_KeyString, _image, 1000, context);
   acceptor.accept(_doCreateProposal);
 }
 @Override
 public void completeMobaDtoEmbeddable_Alias(
     final EObject model,
     final Assignment assignment,
     final ContentAssistContext context,
     final ICompletionProposalAcceptor acceptor) {
   super.completeMobaDtoEmbeddable_Alias(model, assignment, context, acceptor);
   Image _image = this.getImage(model);
   ConfigurableCompletionProposal _doCreateProposal =
       this.doCreateProposal("aliasName", null, _image, 1000, context);
   acceptor.accept(_doCreateProposal);
 }
 @Override
 public void complete_ValidCommand(
     EObject model,
     RuleCall ruleCall,
     ContentAssistContext context,
     ICompletionProposalAcceptor acceptor) {
   super.complete_ValidState(model, ruleCall, context, acceptor);
   for (Command command : stateAndCommandProvider.getAllCommands()) {
     if (command.toString().startsWith(context.getPrefix())) {
       acceptor.accept(createCompletionProposal(command.toString(), context));
     }
   }
 }
  @Override
  public void complete_MultiplicityRule(
      EObject model,
      RuleCall ruleCall,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    String zero_one = "[0..1]";
    String one = "[1]";
    String one_star = "[1..*]";
    String star = "[*]";

    String completionString = "";
    String displayString = "";
    ICompletionProposal completionProposal = null;

    completionString = "" + zero_one.substring(context.getPrefix().length());
    displayString = "" + zero_one;
    completionProposal =
        CompletionProposalUtils.createCompletionProposal(completionString, displayString, context);
    acceptor.accept(completionProposal);

    completionString = "" + one.substring(context.getPrefix().length());
    displayString = "" + one;
    completionProposal =
        CompletionProposalUtils.createCompletionProposal(completionString, displayString, context);
    acceptor.accept(completionProposal);

    completionString = "" + one_star.substring(context.getPrefix().length());
    displayString = "" + one_star + "     ";
    completionProposal =
        CompletionProposalUtils.createCompletionProposal(completionString, displayString, context);
    acceptor.accept(completionProposal);

    completionString = "" + star.substring(context.getPrefix().length());
    displayString = "" + star;
    completionProposal =
        CompletionProposalUtils.createCompletionProposal(completionString, displayString, context);
    acceptor.accept(completionProposal);
  }
 @Override
 public void complete_MobaMuliplicity(
     final EObject model,
     final RuleCall ruleCall,
     final ContentAssistContext context,
     final ICompletionProposalAcceptor acceptor) {
   super.complete_MobaMuliplicity(model, ruleCall, context, acceptor);
   StyledString _displayString_Multiplicity =
       this.getDisplayString_Multiplicity("attName", "the attName for optional");
   Image _image = this.getImage(model);
   ConfigurableCompletionProposal _doCreateProposal =
       this.doCreateProposal("attName", _displayString_Multiplicity, _image, 1001, context);
   acceptor.accept(_doCreateProposal);
   StyledString _displayString_Multiplicity_1 =
       this.getDisplayString_Multiplicity("[*]", "to many");
   Image _image_1 = this.getImage(model);
   ConfigurableCompletionProposal _doCreateProposal_1 =
       this.doCreateProposal("[*]", _displayString_Multiplicity_1, _image_1, 1000, context);
   acceptor.accept(_doCreateProposal_1);
   StyledString _displayString_Multiplicity_2 =
       this.getDisplayString_Multiplicity("[+]", "to many, but at least one");
   Image _image_2 = this.getImage(model);
   ConfigurableCompletionProposal _doCreateProposal_2 =
       this.doCreateProposal("[+]", _displayString_Multiplicity_2, _image_2, 1000, context);
   acceptor.accept(_doCreateProposal_2);
   StyledString _displayString_Multiplicity_3 =
       this.getDisplayString_Multiplicity("[?]", "optional");
   Image _image_3 = this.getImage(model);
   ConfigurableCompletionProposal _doCreateProposal_3 =
       this.doCreateProposal("[?]", _displayString_Multiplicity_3, _image_3, 1000, context);
   acceptor.accept(_doCreateProposal_3);
   StyledString _displayString_Multiplicity_4 =
       this.getDisplayString_Multiplicity("[0..*]", "to many");
   Image _image_4 = this.getImage(model);
   ConfigurableCompletionProposal _doCreateProposal_4 =
       this.doCreateProposal("[0 ..*]", _displayString_Multiplicity_4, _image_4, 1000, context);
   acceptor.accept(_doCreateProposal_4);
 }
 protected void createProposal(
     EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor, Tag tag) {
   String prefix = context.getPrefix();
   if (prefix.trim().startsWith("-") && !prefix.contains("@" + tag.getName())) {
     acceptor.accept(
         createCompletionProposal(
             prefix + tag,
             getStyledDisplayString(model, tag.getName(), tag.getName()),
             getLabelProvider().getImage(tag),
             0,
             "",
             context));
   }
 }
  @Override
  public void complete_HEX(
      EObject model,
      RuleCall ruleCall,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    ICompletionProposalAcceptor priorityOptimizer = getCustomAcceptor(model, "integer", acceptor);

    String proposalText = "0x1";
    ICompletionProposal proposal =
        createCompletionProposal(
            proposalText, proposalText + " - " + ruleCall.getRule().getName(), null, context);

    if (proposal instanceof ConfigurableCompletionProposal) {
      ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
      configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
      configurable.setSelectionLength(proposalText.length() - 2);
      configurable.setAutoInsertable(false);
      configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
    }

    priorityOptimizer.accept(proposal);
  }
  /**
   * 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);
      }
    }
  }
  @Override
  public void complete_ItemName(
      EObject model,
      RuleCall ruleCall,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    super.complete_ItemName(model, ruleCall, context, acceptor);
    ItemRegistry itemRegistry = RuleModelUIActivator.itemRegistryTracker.getService();

    for (Item item : itemRegistry.getItems()) {
      if (item.getName().startsWith(context.getPrefix())) {
        acceptor.accept(createCompletionProposal(item.getName(), context));
      }
    }
  }
 @Override
 public void completeSubsetsRule_Port(
     EObject model,
     Assignment assignment,
     ContentAssistContext context,
     ICompletionProposalAcceptor acceptor) {
   for (Property inherited : UmlPortScopeProvider.retrieveInheritedProperties(model)) {
     if (inherited.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) {
       String completionString = inherited.getName();
       String displayString = PropertyUtil.getLabel(inherited);
       CustomCompletionProposal completionProposal =
           CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix(
               inherited, completionString, displayString, context);
       acceptor.accept(completionProposal);
     }
   }
 }
  private void completeSnippet(
      KeywordProposal proposal,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    XtextTemplateContext templateContext =
        new IndentTemplateContext(
            templateContextType,
            context.getDocument(),
            new Position(
                context.getReplaceRegion().getOffset(), context.getReplaceRegion().getLength()),
            context,
            getScopeProvider());

    Template template =
        new Template(proposal.keyword, proposal.description, "", proposal.pattern, true);
    acceptor.accept(
        new IndentTemplateProposal(
            template, templateContext, context.getReplaceRegion(), proposal.image, 1000));
  }
  @Override
  public void complete_ImageExpression(
      EObject model,
      RuleCall ruleCall,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    Resource res = model.eResource();
    URI uri = res.getURI().appendSegment("..").appendSegment("Images");

    String platformResourceString = uri.toPlatformString(true);
    IFolder folder =
        ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(platformResourceString));
    try {
      IResource[] members = folder.members();
      for (IResource member : members) {
        String proposal = getValueConverter().toString(member.getName(), "STRING");
        ICompletionProposal completionProposal = createCompletionProposal(proposal, context);
        acceptor.accept(completionProposal);
      }
    } catch (CoreException e) {
      log.error(e.getMessage(), e);
    }
  }
 /**
  * Provides custom completion for the specifying the type of a property
  *
  * @see
  *     org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completePropertyRule_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 completePortRule_Type(
     EObject model,
     Assignment assignment,
     ContentAssistContext context,
     ICompletionProposalAcceptor acceptor) {
   List<Classifier> allClassifiers = new ArrayList<Classifier>();
   Namespace namespace =
       (Namespace)
           EcoreUtil.getRootContainer(ContextElementUtil.getContextElement(model.eResource()));
   allClassifiers.addAll(getRecursivelyOwnedClassifiers(namespace));
   allClassifiers.addAll(getRecursivelyImportedClassifiers(namespace));
   for (Classifier c : allClassifiers) {
     if (c.getQualifiedName().toLowerCase().contains(context.getPrefix().toLowerCase())) {
       String displayString = c.getQualifiedName();
       String completionString =
           CompletionProposalUtils.getQualifiedNameLabelWithSufficientDepth(c, namespace);
       ICompletionProposal completionProposal =
           CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix(
               c, completionString, displayString, context);
       acceptor.accept(completionProposal);
     }
   }
 }
 @Override
 public void completeMobaGeneratorIDFeature_GeneratorVersion(
     final EObject model,
     final Assignment assignment,
     final ContentAssistContext context,
     final ICompletionProposalAcceptor acceptor) {
   super.completeMobaGeneratorIDFeature_GeneratorId(model, assignment, context, acceptor);
   final String prefix = context.getPrefix();
   final MobaGeneratorIDFeature feature = ((MobaGeneratorIDFeature) model);
   String _id = feature.getId();
   final Map<String, ExtensionGeneratorDelegate.Metadata> allGenerators =
       this.generatorDelegate.readExtentionsMetadataByVersion(this.grammarName, _id, prefix);
   Collection<ExtensionGeneratorDelegate.Metadata> _values = allGenerators.values();
   final Consumer<ExtensionGeneratorDelegate.Metadata> _function =
       (ExtensionGeneratorDelegate.Metadata it) -> {
         String _version = it.getVersion();
         StyledString _createStyledStringForVersion = this.createStyledStringForVersion(it);
         Image _image = this.getImage(model);
         ConfigurableCompletionProposal _doCreateProposal =
             this.doCreateProposal(_version, _createStyledStringForVersion, _image, 1000, context);
         acceptor.accept(_doCreateProposal);
       };
   _values.forEach(_function);
 }
  private void calculateVersionProposals(
      EObject model,
      ContentAssistContext context,
      ICompletionProposalAcceptor acceptor,
      boolean majorVersionsOnly) {
    ICompositeNode parentNode = NodeModelUtils.findActualNodeFor(model).getParent();
    Iterable<ILeafNode> leafs = parentNode.getLeafNodes();
    Iterable<ILeafNode> nonHidden =
        Iterables.filter(
            leafs,
            new Predicate<ILeafNode>() {

              public boolean apply(ILeafNode node) {
                return !node.isHidden();
              }
            });
    Model bizModel = null;
    EObject curObj = model;
    while (!(curObj instanceof Model) && curObj.eContainer() != null) {
      curObj = curObj.eContainer();
    }
    if (curObj instanceof Model) {
      bizModel = (Model) curObj;
      EList<Import> imports = bizModel.getImports();
      List<String> importedNamespaces =
          Lists.newArrayList(
              Lists.transform(
                  imports,
                  new Function<Import, String>() {

                    public String apply(Import from) {
                      return from.getImportedNamespace().replaceAll("\\.\\*", "");
                    }
                  }));
      Iterator<ILeafNode> leafIt = nonHidden.iterator();
      if (model.eContainer() instanceof CapabilityRef) {
        CapabilityRef capRef = (CapabilityRef) model.eContainer();
        boolean versionConstraintFound = false;
        StringBuilder nameParts = new StringBuilder();
        while (leafIt.hasNext() && !versionConstraintFound) {
          ILeafNode curNode = leafIt.next();
          if (curNode.getSemanticElement() instanceof VersionRef) versionConstraintFound = true;
          else nameParts.append(curNode.getText());
        }
        String typeName = nameParts.toString().trim().replaceAll("\\[\\]", "").trim();
        final List<String> classNames =
            Lists.newArrayList(
                BusinessDslPackage.Literals.SIMPLE_CAPABILITY.getName(),
                BusinessDslPackage.Literals.CAPABILITY_VARIANT.getName());
        Iterable<String> canditateVersions =
            getCanditateVersions(typeName, classNames, importedNamespaces, majorVersionsOnly);
        for (String version : canditateVersions) {
          acceptor.accept(createCompletionProposal(version, context));
        }
      } else if (model.eContainer() instanceof ServiceRef) {
        ServiceRef capRef = (ServiceRef) model.eContainer();
        boolean versionConstraintFound = false;
        StringBuilder nameParts = new StringBuilder();
        while (leafIt.hasNext() && !versionConstraintFound) {
          ILeafNode curNode = leafIt.next();
          if (curNode.getSemanticElement() instanceof VersionRef) versionConstraintFound = true;
          else nameParts.append(curNode.getText());
        }
        String typeName = nameParts.toString().trim().replaceAll("\\[\\]", "").trim();
        Iterable<String> canditateVersions =
            getCanditateVersions(
                typeName,
                ServiceDslPackage.Literals.SERVICE.getName(),
                importedNamespaces,
                majorVersionsOnly);
        for (String version : canditateVersions) {
          acceptor.accept(createCompletionProposal(version, context));
        }
      } else if (model.eContainer() instanceof EventRef) {
        EventRef eventRef = (EventRef) model.eContainer();
        boolean versionConstraintFound = false;
        StringBuilder nameParts = new StringBuilder();
        while (leafIt.hasNext() && !versionConstraintFound) {
          ILeafNode curNode = leafIt.next();
          if (curNode.getSemanticElement() instanceof VersionRef) versionConstraintFound = true;
          else nameParts.append(curNode.getText());
        }
        String typeName = nameParts.toString().trim().replaceAll("\\[\\]", "").trim();
        final List<String> classNames =
            Lists.newArrayList(
                ServiceDslPackage.Literals.EVENT.getName(),
                ServiceDslPackage.Literals.EVENT.getName());
        Iterable<String> canditateVersions =
            getCanditateVersions(typeName, classNames, importedNamespaces, majorVersionsOnly);
        for (String version : canditateVersions) {
          acceptor.accept(createCompletionProposal(version, context));
        }
      } else if (model.eContainer() instanceof OperationRef) {
        boolean versionConstraintFound = false;
        StringBuilder nameParts = new StringBuilder();
        while (leafIt.hasNext() && !versionConstraintFound) {
          ILeafNode curNode = leafIt.next();
          if (curNode.getSemanticElement() instanceof VersionRef) versionConstraintFound = true;
          else nameParts.append(curNode.getText());
        }
        String typeName = nameParts.toString().trim().replaceAll("\\[\\]", "").trim();
        String[] opNameParts = typeName.split("\\.");
        if (opNameParts.length > 1) {
          typeName = typeName.replaceAll("\\." + opNameParts[opNameParts.length - 1], "");
        }
        String className = ServiceDslPackage.Literals.SERVICE.getName();
        Iterable<String> canditateVersions =
            getCanditateVersions(typeName, className, importedNamespaces, majorVersionsOnly);
        for (String version : canditateVersions) {
          acceptor.accept(createCompletionProposal(version, context));
        }
      } else {
        if (majorVersionsOnly) acceptor.accept(createCompletionProposal("1", context));
        else acceptor.accept(createCompletionProposal("1.0", context));
      }
    }
  }
 public boolean canAcceptMoreProposals() {
   return delegate.canAcceptMoreProposals();
 }
Beispiel #26
0
 @Override
 public void complete_TEXT(
     EObject model,
     RuleCall ruleCall,
     ContentAssistContext context,
     ICompletionProposalAcceptor acceptor) {
   acceptor.accept(new CompletionProposal("#{  }", context.getOffset(), 0, 3));
   acceptor.accept(new CompletionProposal("#render ()", context.getOffset(), 0, 8));
   acceptor.accept(
       new CompletionProposal(
           "#if()\n    \n#end", context.getOffset(), 0, 4, null, "#if() #end", null, null));
   acceptor.accept(
       new CompletionProposal(
           "#if()\n    \n#else\n    \n#end",
           context.getOffset(),
           0,
           4,
           null,
           "#if() #else #end",
           null,
           null));
   acceptor.accept(
       new CompletionProposal(
           "#if()\n    \n#elseif()\n    \n#else\n    \n#end",
           context.getOffset(),
           0,
           4,
           null,
           "#if() #elseif() #else #end",
           null,
           null));
   acceptor.accept(
       new CompletionProposal(
           "#for()\n    \n#end", context.getOffset(), 0, 5, null, "#for() #end", null, null));
   acceptor.accept(
       new CompletionProposal(
           "#while()\n    \n#end", context.getOffset(), 0, 7, null, "#while() #end", null, null));
   acceptor.accept(
       new CompletionProposal(
           "#do\n    \n#end #while()",
           context.getOffset(),
           0,
           21,
           null,
           "#do #end #while()",
           null,
           null));
   acceptor.accept(new CompletionProposal("$()", context.getOffset(), 0, 2));
   acceptor.accept(new CompletionProposal("$?()", context.getOffset(), 0, 3));
   acceptor.accept(new CompletionProposal("$\\html()", context.getOffset(), 0, 7));
   acceptor.accept(new CompletionProposal("$?\\html()", context.getOffset(), 0, 8));
   acceptor.accept(new CompletionProposal("$\\js()", context.getOffset(), 0, 5));
   acceptor.accept(new CompletionProposal("$?\\js()", context.getOffset(), 0, 6));
   acceptor.accept(new CompletionProposal("$\\xml()", context.getOffset(), 0, 6));
   acceptor.accept(new CompletionProposal("$?\\xml()", context.getOffset(), 0, 7));
   acceptor.accept(new CompletionProposal("$\\java()", context.getOffset(), 0, 7));
   acceptor.accept(new CompletionProposal("$?\\java()", context.getOffset(), 0, 8));
   acceptor.accept(new CompletionProposal("$\\csv()", context.getOffset(), 0, 6));
   acceptor.accept(new CompletionProposal("$?\\csv()", context.getOffset(), 0, 7));
   acceptor.accept(new CompletionProposal("$\\sql()", context.getOffset(), 0, 6));
   acceptor.accept(new CompletionProposal("$?\\sql()", context.getOffset(), 0, 7));
   acceptor.accept(new CompletionProposal("$\\\\()", context.getOffset(), 0, 4));
   acceptor.accept(new CompletionProposal("$?\\\\()", context.getOffset(), 0, 5));
 }