KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ast > ThisReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /*
36      * @see Reference#analyseAssignment(...)
37      */

38     public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
39
40         return flowInfo; // this cannot be assigned
41
}
42
43     public boolean checkAccess(MethodScope methodScope) {
44     
45         // this/super cannot be used in constructor call
46
if (methodScope.isConstructorCall) {
47             methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
48             return false;
49         }
50     
51         // static may not refer to this/super
52
if (methodScope.isStatic) {
53             methodScope.problemReporter().errorThisSuperInStatic(this);
54             return false;
55         }
56         return true;
57     }
58
59     /*
60      * @see Reference#generateAssignment(...)
61      */

62     public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
63
64          // this cannot be assigned
65
}
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     /*
76      * @see Reference#generateCompoundAssignment(...)
77      */

78     public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
79
80          // this cannot be assigned
81
}
82     
83     /*
84      * @see org.eclipse.jdt.internal.compiler.ast.Reference#generatePostIncrement()
85      */

86     public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
87
88          // this cannot be assigned
89
}
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 JavaDoc printExpression(int indent, StringBuffer JavaDoc output){
106     
107         if (this.isImplicitThis()) return output;
108         return output.append("this"); //$NON-NLS-1$
109
}
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