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; } }
protected ST copyNonRuleSubTree(ST subtree) { ST ret = nodeConstructor.newNode(subtree.getInfo()); if (subtree.getChildren()!=null) { for (ST child : subtree.getChildren()) { if (!mapRuleLhsToTree.rightContains(child)) { ret.addChild(copyNonRuleSubTree(child)); } } } mapOrigToGenerated.put(subtree, ret); return ret; }
public void generate() { TreeCopier<I, S, I, S> copier = new TreeCopier<I, S, I, S>( originalTree, new TreeCopier.InfoConverter<S, I>() { @Override public I convert(S os) { return os.getInfo(); } }, nodeConstructor ); copier.copy(); generatedTree = copier.getGeneratedTree(); generatedTree.addChild(treeToPatch); BidirectionalMap<S, S> copierMap = copier.getNodesMap(); mapOriginalToGenerated = new SimpleValueSetMap<>(); for (S node : copierMap.leftSet()) { mapOriginalToGenerated.put(node, copierMap.leftGet(node)); } }
/** * @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; } }
ret.addChild(copySubTree(child));