@Override
 protected String getUnassignedRuleCallToken(
     EObject semanticObject, RuleCall ruleCall, INode node) {
   if (ruleCall.getRule() == grammarAccess.getArrayBracketsRule())
     return getArrayBracketsToken(semanticObject, ruleCall, node);
   else if (ruleCall.getRule() == grammarAccess.getOpSingleAssignRule())
     return getOpSingleAssignToken(semanticObject, ruleCall, node);
   return "";
 }
 @Override
 protected String getUnassignedRuleCallToken(
     EObject semanticObject, RuleCall ruleCall, INode node) {
   if (ruleCall.getRule() == grammarAccess.getASSIGNRule())
     return getASSIGNToken(semanticObject, ruleCall, node);
   else if (ruleCall.getRule() == grammarAccess.getCLOSERule())
     return getCLOSEToken(semanticObject, ruleCall, node);
   else if (ruleCall.getRule() == grammarAccess.getNEWLINERule())
     return getNEWLINEToken(semanticObject, ruleCall, node);
   else if (ruleCall.getRule() == grammarAccess.getOPENRule())
     return getOPENToken(semanticObject, ruleCall, node);
   return "";
 }
 protected String _localVar(final RuleCall it) {
   AbstractRule _rule = it.getRule();
   String _name = _rule.getName();
   String _plus = ("this_" + _name);
   String _plus_1 = (_plus + "_");
   ParserRule _containingParserRule = GrammarUtil.containingParserRule(it);
   List<AbstractElement> _contentsAsList = this.contentsAsList(_containingParserRule);
   int _indexOf = _contentsAsList.indexOf(it);
   return (_plus_1 + Integer.valueOf(_indexOf));
 }
 protected String _toXtext(final RuleCall rc) {
   AbstractRule _rule = rc.getRule();
   String _name = _rule.getName();
   String _elvis = null;
   String _cardinality = rc.getCardinality();
   if (_cardinality != null) {
     _elvis = _cardinality;
   } else {
     _elvis = "";
   }
   return (_name + _elvis);
 }
 protected AbstractElement _predicatedElement(final RuleCall it) {
   AbstractElement _xifexpression = null;
   boolean _isPredicated = it.isPredicated();
   if (_isPredicated) {
     _xifexpression = it;
   } else {
     AbstractRule _rule = it.getRule();
     AbstractElement _alternatives = _rule.getAlternatives();
     EList<AbstractElement> _elements = ((Group) _alternatives).getElements();
     AbstractElement _head = IterableExtensions.<AbstractElement>head(_elements);
     _xifexpression = this.predicatedElement(_head);
   }
   return _xifexpression;
 }
  @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);
    }
  }
示例#8
0
 @Override
 public Boolean caseRuleCall(RuleCall object) {
   AbstractRule calledRule = object.getRule();
   if (calledRule == null || calledRule instanceof TerminalRule || calledRule instanceof EnumRule)
     return Boolean.FALSE;
   ParserRule parserRule = (ParserRule) calledRule;
   if (GrammarUtil.isDatatypeRule(parserRule)) return Boolean.FALSE;
   if (!addVisited(parserRule)) return Boolean.FALSE;
   Multimap<String, AbstractElement> prevAssignedFeatures = assignedFeatures;
   assignedFeatures = newMultimap();
   doSwitch(parserRule.getAlternatives());
   for (String feature : assignedFeatures.keySet()) prevAssignedFeatures.put(feature, object);
   assignedFeatures = prevAssignedFeatures;
   removeVisited(parserRule);
   return Boolean.FALSE;
 }
示例#9
0
  public static AbstractElement getPredicatedElement(AbstractElement element) {
    if (element.isPredicated()) {
      return element;
    }
    if (element instanceof Assignment) {
      return getPredicatedElement(((Assignment) element).getTerminal());
    }
    if (element instanceof RuleCall) {
      final RuleCall ruleCall = (RuleCall) element;
      final AbstractRule calledRule = ruleCall.getRule();
      Group group = (Group) calledRule.getAlternatives();
      AbstractElement first = group.getElements().get(0);
      AbstractElement result = getPredicatedElement(first);
      if (ruleCall.getArguments().isEmpty()) {
        return result;
      }
      EcoreUtil.Copier copier =
          new EcoreUtil.Copier() {
            private static final long serialVersionUID = 1L;

            @Override
            public EObject copy(EObject eObject) {
              if (eObject instanceof ParameterReference) {
                ParameterReference paramRef = (ParameterReference) eObject;
                Parameter parameter = paramRef.getParameter();
                if (calledRule == GrammarUtil.containingRule(parameter)) {
                  for (NamedArgument givenArgument : ruleCall.getArguments()) {
                    if (givenArgument.getParameter() == parameter) {
                      EObject result = copy(givenArgument.getValue());
                      return result;
                    }
                  }
                  throw new IllegalStateException();
                }
              }
              return super.copy(eObject);
            }
          };
      AbstractElement clone = (AbstractElement) copier.copy(result);
      copier.copyReferences();
      return clone;
    }
    return element;
  }
示例#10
0
 @Override
 public Boolean caseRuleCall(RuleCall object) {
   if (!visitedRuleCalls.add(object)) return isOptional(object);
   acceptor.accept(object);
   Set<Parameter> oldConfig = currentConfig;
   try {
     if (!object.getArguments().isEmpty()) {
       currentConfig =
           ParameterConfigHelper.getAssignedArguments(object, getParameterValues(object));
     } else {
       currentConfig = Collections.emptySet();
     }
     Boolean result = doSwitch(object.getRule()) || isOptional(object);
     visitedRuleCalls.remove(object);
     return result;
   } finally {
     currentConfig = oldConfig;
   }
 }
示例#11
0
 public static String getArgumentList(final RuleCall ruleCall, final Boolean skipCurrent) {
   final List<NamedArgument> arguments = ruleCall.getArguments();
   AbstractRule abstractRule = ruleCall.getRule();
   boolean needsCurrent =
       !skipCurrent
           && GrammarUtil.isEObjectFragmentRule(abstractRule)
           && !GrammarUtil.isDatatypeRule(abstractRule);
   if (arguments.isEmpty()) {
     if (needsCurrent) {
       return "[$current]";
     }
     return "";
   }
   ParserRule rule = (ParserRule) abstractRule;
   StringBuilder result = new StringBuilder();
   result.append("[");
   if (needsCurrent) {
     result.append("$current, ");
   }
   Joiner.on(", ")
       .appendTo(
           result,
           Iterables.transform(
               rule.getParameters(),
               new Function<Parameter, String>() {
                 @Override
                 public String apply(Parameter input) {
                   for (NamedArgument argument : arguments) {
                     if (argument.getParameter() == input) {
                       return conditionToAntlr(argument.getValue(), true);
                     }
                   }
                   throw new IllegalStateException(
                       "Cannot find argument for parameter: " + input.getName());
                 }
               }));
   result.append("]");
   return result.toString();
 }
  @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);
  }
 protected boolean _predicated(final RuleCall it) {
   boolean _or = false;
   boolean _isPredicated = it.isPredicated();
   if (_isPredicated) {
     _or = true;
   } else {
     boolean _xblockexpression = false;
     {
       AbstractRule _rule = it.getRule();
       final AbstractElement group = _rule.getAlternatives();
       boolean _xifexpression = false;
       if ((group instanceof Group)) {
         EList<AbstractElement> _elements = ((Group) group).getElements();
         AbstractElement _head = IterableExtensions.<AbstractElement>head(_elements);
         _xifexpression = this.predicated(_head);
       } else {
         _xifexpression = false;
       }
       _xblockexpression = _xifexpression;
     }
     _or = _xblockexpression;
   }
   return _or;
 }
示例#14
0
 public static String getQualifiedNameAsString(RuleCall ruleCall) {
   AbstractRule rule = ruleCall.getRule();
   String result = RuleNames.getRuleNames(rule).getQualifiedName(rule);
   return '"' + result + '"';
 }