Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2011 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.internal.eval;
 
 
 public class CodeSnippetMessageSend extends MessageSend {
CodeSnippetMessageSend constructor comment.
 
 public CodeSnippetMessageSend(EvaluationContext evaluationContext) {
 	this. = evaluationContext;
 }
MessageSend code generation

Parameters:
currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
valueRequired boolean
 
 public void generateCode(BlockScope currentScopeCodeStream codeStreamboolean valueRequired) {
 	int pc = codeStream.position;
 	MethodBinding codegenBinding = this..original();
 	if (codegenBinding.canBeSeenBy(this.thiscurrentScope)) {
 		// generate receiver/enclosing instance access
 		boolean isStatic = codegenBinding.isStatic();
 		// outer access ?
 		if (!isStatic && ((this. & ) != 0)) {
 			// outer method can be reached through emulation
 			ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this. & ) >> );
 			Object[] path = currentScope.getEmulationPath(targetTypetrue /*only exact match*/false/*consider enclosing arg*/);
 			if (path == null) {
 				// emulation was not possible (should not happen per construction)
 				currentScope.problemReporter().needImplementation(this);
 			} else {
 				codeStream.generateOuterAccess(paththistargetTypecurrentScope);
 			}
 		} else {
 			this..generateCode(currentScopecodeStream, !isStatic);
 			if ((this. & ) != 0) {
 				codeStream.checkcast(this.);
 			}			
 			codeStream.recordPositionsFrom(pcthis.);
 		}
 		// generate arguments
 		generateArguments(this.this.currentScopecodeStream);
 		// actual message invocation
 		TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScopecodegenBindingthis.this..isImplicitThis());
 		if (isStatic) {
 			codeStream.invoke(.codegenBindingconstantPoolDeclaringClass);
 		} else if( (this..isSuper()) || codegenBinding.isPrivate()){
 			codeStream.invoke(.codegenBindingconstantPoolDeclaringClass);
 		} else {
 			if (constantPoolDeclaringClass.isInterface()) { // interface or annotation type
 				codeStream.invoke(.codegenBindingconstantPoolDeclaringClass);
 			} else {
 				codeStream.invoke(.codegenBindingconstantPoolDeclaringClass);
 			}
 		}
 	} else {
 		codeStream.generateEmulationForMethod(currentScopecodegenBinding);
 		// generate receiver/enclosing instance access
 		boolean isStatic = codegenBinding.isStatic();
 		// outer access ?
 		if (!isStatic && ((this. & ) != 0)) {
 			// not supported yet
 			currentScope.problemReporter().needImplementation(this);
 		} else {
			this..generateCode(currentScopecodeStream, !isStatic);
			if ((this. & ) != 0) {
				codeStream.checkcast(this.);
			}			
			codeStream.recordPositionsFrom(pcthis.);
		}
		if (isStatic) {
			// we need an object on the stack which is ignored for the method invocation
			codeStream.aconst_null();
		}
		// generate arguments
		if (this. != null) {
			int argsLength = this..length;
			codeStream.generateInlinedValue(argsLength);
			codeStream.newArray(currentScope.createArrayType(currentScope.getType(., 3), 1));
			codeStream.dup();
			for (int i = 0; i < argsLengthi++) {
				codeStream.generateInlinedValue(i);
				this.[i].generateCode(currentScopecodeStreamtrue);
				TypeBinding parameterBinding = codegenBinding.parameters[i];
				if (parameterBinding.isBaseType() && parameterBinding != .) {
					codeStream.generateBoxingConversion(codegenBinding.parameters[i].);
				}
				codeStream.aastore();
				if (i < argsLength - 1) {
					codeStream.dup();
				}
			}
else {
			codeStream.generateInlinedValue(0);
			codeStream.newArray(currentScope.createArrayType(currentScope.getType(., 3), 1));
		}
		// convert the return value to the appropriate type for primitive types
		if (codegenBinding.returnType.isBaseType()) {
			int typeID = codegenBinding.returnType.id;
			if (typeID == ) {
				// remove the null from the stack
				codeStream.pop();
			}
			codeStream.checkcast(typeID);
			codeStream.getBaseTypeValue(typeID);
else {
			codeStream.checkcast(codegenBinding.returnType);
		}
	}
	// required cast must occur even if no value is required
	if (this. != nullcodeStream.checkcast(this.);
	if (valueRequired){
		// implicit conversion if necessary
else {
		boolean isUnboxing = (this. & .) != 0;
		// conversion only generated if unboxing
		if (isUnboxingcodeStream.generateImplicitConversion(this.);
		switch (isUnboxing ? postConversionType(currentScope). : codegenBinding.returnType.id) {
			case  :
			case  :
				codeStream.pop2();
				break;
			case  :
				break;
			default :
				codeStream.pop();
		}
	}
	codeStream.recordPositionsFrom(pc, (int)(this. >>> 32)); // highlight selector
public void manageSyntheticAccessIfNecessary(BlockScope currentScopeFlowInfo flowInfo) {
	if ((flowInfo.tagBits & .) == 0) {
		// if method from parameterized type got found, use the original method at codegen time
		MethodBinding codegenBinding = this..original();
		if (codegenBinding != this.) {
		    // extra cast needed if method return type was type variable
		    if (codegenBinding.returnType.isTypeVariable()) {
		        TypeVariableBinding variableReturnType = (TypeVariableBindingcodegenBinding.returnType;
		        if (variableReturnType.firstBound != this..) { // no need for extra cast if same as first bound anyway
				    this. = this..;
		        }
		    }
		}
	}
	// Answer the signature return type
	// Base type promotion
	boolean receiverCast = falseargsContainCast = false;
	if (this. instanceof CastExpression) {
		this.. |= // will check later on
		receiverCast = true;
	}
	if (receiverCast && this. != null) {
		 // due to change of declaring class with receiver type, only identity cast should be notified
		}
	}
	// resolve type arguments (for generic constructor call)
	if (this. != null) {
		int length = this..length;
		boolean argHasError = false// typeChecks all arguments
		this. = new TypeBinding[length];
		for (int i = 0; i < lengthi++) {
			if ((this.[i] = this.[i].resolveType(scopetrue /* check bounds*/)) == null) {
				argHasError = true;
			}
		}
		if (argHasError) {
			return null;
		}
	}
	// will check for null after args are resolved
	TypeBinding[] argumentTypes = .;
	if (this. != null) {
		boolean argHasError = false// typeChecks all arguments
		int length = this..length;
		argumentTypes = new TypeBinding[length];
		for (int i = 0; i < lengthi++) {
			Expression argument = this.[i];
			if (argument instanceof CastExpression) {
				argument.bits |= // will check later on
				argsContainCast = true;
			}
			if ((argumentTypes[i] = this.[i].resolveType(scope)) == null)
				argHasError = true;
		}
		if (argHasError) {
			if(this. instanceof ReferenceBinding) {
				// record any selector match, for clients who may still need hint about possible method match
				this. = scope.findMethod((ReferenceBinding)this.this.new TypeBinding[]{}, this);
			}
			return null;
		}
	}
	if (this. == null) {
		return null;
	}
	// base type cannot receive any message
		scope.problemReporter().errorNoMethodFor(thisthis.argumentTypes);
		return null;
	}
	this. =
scope.getImplicitMethod(this.argumentTypesthis)
scope.getMethod(this.this.argumentTypesthis);
	if (!this..isValidBinding()) {
		if (this. instanceof ProblemMethodBinding
			if (this.. != null) {
				if (this. == null){ // if not found then internal error, field should have been found
					return null;
				}
else {
				return null;
			}
			CodeSnippetScope localScope = new CodeSnippetScope(scope);
			MethodBinding privateBinding =
localScope.getImplicitMethod((ReferenceBinding)this..this.argumentTypesthis)
localScope.getMethod(this..this.argumentTypesthis);
			if (!privateBinding.isValidBinding()) {
				if (this.. == null) {
					if (this. instanceof ReferenceBinding) {
else { // really bad error ....
						scope.problemReporter().errorNoMethodFor(thisthis.argumentTypes);
						return null;
					}
				}
				return null;
else {
				this. = privateBinding;
			}
else {
			if (this.. == null) {
				if (this. instanceof ReferenceBinding) {
else { // really bad error ....
					scope.problemReporter().errorNoMethodFor(thisthis.argumentTypes);
					return null;
				}
			}
			return null;
		}
	}
	if (!this..isStatic()) {
		// the "receiver" must not be a type, in other words, a NameReference that the TC has bound to a Type
		if (this. instanceof NameReference
				&& (((NameReferencethis.). & .) != 0) {
else {
			// handle indirect inheritance thru variable secondary bound
			// receiver may receive generic cast, as part of implicit conversion
			TypeBinding oldReceiverType = this.;
			if (this. != oldReceiverType && this..postConversionType(scope) != this.) { // record need for explicit cast at codegen since receiver could not handle it
			}			
		}
	}
	if (checkInvocationArguments(scopethis.this.this.this.argumentTypesargsContainCastthis)) {
	}
	//-------message send that are known to fail at compile time-----------
	if (this..isAbstract()) {
		if (this..isSuper()) {
		}
		// abstract private methods cannot occur nor abstract static............
	}
	if (isMethodUseDeprecated(this.scopetrue))
	// from 1.5 compliance on, array#clone() returns the array type (but binding still shows Object)
			&& CharOperation.equals(this..)) {
else {
		TypeBinding returnType = this..;
		if (returnType != null) {
			if ((this. & .) != 0 && this. == null) {
				returnType = scope.environment().convertToRawType(returnType.erasure(), true);
			}
			returnType = returnType.capture(scopethis.);			
		}
		this. = returnType;
	}
	return this.;
New to GrepCode? Check out our FAQ X