int cloneId = tn.getNearestAncestor(SoyFileSetNode.class).getNodeIdGenerator().genId();
// We need to use the unnamespaced name in the command text since we'll be inserting this
// template into a file node that already has a namespace declaration.
TemplateNode clone;
boolean useAttrStyleForName = tn.getCommandText().contains("name=");
if (tn instanceof TemplateBasicNode) {
TemplateBasicNode tbn = (TemplateBasicNode) tn;
String derivedPartialName = (tn.getPartialTemplateName() != null) ?
derivedName.substring(soyFileHeaderInfo.namespace.length()) : null;
clone = new TemplateBasicNode(
cloneId, soyFileHeaderInfo, derivedName, derivedPartialName,
useAttrStyleForName, tbn.isOverride(), tn.isPrivate(),
tn.getAutoescapeMode(), tn.getContentKind(), tn.getSoyDoc(), tn.getSyntaxVersion());
if (! (derivedName.equals(clone.getTemplateName()) &&
Objects.equal(derivedPartialName, clone.getPartialTemplateName()))) {
throw new AssertionError();
}
} else if (tn instanceof TemplateDelegateNode) {
TemplateDelegateNode tdn = (TemplateDelegateNode) tn;
clone = new TemplateDelegateNode(
cloneId, soyFileHeaderInfo, derivedName, tdn.getDelTemplateVariant(),
tdn.getDelPriority(), tn.getAutoescapeMode(), tn.getContentKind(), tn.getSoyDoc());
if (! (derivedName.equals(((TemplateDelegateNode) clone).getDelTemplateName()))) {
throw new AssertionError();
}
} else {
throw new AssertionError("Unknown template node type: " + tn.getClass());
}
clone.setSourceLocation(tn.getSourceLocation());
for (StandaloneNode child : tn.getChildren()) {
clone.addChild(SoytreeUtils.cloneWithNewIds(child));
}
b.add(clone);
}