misc changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ThisReference.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.*;
15 import net.sourceforge.phpdt.internal.compiler.lookup.*;
16
17 public class ThisReference extends Reference {
18         
19         public static final ThisReference ThisImplicit = new ThisReference();
20         
21 /**
22  * ThisReference constructor comment.
23  */
24 public ThisReference() {
25         super();
26 }
27 public ThisReference(int s, int sourceEnd) {
28         this();
29         this.sourceStart = s ;
30         this.sourceEnd = sourceEnd;
31 }
32 protected boolean checkAccess(MethodScope methodScope) {
33         // this/super cannot be used in constructor call
34         if (methodScope.isConstructorCall) {
35                 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
36                 return false;
37         }
38
39         // static may not refer to this/super
40         if (methodScope.isStatic) {
41                 methodScope.problemReporter().errorThisSuperInStatic(this);
42                 return false;
43         }
44         return true;
45 }
46 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
47         int pc = codeStream.position;
48         if (valueRequired)
49                 codeStream.aload_0();
50         codeStream.recordPositionsFrom(pc, this.sourceStart);
51 }
52 public boolean isThis() {
53         
54         return true ;
55 }
56 public TypeBinding resolveType(BlockScope scope) {
57         // implicit this
58         constant = NotAConstant;
59         if (this != ThisImplicit && !checkAccess(scope.methodScope()))
60                 return null;
61         return scope.enclosingSourceType();
62 }
63 public String toStringExpression(){
64
65         if (this == ThisImplicit) return "" ; //$NON-NLS-1$
66         return "this"; //$NON-NLS-1$
67 }
68 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
69         visitor.visit(this, blockScope);
70         visitor.endVisit(this, blockScope);
71 }
72 }