*** empty log message ***
[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.CodeStream;
15 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
16 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
18
19 public class ThisReference extends Reference {
20         
21         public static final ThisReference ThisImplicit = new ThisReference();
22         
23 /**
24  * ThisReference constructor comment.
25  */
26 public ThisReference() {
27         super();
28 }
29 public ThisReference(int s, int sourceEnd) {
30         this();
31         this.sourceStart = s ;
32         this.sourceEnd = sourceEnd;
33 }
34 protected boolean checkAccess(MethodScope methodScope) {
35         // this/super cannot be used in constructor call
36         if (methodScope.isConstructorCall) {
37                 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
38                 return false;
39         }
40
41         // static may not refer to this/super
42         if (methodScope.isStatic) {
43                 methodScope.problemReporter().errorThisSuperInStatic(this);
44                 return false;
45         }
46         return true;
47 }
48 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
49         int pc = codeStream.position;
50         if (valueRequired)
51                 codeStream.aload_0();
52         codeStream.recordPositionsFrom(pc, this.sourceStart);
53 }
54 public boolean isThis() {
55         
56         return true ;
57 }
58 public TypeBinding resolveType(BlockScope scope) {
59         // implicit this
60         constant = NotAConstant;
61         if (this != ThisImplicit && !checkAccess(scope.methodScope()))
62                 return null;
63         return scope.enclosingSourceType();
64 }
65 public String toStringExpression(){
66
67         if (this == ThisImplicit) return "" ; //$NON-NLS-1$
68         return "this"; //$NON-NLS-1$
69 }
70 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
71         visitor.visit(this, blockScope);
72         visitor.endVisit(this, blockScope);
73 }
74 }