Example usage for org.eclipse.jdt.internal.compiler.impl ReferenceContext compilationResult

List of usage examples for org.eclipse.jdt.internal.compiler.impl ReferenceContext compilationResult

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.impl ReferenceContext compilationResult.

Prototype

CompilationResult compilationResult();

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.MethodSpec.java

License:Open Source License

/**
 * Same as above, but consider specified signature for argument mapping (using AnchorMapping).
 * @param receiverType receiver of the method call.
 * @param scope//  w  ww .  j  a  v a  2 s .c  om
 * @param isBaseSide
 * @param callinExpected whether this method spec is the LHS of a replace callin.
 * @param allowEnclosing whether a method may be found in an enclosing type of receiverType
 */
public void resolveFeatureWithArgMapping(ReferenceBinding receiverType, BlockScope scope, boolean isBaseSide,
        boolean callinExpected, boolean allowEnclosing) {
    FieldReference receiver = null;
    if (isBaseSide) {
        // construct temporary faked receiver
        ReferenceContext referenceContext = scope.referenceContext();
        CheckPoint cp = referenceContext.compilationResult().getCheckPoint(referenceContext);
        receiver = new FieldReference(IOTConstants._OT_BASE, 0L); // can't fail, help the compiler recognize that receiver won't be null below.
        try {
            receiver.receiver = ThisReference.implicitThis();
            receiver.resolveType(scope);
        } finally {
            if (receiver.binding == null || !receiver.binding.isValidBinding()) {
                // resolve didn't work, which happens if role is ifc, thus has no base field
                // at least set the receiver type.
                // TODO(SH): this means, role ifcs can not use base-anchored types.
                receiver.resolvedType = receiverType;
                referenceContext.compilationResult().rollBack(cp);
            }
        }
    }
    AnchorMapping anchorMapping = null;
    try {
        anchorMapping = AnchorMapping.setupNewMapping(receiver, this.arguments, scope);
        resolveFeature(receiverType, scope, callinExpected, isBaseSide, allowEnclosing);
    } finally {
        AnchorMapping.removeCurrentMapping(anchorMapping);
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PotentialRoleReceiverExpression.java

License:Open Source License

@Override
public TypeBinding resolveType(BlockScope scope) {
    ReferenceContext referenceContext = scope.referenceContext();
    CompilationResult compilationResult = referenceContext.compilationResult();
    CheckPoint cp = compilationResult.getCheckPoint(referenceContext);

    // try normal:
    this.resolvedType = this.expression.resolveType(scope);
    if (this.resolvedType != null && this.resolvedType.isValidBinding()) {
        this.constant = this.expression.constant;
        return this.resolvedType;
    }/* w ww  .j  ava2s . c  o m*/

    // try alternative:
    TypeBinding altResult = null;
    AstGenerator gen = new AstGenerator(this.expression);
    if (this.expression instanceof PotentialLiftExpression) // that didn't help, only use one of lifting/role-scoping
        this.expression = ((PotentialLiftExpression) this.expression).expression;
    if (this.expression instanceof SingleNameReference) {
        this.altExpression = gen.fieldReference(gen.castExpression(gen.singleNameReference(this.roleVarName),
                this.roleClassRef, CastExpression.NEED_CLASS), ((SingleNameReference) this.expression).token);
        altResult = this.altExpression.resolveType(scope);
        // share resolved binding (helps the match locator)
        ((NameReference) this.expression).binding = ((FieldReference) this.altExpression).binding;
    } else if (this.expression instanceof MessageSend) {
        MessageSend send = (MessageSend) this.expression;
        if (send.receiver.isThis()) {
            this.altExpression = gen.messageSend(gen.singleNameReference(this.roleVarName), send.selector,
                    send.arguments);
            altResult = this.altExpression.resolveType(scope);
            // share resolved bindings (helps the match locator)
            ((MessageSend) this.expression).binding = ((MessageSend) this.altExpression).binding;
            ((MessageSend) this.expression).resolvedType = ((MessageSend) this.altExpression).resolvedType;
            ((MessageSend) this.expression).actualReceiverType = ((MessageSend) this.altExpression).actualReceiverType;
        }
    }

    // evaluate results:
    if (altResult != null && altResult.isValidBinding()) {
        compilationResult.rollBack(cp);
        this.constant = this.altExpression.constant;
        return this.resolvedType = altResult;
    }
    this.altExpression = null; // discard unsuccessful indirection
    this.constant = this.expression.constant;
    return this.resolvedType;
}

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

License:Open Source License

/** Create a message send to a method that will be created by the otre. */
public MessageSend fakeMessageSend(Expression receiver, char[] selector, Expression[] parameters,
        final ReferenceBinding receiverType, final TypeBinding resolvedReturn) {
    MessageSend messageSend = new MessageSend() {
        @Override//from w  w w  . j  a v a 2  s .c om
        public TypeBinding resolveType(BlockScope scope) {
            ReferenceContext referenceContext = scope.referenceContext();
            CheckPoint cp = referenceContext.compilationResult().getCheckPoint(referenceContext);
            super.resolveType(scope);
            referenceContext.compilationResult().rollBack(cp);
            this.binding = new MethodBinding(ClassFileConstants.AccStatic | ClassFileConstants.AccPublic,
                    this.selector, resolvedReturn, this.binding.parameters, Binding.NO_EXCEPTIONS,
                    receiverType);
            return this.resolvedType = resolvedReturn;
        }
    };
    messageSend.isGenerated = true;
    messageSend.sourceStart = this.sourceStart;
    messageSend.sourceEnd = this.sourceEnd;
    messageSend.statementEnd = this.sourceEnd;
    messageSend.nameSourcePosition = this.pos;
    messageSend.receiver = receiver;
    messageSend.selector = selector;
    messageSend.arguments = parameters;
    return messageSend;
}