void createResultNode(final MergeClassLoader mergeClassLoader) throws MergeException { if (nodeClasses == null) { try { result = elem.astNewInstance(); } catch (final Exception e) { throw new MergeException("Cannot merge ASTs", elem, e); } } else { try { final Class<?> merged = mergeClassLoader.mergeNodeClasses(elem .astGetType(), nodeClasses); result = (Node) merged.newInstance(); } catch (final Exception e) { throw new MergeException("Cannot merge AST classes", elem, e); } } }
T newNode; if (node instanceof AbstractSTNode) { newNode = (T) node.astNewInstance(); } else { final Class<?> nodeClass = node.getClass(); newNode = (T) n.astNewInstance();
@SuppressWarnings("unchecked") private static <T extends Node> T cloneNodeState(final T node) { // first create a new node instance final T newNode = (T) node.astNewInstance(); // copy node attributes newNode.astSetAttributes(node.astGetAttributes()); // copy node decoration newNode.astSetDecorations(node.astGetDecorations()); // copy source newNode.astSetSource(node.astGetSource()); return newNode; }