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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.internal.compiler.ast;
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;
20 public class ThisReference extends Reference {
22 public static ThisReference implicitThis(){
24 ThisReference implicitThis = new ThisReference(0, 0);
25 implicitThis.bits |= IsImplicitThisMask;
29 public ThisReference(int sourceStart, int sourceEnd) {
31 this.sourceStart = sourceStart;
32 this.sourceEnd = sourceEnd;
36 * @see Reference#analyseAssignment(...)
38 public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
40 return flowInfo; // this cannot be assigned
43 public boolean checkAccess(MethodScope methodScope) {
45 // this/super cannot be used in constructor call
46 if (methodScope.isConstructorCall) {
47 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
51 // static may not refer to this/super
52 if (methodScope.isStatic) {
53 methodScope.problemReporter().errorThisSuperInStatic(this);
60 * @see Reference#generateAssignment(...)
62 // public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
64 // // this cannot be assigned
67 // public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
69 // int pc = codeStream.position;
71 // codeStream.aload_0();
72 // if ((this.bits & IsImplicitThisMask) == 0) codeStream.recordPositionsFrom(pc, this.sourceStart);
76 // * @see Reference#generateCompoundAssignment(...)
78 // public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
80 // // this cannot be assigned
84 // * @see org.eclipse.jdt.internal.compiler.ast.Reference#generatePostIncrement()
86 // public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
88 // // this cannot be assigned
91 public boolean isImplicitThis() {
93 return (this.bits & IsImplicitThisMask) != 0;
96 public boolean isThis() {
101 public TypeBinding resolveType(BlockScope scope) {
103 constant = NotAConstant;
104 if (!this.isImplicitThis() && !checkAccess(scope.methodScope()))
106 return this.resolvedType = scope.enclosingSourceType();
109 public String toStringExpression(){
111 if (this.isImplicitThis()) return "" ; //$NON-NLS-1$
112 return "this"; //$NON-NLS-1$
115 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
117 visitor.visit(this, blockScope);
118 visitor.endVisit(this, blockScope);