*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / ThisReference.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
19
20 public class ThisReference extends Reference {
21
22         public static ThisReference implicitThis(){
23
24                 ThisReference implicitThis = new ThisReference(0, 0); 
25                 implicitThis.bits |= IsImplicitThisMask;
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 & IsImplicitThisMask) == 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 & IsImplicitThisMask) != 0;
94         }
95
96         public boolean isThis() {
97                 
98                 return true ;
99         }
100
101         public TypeBinding resolveType(BlockScope scope) {
102         
103                 constant = NotAConstant;
104                 if (!this.isImplicitThis() && !checkAccess(scope.methodScope()))
105                         return null;
106                 return this.resolvedType = scope.enclosingSourceType();
107         }
108
109         public String toStringExpression(){
110         
111                 if (this.isImplicitThis()) return "" ; //$NON-NLS-1$
112                 return "this"; //$NON-NLS-1$
113         }
114
115         public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
116
117                 visitor.visit(this, blockScope);
118                 visitor.endVisit(this, blockScope);
119         }
120 }