use of org.eclipse.jdt.core.dom.ChildPropertyDescriptor in project che by eclipse.
the class SourceProvider method isDangligIf.
public boolean isDangligIf() {
List<Statement> statements = fDeclaration.getBody().statements();
if (statements.size() != 1)
return false;
ASTNode p = statements.get(0);
while (true) {
if (p instanceof IfStatement) {
return ((IfStatement) p).getElseStatement() == null;
} else {
ChildPropertyDescriptor childD;
if (p instanceof WhileStatement) {
childD = WhileStatement.BODY_PROPERTY;
} else if (p instanceof ForStatement) {
childD = ForStatement.BODY_PROPERTY;
} else if (p instanceof EnhancedForStatement) {
childD = EnhancedForStatement.BODY_PROPERTY;
} else if (p instanceof DoStatement) {
childD = DoStatement.BODY_PROPERTY;
} else if (p instanceof LabeledStatement) {
childD = LabeledStatement.BODY_PROPERTY;
} else {
return false;
}
Statement body = (Statement) p.getStructuralProperty(childD);
if (body instanceof Block) {
return false;
} else {
p = body;
}
}
}
}
use of org.eclipse.jdt.core.dom.ChildPropertyDescriptor 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);
}
use of org.eclipse.jdt.core.dom.ChildPropertyDescriptor in project xtext-xtend by eclipse.
the class ASTFlattenerUtils method genericChildProperty.
public ASTNode genericChildProperty(final ASTNode node, final String propertyName) {
final Function1<ChildPropertyDescriptor, Boolean> _function = (ChildPropertyDescriptor it) -> {
String _id = it.getId();
return Boolean.valueOf(Objects.equal(propertyName, _id));
};
final ChildPropertyDescriptor property = IterableExtensions.<ChildPropertyDescriptor>head(IterableExtensions.<ChildPropertyDescriptor>filter(Iterables.<ChildPropertyDescriptor>filter(node.structuralPropertiesForType(), ChildPropertyDescriptor.class), _function));
if ((property != null)) {
Object _structuralProperty = node.getStructuralProperty(property);
return ((ASTNode) _structuralProperty);
}
return null;
}
Aggregations