private void setSource(final Node node, final NodeToken source) { if (source == null) node.astSetSource(filename); else node.astSetSource(filename + ":" + source.beginLine + "-" + source.beginColumn); }
@SuppressWarnings("unchecked") private static List<AdditionalCompilationUnitDecoration> getDecoration( final Definition def) { return (List<AdditionalCompilationUnitDecoration>) def .astGetDecoration(ADDITIONAL_COMPILATION_UNIT_DECORATION_NAME); }
@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; }
/** * 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; }
public Component visit(final List<Node> path, final ComponentContainer node, final Map<Object, Object> context) throws ADLException, TaskException { final Implementation impl = castNodeError(node, ImplementationContainer.class).getImplementation(); if (impl == null) { throw new CompilerError(GenericErrors.INTERNAL_ERROR, "This visitor is only applicable for primitive component."); } return createImplementationTask(node, impl); }
public Object newComponentType(final String name, final Map context) throws ADLException { for (final Factory factory : factoryItfs.values()) { try { return factory.newComponentType(name, context); } catch (final ADLException e) { } } throw new CompilerError(GenericErrors.INTERNAL_ERROR, "Coud not instantiate the plugin '" + name + "'"); }
private static AnnotationDecoration getDecoration(final Node container) { return (AnnotationDecoration) container .astGetDecoration(ANNOTATION_DECORATION_NAME); }
/** * @see org.objectweb.fractal.adl.Loader#load(java.lang.String, * java.util.Map) */ public Definition load(String name, Map<Object, Object> context) throws ADLException { Definition d = clientLoader.load(name, context); checkNode(d); return d; }
/** * @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); }
/** * A static method that returns the name of the file that is generated by this * component for the given {@link Definition}; * * @param definition a {@link Definition} node. * @return the name of the file that is generated by this component for the * given {@link Definition}; */ public static String getMacroFileName(final Definition definition) { return fullyQualifiedNameToPath(definition.getName(), FILE_EXT); }
private static void addDecoration(final Node container, final AnnotationDecoration decoration) { container.astSetDecoration(ANNOTATION_DECORATION_NAME, decoration); }
public Node newNode(final String nodeType, final String... interfaces) throws ClassNotFoundException { return newNode(nodeType, AbstractNode.class, interfaces); }
@Override public void bindFc(final String s, final Object o) { if ("node-factory".equals(s)) { return; } super.bindFc(s, o); } }
/** * 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; }
@Override public String getMessage() { return (src == null) ? super.getMessage() : super.getMessage() + " (" + src.astGetSource() + ")"; }
/** * A static method that returns the name of the file that is generated by this * component for the given {@link Definition}; * * @param definition a {@link Definition} node. * @return the name of the file that is generated by this component for the * given {@link Definition}; */ public static String getHeaderFileName(final Definition definition) { return fullyQualifiedNameToPath(definition.getName(), FILE_EXT); }
@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; }
/** * 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); }
public static String[] getDebugDecoration(final Node node) { return (String[]) node.astGetDecoration(DEBUG_DECORATION); }