Example usage for org.eclipse.jdt.core.dom QualifiedName getRoot

List of usage examples for org.eclipse.jdt.core.dom QualifiedName getRoot

Introduction

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

Prototype

public final ASTNode getRoot() 

Source Link

Document

Returns the root node at or above this node; returns this node if it is a root.

Usage

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils.java

License:Open Source License

/**
 * Tracks assignments on execution flow starting from given {@link ExecutionFlowDescription} and
 * remember results in {@link ASTNode} properties.
 *///from  ww  w  .  j  av  a 2s  .  c  o  m
private static void prepareAssignmentInformation(ExecutionFlowDescription flowDescription) {
    final Long assignmentStamp = flowDescription.getAST().modificationCount();
    // visit execution flow, find declarations/assignments for all variables
    visit(new VisitingContext(true), flowDescription, new AbstractVariablesExecutionFlowVisitor(true) {
        @Override
        public void endVisit(Assignment node) {
            Expression leftSide = node.getLeftHandSide();
            if (isVariable(leftSide)) {
                Expression variable = leftSide;
                executionFlowContext.addAssignment(variable, node);
                executionFlowContext.storeAssignments(variable);
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        //
        // Generic ASTNode pre/post visiting
        //
        ////////////////////////////////////////////////////////////////////////////
        @Override
        public void postVisit(ASTNode node) {
            // store assignment for variable usage
            if (node instanceof Expression && isVariable(node)) {
                Expression variable = (Expression) node;
                variable.setProperty(KEY_LAST_VARIABLE_STAMP, assignmentStamp);
                executionFlowContext.storeAssignments(variable);
            }
        }
    });
    // visit CompilationUnit, find references for all variables
    flowDescription.getCompilationUnit().accept(new AbstractVariablesExecutionFlowVisitor(false) {
        @Override
        public boolean visit(AnonymousClassDeclaration node) {
            return true;
        }

        @Override
        public void preVisit(ASTNode node) {
            super.preVisit(node);
            if (isFrameNode(node)) {
                enterFrame(node);
                // visit all fields on enter TypeDeclaration
                if (node instanceof TypeDeclaration) {
                    TypeDeclaration typeDeclaration = (TypeDeclaration) node;
                    visitFields(this, typeDeclaration, true);
                    visitFields(this, typeDeclaration, false);
                }
            }
        }

        @Override
        public void postVisit(ASTNode node) {
            super.postVisit(node);
            if (isFrameNode(node)) {
                leaveFrame(node);
            }
            if (node instanceof Expression) {
                if (isVariable(node)) {
                    executionFlowContext.storeReferences((Expression) node);
                }
                // special support for "instanceOfTopType.field"
                if (node instanceof QualifiedName) {
                    QualifiedName qualifiedName = (QualifiedName) node;
                    CompilationUnit unit = (CompilationUnit) qualifiedName.getRoot();
                    TypeDeclaration topType = (TypeDeclaration) unit.types().get(0);
                    if (qualifiedName.getQualifier().resolveTypeBinding() == topType.resolveBinding()) {
                        executionFlowContext.storeReferences(qualifiedName.getName());
                    }
                }
            }
        }

        private boolean isFrameNode(ASTNode node) {
            return node instanceof TypeDeclaration || node instanceof MethodDeclaration
                    || node instanceof Block;
        }
    });
}