Example usage for org.eclipse.jdt.core.dom FieldAccess getParent

List of usage examples for org.eclipse.jdt.core.dom FieldAccess getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom FieldAccess getParent.

Prototype

public final ASTNode getParent() 

Source Link

Document

Returns this node's parent node, or null if this is the root node.

Usage

From source file:com.google.gdt.eclipse.designer.smart.model.data.DataSourceInfo.java

License:Open Source License

public StatementTarget calculateStatementTarget(JavaInfo component, List<ASTNode> afterNodes) throws Exception {
    // prepare/*from   w w  w.j  a va2 s. co m*/
    prepareForAssignTo(component);
    //
    LazyVariableSupport lazyVariableSupport = null;
    if (getVariableSupport() instanceof LazyVariableSupport) {
        lazyVariableSupport = (LazyVariableSupport) getVariableSupport();
    }
    // collect nodes
    List<ASTNode> nodes = Lists.newArrayList(afterNodes);
    for (ASTNode node : getRelatedNodes()) {
        if (lazyVariableSupport != null
                && lazyVariableSupport.m_accessor.equals(AstNodeUtils.getEnclosingMethod(node))) {
            // skip nodes in "lazy" method
            continue;
        }
        // all "dataSource.setX()" invocations must be before
        ASTNode parentNode = node.getParent();
        if (parentNode instanceof MethodInvocation) {
            MethodInvocation methodInvocation = (MethodInvocation) parentNode;
            if (isRepresentedBy(methodInvocation.getExpression())
                    && methodInvocation.getName().getIdentifier().startsWith("set")) {
                nodes.add(node);
                continue;
            }
        }
        // all "dataSource.x = X" fields assignment must be before
        if (parentNode instanceof FieldAccess) {
            FieldAccess fieldAccess = (FieldAccess) parentNode;
            if (isRepresentedBy(fieldAccess.getExpression()) && fieldAccess.getParent() instanceof Assignment) {
                nodes.add(node);
                continue;
            }
        }
    }
    // process nodes
    if (!nodes.isEmpty()) {
        nodes.add(getCreationSupport().getNode());
        nodes.add(component.getCreationSupport().getNode());
        // sort nodes
        ExecutionFlowDescription flowDescription = JavaInfoUtils.getState(getRootJava()).getFlowDescription();
        JavaInfoUtils.sortNodesByFlow(flowDescription, false, nodes);
        ASTNode targetNode = nodes.get(nodes.size() - 1);
        return new StatementTarget(targetNode, false);
    }
    return null;
}

From source file:fr.labri.harmony.rta.junit.jdt.JDTVisitorRTA.java

License:Open Source License

public boolean visit(FieldAccess a) {
    IVariableBinding b = a.resolveFieldBinding();

    if (b != null && currentJavaMethod != null) {
        if (b.getDeclaringClass() != null) {
            if (!(a.getParent() instanceof Assignment)) {

                String fieldId = getVariableBindingId(b);
                //System.err.println("Add "+fieldId);
                currentJavaMethod.getCallsSite().add(fieldId);
            } else {
                if (((Assignment) a.getParent()).getLeftHandSide() instanceof FieldAccess) {
                    if (((FieldAccess) ((Assignment) a.getParent()).getLeftHandSide())
                            .resolveFieldBinding() != null) {
                        if (!((FieldAccess) ((Assignment) a.getParent()).getLeftHandSide())
                                .resolveFieldBinding().getKey().equals(b.getKey())) {

                            String fieldId = getVariableBindingId(b);
                            //System.err.println("Add "+fieldId);
                            currentJavaMethod.getCallsSite().add(fieldId);
                        }/*from www .j  av a 2s . co m*/
                    }
                }
            }
        }
    }

    return true;
}