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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.*;
15 import net.sourceforge.phpdt.internal.compiler.lookup.*;
17 public class ThisReference extends Reference {
19 public static final ThisReference ThisImplicit = new ThisReference();
22 * ThisReference constructor comment.
24 public ThisReference() {
27 public ThisReference(int s, int sourceEnd) {
29 this.sourceStart = s ;
30 this.sourceEnd = sourceEnd;
32 protected boolean checkAccess(MethodScope methodScope) {
33 // this/super cannot be used in constructor call
34 if (methodScope.isConstructorCall) {
35 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
39 // static may not refer to this/super
40 if (methodScope.isStatic) {
41 methodScope.problemReporter().errorThisSuperInStatic(this);
46 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
47 int pc = codeStream.position;
50 codeStream.recordPositionsFrom(pc, this.sourceStart);
52 public boolean isThis() {
56 public TypeBinding resolveType(BlockScope scope) {
58 constant = NotAConstant;
59 if (this != ThisImplicit && !checkAccess(scope.methodScope()))
61 return scope.enclosingSourceType();
63 public String toStringExpression(){
65 if (this == ThisImplicit) return "" ; //$NON-NLS-1$
66 return "this"; //$NON-NLS-1$
68 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
69 visitor.visit(this, blockScope);
70 visitor.endVisit(this, blockScope);