private static <I extends Info, N extends AbstractNode<I, N>, CN extends AbstractConstructionNode<I, CN>, A extends RuleAnnotations> N convertAnnotationTreeToRegularNodes(CN oldLhs, Map<CN, A> oldAnnotationAlignments, Map<N, A> newAnnotationAlignments, AnnotationRuleCompileServices<I, N, CN, A> compilationServices) { N newLhs = compilationServices.newNode(oldLhs.getInfo()); newAnnotationAlignments.put(newLhs, oldAnnotationAlignments.get(oldLhs)); if (oldLhs.hasChildren()) for (CN child : oldLhs.getChildren()) { N newChild = convertAnnotationTreeToRegularNodes(child, oldAnnotationAlignments, newAnnotationAlignments, compilationServices); newLhs.addChild(newChild); newChild.setAntecedent(newLhs); } return newLhs; } }
/** * @param rhs * @param helpMap * @param newMapping * @return */ private N convertRhsToNNodes( CN rhs, BidirectionalMap<N, CN> helpMap, BidirectionalMap<N, N> newMapping) { N newRhs = compilationServices.newNode(rhs.getInfo()); if (rhs.getChildren() != null) for (CN child : rhs.getChildren()) { N newChild = convertRhsToNNodes(child, helpMap, newMapping); newRhs.addChild(newChild); newChild.setAntecedent(newRhs); } // update the new mapping if necessary if (helpMap.rightContains(rhs)) newMapping.put(helpMap.rightGet(rhs), newRhs); return newRhs; }
/** * @param lhs * @param mappings * @param helpMap * @return */ private N convertLhsToNNodes( CN lhs, BidirectionalMap<CN, CN> mappings, BidirectionalMap<N, CN> helpMap) { N newLhs = compilationServices.newNode(lhs.getInfo()); if (lhs.getChildren() != null) for (CN child : lhs.getChildren()) { N newChild = convertLhsToNNodes(child, mappings, helpMap); newLhs.addChild(newChild); newChild.setAntecedent(newLhs); } // update the new mapping if necessary if (mappings.leftContains(lhs)) helpMap.put(newLhs, mappings.leftGet(lhs)); return newLhs; } }