@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 "";
 }
Ejemplo n.º 2
0
 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);
 }
 @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 "";
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
 protected boolean _mustBeParenthesized(final RuleCall it) {
   boolean _or = false;
   boolean _or_1 = false;
   boolean _predicated = this.predicated(it);
   if (_predicated) {
     _or_1 = true;
   } else {
     boolean _isFirstSetPredicated = it.isFirstSetPredicated();
     _or_1 = _isFirstSetPredicated;
   }
   if (_or_1) {
     _or = true;
   } else {
     String _cardinality = it.getCardinality();
     boolean _notEquals = (!Objects.equal(_cardinality, null));
     _or = _notEquals;
   }
   return _or;
 }
Ejemplo n.º 8
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;
   }
 }
Ejemplo n.º 9
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();
 }
Ejemplo n.º 10
0
  @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);
  }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
  @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);
    }
  }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
0
  @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);
  }
Ejemplo n.º 15
0
 public static String getQualifiedNameAsString(RuleCall ruleCall) {
   AbstractRule rule = ruleCall.getRule();
   String result = RuleNames.getRuleNames(rule).getQualifiedName(rule);
   return '"' + result + '"';
 }