1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.internal.compiler.ast;
10 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
11 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
12 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
13 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
14 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
15 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
17 public class ThisReference extends Reference {
19 public static ThisReference implicitThis() {
21 ThisReference implicitThis = new ThisReference(0, 0);
22 implicitThis.bits |= IsImplicitThisMask;
26 public ThisReference(int sourceStart, int sourceEnd) {
28 this.sourceStart = sourceStart;
29 this.sourceEnd = sourceEnd;
33 * @see Reference#analyseAssignment(...)
35 public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment,
38 return flowInfo; // this cannot be assigned
41 public boolean checkAccess(MethodScope methodScope) {
43 // this/super cannot be used in constructor call
44 if (methodScope.isConstructorCall) {
45 methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
49 // static may not refer to this/super
50 if (methodScope.isStatic) {
51 methodScope.problemReporter().errorThisSuperInStatic(this);
58 * @see Reference#generateAssignment(...)
60 // public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
62 // // this cannot be assigned
65 // public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
67 // int pc = codeStream.position;
69 // codeStream.aload_0();
70 // if ((this.bits & IsImplicitThisMask) == 0) codeStream.recordPositionsFrom(pc, this.sourceStart);
74 // * @see Reference#generateCompoundAssignment(...)
76 // public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int
77 // assignmentImplicitConversion, boolean valueRequired) {
79 // // this cannot be assigned
83 // * @see net.sourceforge.phpdt.internal.compiler.ast.Reference#generatePostIncrement()
85 // public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean
88 // // this cannot be assigned
90 public boolean isImplicitThis() {
92 return (this.bits & IsImplicitThisMask) != 0;
95 public boolean isThis() {
100 public TypeBinding resolveType(BlockScope scope) {
102 constant = NotAConstant;
103 if (!this.isImplicitThis() && !checkAccess(scope.methodScope()))
105 return this.resolvedType = scope.enclosingSourceType();
108 public StringBuffer printExpression(int indent, StringBuffer output) {
110 if (this.isImplicitThis())
112 return output.append("this"); //$NON-NLS-1$
115 public String toStringExpression() {
117 if (this.isImplicitThis())
118 return ""; //$NON-NLS-1$
119 return "this"; //$NON-NLS-1$
122 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
124 visitor.visit(this, blockScope);
125 visitor.endVisit(this, blockScope);