Example usage for org.eclipse.jdt.internal.compiler.ast Expression analyseCode

List of usage examples for org.eclipse.jdt.internal.compiler.ast Expression analyseCode

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast Expression analyseCode.

Prototype

public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo,
        boolean valueRequired) 

Source Link

Document

More sophisticated for of the flow analysis used for analyzing expressions, and be able to optimize out portions of expressions where no actual value is required.

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

/**
 * Assemble an ifstatement with negated condition, that hides the branch instruction from the debugger,
 * even when stepping into the condition. 
 *//*from   w  ww  . j a  va 2  s .c om*/
public IfStatement stealthIfNotStatement(final Expression condition, Statement thenStatement) {
    // mark step-over after the condition:
    Expression recordingCondition = new Expression() {
        public StringBuffer printExpression(int indent, StringBuffer output) {
            return condition.print(indent, output);
        }

        public TypeBinding resolveType(BlockScope scope) {
            return condition.resolveType(scope);
        }

        public void computeConversion(Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType) {
            condition.computeConversion(scope, runtimeType, compileTimeType);
            this.constant = condition.constant;
            this.bits = condition.bits;
        }

        public Constant optimizedBooleanConstant() {
            this.constant = condition.optimizedBooleanConstant();
            this.bits = condition.bits;
            return this.constant;
        }

        public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo,
                boolean valueRequired) {
            return condition.analyseCode(currentScope, flowContext, flowInfo, valueRequired);
        }

        public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
            return condition.analyseCode(currentScope, flowContext, flowInfo);
        }

        public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
            condition.generateCode(currentScope, codeStream, valueRequired);
            // payload:
            codeStream.pcToSourceMap[codeStream.pcToSourceMapSize++] = codeStream.position;
            codeStream.pcToSourceMap[codeStream.pcToSourceMapSize++] = STEP_OVER_LINENUMBER;
        }
    };
    return new IfStatement(new UnaryExpression( // NOT
            recordingCondition, OperatorIds.NOT), thenStatement, this.sourceStart, this.sourceEnd);
}