Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ThisReference.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3  * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4  * http://www.eclipse.org/legal/cpl-v10.html
5  * 
6  * Contributors: IBM Corporation - initial API and implementation
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.ast;
9
10 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
11 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
12 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
13 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
14 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
15 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
16
17 public class ThisReference extends Reference {
18
19         public static ThisReference implicitThis() {
20
21                 ThisReference implicitThis = new ThisReference(0, 0);
22                 implicitThis.bits |= IsImplicitThisMask;
23                 return implicitThis;
24         }
25
26         public ThisReference(int sourceStart, int sourceEnd) {
27
28                 this.sourceStart = sourceStart;
29                 this.sourceEnd = sourceEnd;
30         }
31
32         /*
33          * @see Reference#analyseAssignment(...)
34          */
35         public FlowInfo analyseAssignment(BlockScope currentScope,
36                         FlowContext flowContext, FlowInfo flowInfo, Assignment assignment,
37                         boolean isCompound) {
38
39                 return flowInfo; // this cannot be assigned
40         }
41
42         public boolean checkAccess(MethodScope methodScope) {
43
44                 // this/super cannot be used in constructor call
45                 if (methodScope.isConstructorCall) {
46                         methodScope.problemReporter()
47                                         .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
63         // codeStream, Assignment assignment, boolean valueRequired) {
64         //
65         // // this cannot be assigned
66         // }
67         //
68         // public void generateCode(BlockScope currentScope, CodeStream codeStream,
69         // boolean valueRequired) {
70         //      
71         // int pc = codeStream.position;
72         // if (valueRequired)
73         // codeStream.aload_0();
74         // if ((this.bits & IsImplicitThisMask) == 0)
75         // codeStream.recordPositionsFrom(pc, this.sourceStart);
76         // }
77         //
78         // /*
79         // * @see Reference#generateCompoundAssignment(...)
80         // */
81         // public void generateCompoundAssignment(BlockScope currentScope,
82         // CodeStream codeStream, Expression expression, int operator, int
83         // assignmentImplicitConversion, boolean valueRequired) {
84         //
85         // // this cannot be assigned
86         // }
87         //      
88         // /*
89         // * @see
90         // net.sourceforge.phpdt.internal.compiler.ast.Reference#generatePostIncrement()
91         // */
92         // public void generatePostIncrement(BlockScope currentScope, CodeStream
93         // codeStream, CompoundAssignment postIncrement, boolean
94         // valueRequired) {
95         //
96         // // this cannot be assigned
97         // }
98         public boolean isImplicitThis() {
99
100                 return (this.bits & IsImplicitThisMask) != 0;
101         }
102
103         public boolean isThis() {
104
105                 return true;
106         }
107
108         public TypeBinding resolveType(BlockScope scope) {
109
110                 constant = NotAConstant;
111                 if (!this.isImplicitThis() && !checkAccess(scope.methodScope()))
112                         return null;
113                 return this.resolvedType = scope.enclosingSourceType();
114         }
115
116         public StringBuffer printExpression(int indent, StringBuffer output) {
117
118                 if (this.isImplicitThis())
119                         return output;
120                 return output.append("this"); //$NON-NLS-1$
121         }
122
123         public String toStringExpression() {
124
125                 if (this.isImplicitThis())
126                         return ""; //$NON-NLS-1$
127                 return "this"; //$NON-NLS-1$
128         }
129
130         public void traverse(IAbstractSyntaxTreeVisitor visitor,
131                         BlockScope blockScope) {
132
133                 visitor.visit(this, blockScope);
134                 visitor.endVisit(this, blockScope);
135         }
136 }