/** * Returns the value of the {@link #INPUT_RESOURCES_DECORATION input * resources} decoration associated to the given node. May be * <code>null</code>. * * @param node a node. * @return a set of name. May be <code>null</code>. */ @SuppressWarnings("unchecked") public static Set<InputResource> getInputResources(final Node node) { return (Set<InputResource>) node .astGetDecoration(INPUT_RESOURCES_DECORATION); }
@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; }
protected void interpolate(final Node node) { final Map<String, String> attributes = node.astGetAttributes(); for (final Map.Entry<String, String> attribute : attributes.entrySet()) { if (attribute.getValue() != null) attribute.setValue(interpolate(node, attribute.getValue())); } node.astSetAttributes(attributes); for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) interpolate(subNode); } } }
/** * Clone the given {@link Node}. Sub nodes of the given node are not * recursively cloned. This imply that the returned node has the same sub * nodes as the given node. * * @param <T> The type of the node. * @param node the node to clone. * @return a clone of the given node. */ public static <T extends Node> T cloneNode(final T node) { final T newNode = cloneNodeState(node); // add sub nodes for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) newNode.astAddNode(subNode); } } return newNode; }
result.astSetSource(elem.astGetSource()); final Map<String, String> resultAttrs = elem.astGetAttributes(); for (final Map.Entry<String, String> entry : superNode.astGetAttributes() .entrySet()) { final String name = entry.getKey(); result.astSetAttributes(resultAttrs); final Map<String, Object> resultDecors = elem.astGetDecorations(); for (final Node superNode : info.getSuperNodes()) { .astGetDecorations().entrySet()) { final String name = entry.getKey(); final Object superValue = entry.getValue(); result.astSetDecorations(resultDecors); result.astAddNode(initMergedNodes(subNodeInfo, infos));
w.write(indent); w.write('<'); w.write(node.astGetType()); final Map attrs = node.astGetAttributes(); final Iterator i = attrs.keySet().iterator(); while (i.hasNext()) { } else { final List<Node> subNodes = new ArrayList<Node>(); final String[] subNodeTypes = node.astGetNodeTypes(); for (final String subNode : subNodeTypes) { final Node[] nodes = node.astGetNodes(subNode); for (final Node n : nodes) { if (n != null) { w.write(indent); w.write("</"); w.write(node.astGetType()); w.write(">\n"); } else {
/** * Attach the given comment to the given node. * * @param node a node. * @param comment the comment to attach. * @throws IllegalArgumentException if the given node already has a decoration * called {@link #COMMENT_DECORATION_NAME}. */ public static void setComment(final Node node, final String comment) { final Object o = node.astGetDecoration(COMMENT_DECORATION_NAME); if (o != null) throw new IllegalArgumentException("Given node already contains a \"" + COMMENT_DECORATION_NAME + "\" decoration."); node.astSetDecoration(COMMENT_DECORATION_NAME, new CommentDecoration( comment, node)); }
/** * @param location the node that can't be evaluated. * @param message a detail message. * @param cause the cause of this exception. */ public EvaluationException(final Node location, final String message, final Throwable cause) { super((location == null) ? message : message + "(at " + location.astGetSource() + ')', cause); }
protected void checkAnnotations(final Node container, final Set<Node> visitedNodes, final Map<Object, Object> context) throws ADLException { if (visitedNodes.add(container)) { if (container instanceof AnnotationContainer) { checkAnnotationContainer((AnnotationContainer) container, context); } for (final String nodeType : container.astGetNodeTypes()) { for (final Node subNode : container.astGetNodes(nodeType)) { if (subNode != null) { checkAnnotations(subNode, visitedNodes, context); } } } } }
private static void addDecoration(final Node container, final AnnotationDecoration decoration) { container.astSetDecoration(ANNOTATION_DECORATION_NAME, decoration); }
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); } } }
protected Node findOverridingNode(final Node superNode, final Node[] nodes, final String nodeType, final Map<String, String> idAttributes) { // get the name of the attribute that identify the one sub node of // type 'nodeType' among others. final String nameAttr = idAttributes.get(nodeType); if (nameAttr != null) { // get the value of attribute 'nameAttr' of node 'superNode' final String superName = superNode.astGetAttributes().get(nameAttr); // Check that the value is not null if (superName != null) { // for each node in 'Nodes' for (final Node node : nodes) { // get the value of attribute 'nameAttr' of node 'node' final String name = node.astGetAttributes().get(nameAttr); // Check that the value is not null if (name == null) continue; if (name.equals(superName)) { return node; } } } } return null; }
.initCause(e); writeUTF(instance.astGetType()); final Class<?>[] nodeInterfaces = cl.getInterfaces();
@SuppressWarnings("unchecked") private static <T extends Node> T cloneGraph(final T node, final Map<Node, Node> clonedNodes) { T clone = (T) clonedNodes.get(node); if (clone == null) { clone = cloneNodeState(node); // add sub nodes for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) clone.astAddNode(cloneGraph(subNode, clonedNodes)); } } clonedNodes.put(node, clone); } return clone; }
@Override public String getMessage() { return (src == null) ? super.getMessage() : super.getMessage() + " (" + src.astGetSource() + ")"; }
protected MergeInfo computeMergeInfos(final Node node, final Map<Node, MergeInfo> infos) throws MergeException { MergeInfo info = infos.get(node); if (info == null) { info = new MergeInfo(node); infos.put(node, info); for (final String type : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(type)) { if (subNode != null) { info.addSubNodeInfo(computeMergeInfos(subNode, infos)); } } } } return info; }
public static void setDebugDecoration(final Node node, final String[] value) { if (!(node instanceof Task) && !(node instanceof Instruction)) { throw new IllegalArgumentException( "node must be either a Task or an Instruction"); } node.astSetDecoration(DEBUG_DECORATION, value); }
T newNode; if (node instanceof AbstractSTNode) { newNode = (T) node.astNewInstance(); } else { final Class<?> nodeClass = node.getClass(); n = nodeFactoryItf.newNode(node.astGetType(), AbstractSTNode.class, nodeItfNames); } catch (final ClassNotFoundException e) { newNode = (T) n.astNewInstance(); newNode.astSetAttributes(node.astGetAttributes()); newNode.astSetSource(node.astGetSource()); final Map<String, Object> decorations = node.astGetDecorations(); for (final Map.Entry<String, Object> entry : decorations.entrySet()) { final Object decoration = entry.getValue(); newNode.astSetDecorations(decorations);
/** * Clone the given {@link Node} and its sub nodes recursively. <br> * <b>Warning</b>: this method consider that the given node is the root of a * <b>tree graph</b> (i.e. any transitive sub node of the given node is the * sub node of one and only one node). Use {@link #cloneGraph(Node)} method if * this condition is not true. * * @param <T> The type of the node. * @param node the root of the tree to clone. * @return a clone of the given tree of node. * @see #cloneGraph(Node) */ public static <T extends Node> T cloneTree(final T node) { final T newNode = cloneNodeState(node); // add sub nodes for (final String subNodeType : node.astGetNodeTypes()) { for (final Node subNode : node.astGetNodes(subNodeType)) { if (subNode != null) newNode.astAddNode(cloneTree(subNode)); } } return newNode; }
/** * Get the parent of the given component * * @param arg the component * @return the parent component */ public static Node getParent(final Node arg) { final Object parent = arg.astGetDecoration("parent"); if (parent instanceof Node) { return (Node) parent; } else return null; }