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.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;
19 public class ThisReference extends Reference {
21 public static final ThisReference ThisImplicit = new ThisReference();
24 * ThisReference constructor comment.
26 public ThisReference() {
29 public ThisReference(int s, int sourceEnd) {
31 this.sourceStart = s ;
32 this.sourceEnd = sourceEnd;
34 protected boolean checkAccess(MethodScope methodScope) {
35 // this/super cannot be used in constructor call
36 if (methodScope.isConstructorCall) {
37 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
41 // static may not refer to this/super
42 if (methodScope.isStatic) {
43 methodScope.problemReporter().errorThisSuperInStatic(this);
48 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
49 int pc = codeStream.position;
52 codeStream.recordPositionsFrom(pc, this.sourceStart);
54 public boolean isThis() {
58 public TypeBinding resolveType(BlockScope scope) {
60 constant = NotAConstant;
61 if (this != ThisImplicit && !checkAccess(scope.methodScope()))
63 return scope.enclosingSourceType();
65 public String toStringExpression(){
67 if (this == ThisImplicit) return "" ; //$NON-NLS-1$
68 return "this"; //$NON-NLS-1$
70 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
71 visitor.visit(this, blockScope);
72 visitor.endVisit(this, blockScope);