Search in sources :

Example 1 with SimplePropertyDescriptor

use of org.eclipse.jdt.core.dom.SimplePropertyDescriptor in project compiler by boalang.

the class ASTDumper method walk.

/**
     * Walks the tree of objects from the specified node, sending events to the
     * specified printer.
     *
     * @param node
     *            the root node.
     * @param parentIsList
     *            indicates whether the parent node is a list or not.
     */
private void walk(final ASTNode node, final boolean parentIsList) {
    printer.startType(node.getClass().getSimpleName(), parentIsList);
    final List<?> properties = node.structuralPropertiesForType();
    if (comments != null) {
        dumpComments(comments.leadingComments(node), true);
        dumpComments(comments.trailingComments(node), false);
    }
    for (Iterator<?> iterator = properties.iterator(); iterator.hasNext(); ) {
        final Object desciptor = iterator.next();
        if (desciptor instanceof SimplePropertyDescriptor) {
            SimplePropertyDescriptor simple = (SimplePropertyDescriptor) desciptor;
            Object value = node.getStructuralProperty(simple);
            printer.literal(simple.getId(), value);
        } else if (desciptor instanceof ChildPropertyDescriptor) {
            ChildPropertyDescriptor child = (ChildPropertyDescriptor) desciptor;
            ASTNode childNode = (ASTNode) node.getStructuralProperty(child);
            if (childNode != null) {
                printer.startElement(child.getId(), false);
                walk(childNode);
                printer.endElement(child.getId(), false);
            } else {
                printer.literal(child.getId(), null);
            }
        } else {
            ChildListPropertyDescriptor list = (ChildListPropertyDescriptor) desciptor;
            List<ASTNode> value = new ArrayList<ASTNode>((List<ASTNode>) node.getStructuralProperty(list));
            if (value.size() > 0) {
                printer.startElement(list.getId(), true);
                walk(value);
                printer.endElement(list.getId(), true);
            } else {
                printer.literal(list.getId(), value);
            }
        }
    }
    printer.endType(node.getClass().getSimpleName(), parentIsList);
}
Also used : ChildPropertyDescriptor(org.eclipse.jdt.core.dom.ChildPropertyDescriptor) SimplePropertyDescriptor(org.eclipse.jdt.core.dom.SimplePropertyDescriptor) ASTNode(org.eclipse.jdt.core.dom.ASTNode) List(java.util.List) ArrayList(java.util.ArrayList) ChildListPropertyDescriptor(org.eclipse.jdt.core.dom.ChildListPropertyDescriptor)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ChildListPropertyDescriptor (org.eclipse.jdt.core.dom.ChildListPropertyDescriptor)1 ChildPropertyDescriptor (org.eclipse.jdt.core.dom.ChildPropertyDescriptor)1 SimplePropertyDescriptor (org.eclipse.jdt.core.dom.SimplePropertyDescriptor)1