1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.codegen.*; 15 import org.eclipse.jdt.internal.compiler.flow.FlowContext; 16 import org.eclipse.jdt.internal.compiler.flow.FlowInfo; 17 import org.eclipse.jdt.internal.compiler.impl.Constant; 18 import org.eclipse.jdt.internal.compiler.lookup.*; 19 20 public class ThisReference extends Reference { 21 22 public static ThisReference implicitThis(){ 23 24 ThisReference implicitThis = new ThisReference(0, 0); 25 implicitThis.bits |= IsImplicitThis; 26 return implicitThis; 27 } 28 29 public ThisReference(int sourceStart, int sourceEnd) { 30 31 this.sourceStart = sourceStart; 32 this.sourceEnd = sourceEnd; 33 } 34 35 38 public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) { 39 40 return flowInfo; } 42 43 public boolean checkAccess(MethodScope methodScope) { 44 45 if (methodScope.isConstructorCall) { 47 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this); 48 return false; 49 } 50 51 if (methodScope.isStatic) { 53 methodScope.problemReporter().errorThisSuperInStatic(this); 54 return false; 55 } 56 return true; 57 } 58 59 62 public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) { 63 64 } 66 67 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { 68 69 int pc = codeStream.position; 70 if (valueRequired) 71 codeStream.aload_0(); 72 if ((this.bits & IsImplicitThis) == 0) codeStream.recordPositionsFrom(pc, this.sourceStart); 73 } 74 75 78 public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { 79 80 } 82 83 86 public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { 87 88 } 90 91 public boolean isImplicitThis() { 92 93 return (this.bits & IsImplicitThis) != 0; 94 } 95 96 public boolean isThis() { 97 98 return true ; 99 } 100 101 public int nullStatus(FlowInfo flowInfo) { 102 return FlowInfo.NON_NULL; 103 } 104 105 public StringBuffer printExpression(int indent, StringBuffer output){ 106 107 if (this.isImplicitThis()) return output; 108 return output.append("this"); } 110 111 public TypeBinding resolveType(BlockScope scope) { 112 113 constant = Constant.NotAConstant; 114 if (!this.isImplicitThis() &&!checkAccess(scope.methodScope())) { 115 return null; 116 } 117 return this.resolvedType = scope.enclosingReceiverType(); 118 } 119 120 public void traverse(ASTVisitor visitor, BlockScope blockScope) { 121 122 visitor.visit(this, blockScope); 123 visitor.endVisit(this, blockScope); 124 } 125 public void traverse(ASTVisitor visitor, ClassScope blockScope) { 126 127 visitor.visit(this, blockScope); 128 visitor.endVisit(this, blockScope); 129 } 130 } 131 | Popular Tags |