예제 #1
0
 @Override
 public Map<String, Entry<V, CommonTree>> fromASTNode(CommonTree treeNode)
     throws ReadingException {
   if (treeNode.token != null && treeNode.token.getType() == headTokenType) {
     if (treeNode.getChildCount() < 1) {
       return null;
     }
     HashMap<String, Entry<V, CommonTree>> kVals = new HashMap<>();
     for (Object obj : treeNode.getChildren()) {
       CommonTree node = (CommonTree) obj;
       if (node.token != null
           && node.token.getType() == SpiderDiagramsParser.PAIR
           && node.getChildCount() == 2) {
         String key = IDTranslator.Instance.fromASTNode((CommonTree) node.getChild(0));
         ElementTranslator<? extends V> translator = null;
         if (typedValueTranslators != null) {
           translator = typedValueTranslators.get(key);
         }
         if (translator == null) {
           if (defaultValueTranslator != null) {
             translator = defaultValueTranslator;
           } else {
             throw new ReadingException(
                 i18n(
                     "ERR_TRANSLATE_UNEXPECTED_KEY_VALUE",
                     key,
                     typedValueTranslators == null ? "" : typedValueTranslators.keySet()),
                 (CommonTree) node.getChild(0));
           }
         }
         V value = translator.fromASTNode((CommonTree) node.getChild(1));
         kVals.put(key, new SimpleEntry<>(value, node));
       } else {
         throw new ReadingException(
             i18n("ERR_TRANSLATE_UNEXPECTED_ELEMENT", i18n("TRANSLATE_KEY_VALUE_PAIR")), node);
       }
     }
     return kVals;
   }
   throw new ReadingException(
       i18n("ERR_TRANSLATE_UNEXPECTED_ELEMENT", i18n(i18n("ERR_TRANSLATE_LIST_OR_SLIST"))),
       treeNode);
 }
예제 #2
0
 @Override
 protected V fromASTChildAt(int i, CommonTree treeNode) throws ReadingException {
   return valueTranslator.fromASTNode(treeNode);
 }