public String defaultValue(final AbstractElement ele, final Set<AbstractElement> visited) {
   String _switchResult = null;
   boolean _matched = false;
   if (!_matched) {
     boolean _add = visited.add(ele);
     boolean _not = (!_add);
     if (_not) {
       _matched = true;
       _switchResult = "";
     }
   }
   if (!_matched) {
     boolean _isOptionalCardinality = GrammarUtil.isOptionalCardinality(ele);
     if (_isOptionalCardinality) {
       _matched = true;
       _switchResult = "";
     }
   }
   if (!_matched) {
     if (ele instanceof Alternatives) {
       _matched = true;
       EList<AbstractElement> _elements = ((Alternatives) ele).getElements();
       AbstractElement _head = IterableExtensions.<AbstractElement>head(_elements);
       _switchResult = this.defaultValue(_head, visited);
     }
   }
   if (!_matched) {
     if (ele instanceof Group) {
       _matched = true;
       EList<AbstractElement> _elements = ((Group) ele).getElements();
       final Function1<AbstractElement, String> _function =
           new Function1<AbstractElement, String>() {
             @Override
             public String apply(final AbstractElement e) {
               return AbstractSyntacticSequencer.this.defaultValue(e, visited);
             }
           };
       List<String> _map = ListExtensions.<AbstractElement, String>map(_elements, _function);
       _switchResult = IterableExtensions.join(_map);
     }
   }
   if (!_matched) {
     if (ele instanceof Keyword) {
       _matched = true;
       _switchResult = ((Keyword) ele).getValue();
     }
   }
   if (!_matched) {
     if (ele instanceof RuleCall) {
       _matched = true;
       AbstractRule _rule = ((RuleCall) ele).getRule();
       AbstractElement _alternatives = _rule.getAlternatives();
       _switchResult = this.defaultValue(_alternatives, visited);
     }
   }
   if (!_matched) {
     _switchResult = "";
   }
   return _switchResult;
 }
Example #2
0
 @Override
 public Boolean caseCompoundElement(CompoundElement object) {
   Multimap<String, AbstractElement> prevAssignedFeatures = newMultimap(assignedFeatures);
   for (AbstractElement element : object.getElements()) {
     doSwitch(element);
   }
   if (GrammarUtil.isMultipleCardinality(object)) {
     for (AbstractElement element : object.getElements()) {
       doSwitch(element);
     }
   }
   if (GrammarUtil.isOptionalCardinality(object)) assignedFeatures.putAll(prevAssignedFeatures);
   return Boolean.FALSE;
 }
Example #3
0
 @Override
 public Boolean caseAlternatives(Alternatives object) {
   Multimap<String, AbstractElement> prevAssignedFeatures = assignedFeatures;
   Multimap<String, AbstractElement> mergedAssignedFeatures = LinkedHashMultimap.create();
   for (AbstractElement element : object.getElements()) {
     assignedFeatures = newMultimap(prevAssignedFeatures);
     doSwitch(element);
     mergedAssignedFeatures.putAll(assignedFeatures);
   }
   if (GrammarUtil.isOptionalCardinality(object)) {
     mergedAssignedFeatures.putAll(prevAssignedFeatures);
   }
   assignedFeatures = mergedAssignedFeatures;
   if (GrammarUtil.isMultipleCardinality(object)) {
     prevAssignedFeatures = assignedFeatures;
     for (AbstractElement element : object.getElements()) {
       assignedFeatures = newMultimap(prevAssignedFeatures);
       doSwitch(element);
       mergedAssignedFeatures.putAll(assignedFeatures);
     }
     assignedFeatures = mergedAssignedFeatures;
   }
   return Boolean.FALSE;
 }
Example #4
0
 public boolean isOptional(AbstractElement element) {
   return GrammarUtil.isOptionalCardinality(element);
 }