Search in sources :

Example 1 with ChildPropertyDescriptor

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;
            }
        }
    }
}
Also used : IfStatement(org.eclipse.jdt.core.dom.IfStatement) ChildPropertyDescriptor(org.eclipse.jdt.core.dom.ChildPropertyDescriptor) LabeledStatement(org.eclipse.jdt.core.dom.LabeledStatement) DoStatement(org.eclipse.jdt.core.dom.DoStatement) DoStatement(org.eclipse.jdt.core.dom.DoStatement) Statement(org.eclipse.jdt.core.dom.Statement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) IfStatement(org.eclipse.jdt.core.dom.IfStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) LabeledStatement(org.eclipse.jdt.core.dom.LabeledStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Block(org.eclipse.jdt.core.dom.Block) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) WhileStatement(org.eclipse.jdt.core.dom.WhileStatement) EnhancedForStatement(org.eclipse.jdt.core.dom.EnhancedForStatement) ForStatement(org.eclipse.jdt.core.dom.ForStatement)

Example 2 with ChildPropertyDescriptor

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

Example 3 with ChildPropertyDescriptor

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;
}
Also used : ChildPropertyDescriptor(org.eclipse.jdt.core.dom.ChildPropertyDescriptor)

Aggregations

ChildPropertyDescriptor (org.eclipse.jdt.core.dom.ChildPropertyDescriptor)3 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Block (org.eclipse.jdt.core.dom.Block)1 ChildListPropertyDescriptor (org.eclipse.jdt.core.dom.ChildListPropertyDescriptor)1 DoStatement (org.eclipse.jdt.core.dom.DoStatement)1 EnhancedForStatement (org.eclipse.jdt.core.dom.EnhancedForStatement)1 ForStatement (org.eclipse.jdt.core.dom.ForStatement)1 IfStatement (org.eclipse.jdt.core.dom.IfStatement)1 LabeledStatement (org.eclipse.jdt.core.dom.LabeledStatement)1 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)1 SimplePropertyDescriptor (org.eclipse.jdt.core.dom.SimplePropertyDescriptor)1 Statement (org.eclipse.jdt.core.dom.Statement)1 WhileStatement (org.eclipse.jdt.core.dom.WhileStatement)1