1 11 package org.eclipse.jdt.internal.eval; 12 13 import org.eclipse.jdt.internal.compiler.ast.ThisReference; 14 import org.eclipse.jdt.internal.compiler.codegen.CodeStream; 15 import org.eclipse.jdt.internal.compiler.impl.Constant; 16 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 17 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; 18 import org.eclipse.jdt.internal.compiler.lookup.InvocationSite; 19 import org.eclipse.jdt.internal.compiler.lookup.MethodScope; 20 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 21 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 22 23 27 public class CodeSnippetThisReference extends ThisReference implements EvaluationConstants, InvocationSite { 28 29 EvaluationContext evaluationContext; 30 FieldBinding delegateThis; 31 boolean isImplicit; 32 33 38 public CodeSnippetThisReference(int s, int sourceEnd, EvaluationContext evaluationContext, boolean isImplicit) { 39 super(s, sourceEnd); 40 this.evaluationContext = evaluationContext; 41 this.isImplicit = isImplicit; 42 } 43 public boolean checkAccess(MethodScope methodScope) { 44 if (this.evaluationContext.isConstructorCall) { 46 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this); 47 return false; 48 } 49 50 if (this.evaluationContext.declaringTypeName == null || this.evaluationContext.isStatic) { 52 methodScope.problemReporter().errorThisSuperInStatic(this); 53 return false; 54 } 55 return true; 56 } 57 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { 58 int pc = codeStream.position; 59 if (valueRequired) { 60 codeStream.aload_0(); 61 codeStream.getfield(this.delegateThis); 62 } 63 codeStream.recordPositionsFrom(pc, this.sourceStart); 64 } 65 68 public TypeBinding[] genericTypeArguments() { 69 return null; 70 } 71 public boolean isSuperAccess(){ 72 return false; 73 } 74 public boolean isTypeAccess(){ 75 return false; 76 } 77 public StringBuffer printExpression(int indent, StringBuffer output){ 78 79 char[] declaringType = this.evaluationContext.declaringTypeName; 80 output.append('('); 81 if (declaringType == null) 82 output.append("<NO DECLARING TYPE>"); else 84 output.append(declaringType); 85 return output.append(")this"); } 87 public TypeBinding resolveType(BlockScope scope) { 88 89 this.constant = Constant.NotAConstant; 91 TypeBinding snippetType = null; 92 MethodScope methodScope = scope.methodScope(); 93 if (!this.isImplicit && !checkAccess(methodScope)) { 94 return null; 95 } 96 snippetType = scope.enclosingSourceType(); 97 98 this.delegateThis = scope.getField(snippetType, DELEGATE_THIS, this); 99 if (this.delegateThis == null || !this.delegateThis.isValidBinding()) { 100 methodScope.problemReporter().errorThisSuperInStatic(this); 103 return null; 104 } 105 return this.resolvedType = this.delegateThis.type; 106 } 107 public void setActualReceiverType(ReferenceBinding receiverType) { 108 } 110 public void setDepth(int depth){ 111 } 113 public void setFieldIndex(int index){ 114 } 116 } 117 | Popular Tags |