예제 #1
0
 public static String getParameterList(ParserRule rule, Boolean skipCurrent) {
   boolean currentAsParam = rule.isFragment() && !GrammarUtil.isDatatypeRule(rule);
   if ((skipCurrent || !currentAsParam) && rule.getParameters().isEmpty()) {
     return "";
   }
   StringBuilder result = new StringBuilder();
   result.append("[");
   if (!skipCurrent) {
     if (currentAsParam) {
       result.append("EObject in_current");
       if (!rule.getParameters().isEmpty()) {
         result.append(", ");
       }
     }
   }
   Joiner.on(", ")
       .appendTo(
           result,
           Iterables.transform(
               rule.getParameters(),
               new Function<Parameter, String>() {
                 @Override
                 public String apply(Parameter input) {
                   return "boolean p_" + input.getName();
                 }
               }));
   result.append("] ");
   return result.toString();
 }
예제 #2
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;
 }
예제 #3
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();
 }
예제 #4
0
 @Override
 protected boolean canInspect(ParserRule rule) {
   if (GrammarUtil.isDatatypeRule(rule) || rule.getAlternatives() == null) return false;
   return super.canInspect(rule);
 }
예제 #5
0
 @Override
 public Boolean caseParserRule(ParserRule object) {
   if (GrammarUtil.isDatatypeRule(object)) return Boolean.FALSE;
   return doSwitch(object.getAlternatives());
 }