1 11 package org.eclipse.jdt.internal.eval; 12 13 import org.eclipse.jdt.internal.compiler.ast.Expression; 14 import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; 15 import org.eclipse.jdt.internal.compiler.ast.TryStatement; 16 import org.eclipse.jdt.internal.compiler.codegen.CodeStream; 17 import org.eclipse.jdt.internal.compiler.flow.FlowContext; 18 import org.eclipse.jdt.internal.compiler.flow.FlowInfo; 19 import org.eclipse.jdt.internal.compiler.impl.Constant; 20 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 21 import org.eclipse.jdt.internal.compiler.lookup.InvocationSite; 22 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; 23 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 24 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 25 26 31 public class CodeSnippetReturnStatement extends ReturnStatement implements InvocationSite, EvaluationConstants { 32 MethodBinding setResultMethod; 33 public CodeSnippetReturnStatement(Expression expr, int s, int e) { 34 super(expr, s, e); 35 } 36 37 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { 38 FlowInfo info = super.analyseCode(currentScope, flowContext, flowInfo); 39 this.expression.bits &= ~IsReturnedValue; 42 return info; 43 } 44 45 49 public void generateReturnBytecode(CodeStream codeStream) { 50 51 codeStream.return_(); 53 } 54 public void generateStoreSaveValueIfNecessary(CodeStream codeStream){ 55 56 codeStream.aload_0(); 58 59 if (this.expression == null || this.expression.resolvedType == TypeBinding.VOID) { codeStream.aconst_null(); 63 64 codeStream.generateClassLiteralAccessForType(TypeBinding.VOID, null); 66 } else { 67 int valueTypeID = this.expression.resolvedType.id; 69 if (valueTypeID == T_long || valueTypeID == T_double) { 70 codeStream.dup_x2(); 71 codeStream.pop(); 72 } else { 73 codeStream.swap(); 74 } 75 76 if (this.expression.resolvedType.isBaseType() && this.expression.resolvedType != TypeBinding.NULL) { 78 codeStream.generateBoxingConversion(this.expression.resolvedType.id); 79 } 80 81 codeStream.generateClassLiteralAccessForType(this.expression.resolvedType, null); 83 } 84 85 codeStream.invokevirtual(this.setResultMethod); 87 } 88 91 public TypeBinding[] genericTypeArguments() { 92 return null; 93 } 94 public boolean isSuperAccess() { 95 return false; 96 } 97 public boolean isTypeAccess() { 98 return false; 99 } 100 public boolean needValue(){ 101 return true; 102 } 103 public void prepareSaveValueLocation(TryStatement targetTryStatement){ 104 105 } 107 public void resolve(BlockScope scope) { 108 if (this.expression != null) { 109 if (this.expression.resolveType(scope) != null) { 110 TypeBinding javaLangClass = scope.getJavaLangClass(); 111 if (!javaLangClass.isValidBinding()) { 112 scope.problemReporter().codeSnippetMissingClass("java.lang.Class", this.sourceStart, this.sourceEnd); return; 114 } 115 TypeBinding javaLangObject = scope.getJavaLangObject(); 116 if (!javaLangObject.isValidBinding()) { 117 scope.problemReporter().codeSnippetMissingClass("java.lang.Object", this.sourceStart, this.sourceEnd); return; 119 } 120 TypeBinding[] argumentTypes = new TypeBinding[] {javaLangObject, javaLangClass}; 121 this.setResultMethod = scope.getImplicitMethod(SETRESULT_SELECTOR, argumentTypes, this); 122 if (!this.setResultMethod.isValidBinding()) { 123 scope.problemReporter().codeSnippetMissingMethod(ROOT_FULL_CLASS_NAME, new String (SETRESULT_SELECTOR), new String (SETRESULT_ARGUMENTS), this.sourceStart, this.sourceEnd); 124 return; 125 } 126 if (this.expression.constant != Constant.NotAConstant) { 128 this.expression.implicitConversion = this.expression.constant.typeID() << 4; 130 } 131 } 132 } 133 } 134 public void setActualReceiverType(ReferenceBinding receiverType) { 135 } 137 public void setDepth(int depth) { 138 } 140 public void setFieldIndex(int depth) { 141 } 143 144 } 145 | Popular Tags |