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);
}
Aggregations