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.phpdt.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,
36 FlowContext flowContext, FlowInfo flowInfo, Assignment assignment,
39 return flowInfo; // this cannot be assigned
42 public boolean checkAccess(MethodScope methodScope) {
44 // this/super cannot be used in constructor call
45 if (methodScope.isConstructorCall) {
46 methodScope.problemReporter()
47 .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
63 // codeStream, Assignment assignment, boolean valueRequired) {
65 // // this cannot be assigned
68 // public void generateCode(BlockScope currentScope, CodeStream codeStream,
69 // boolean valueRequired) {
71 // int pc = codeStream.position;
73 // codeStream.aload_0();
74 // if ((this.bits & IsImplicitThisMask) == 0)
75 // codeStream.recordPositionsFrom(pc, this.sourceStart);
79 // * @see Reference#generateCompoundAssignment(...)
81 // public void generateCompoundAssignment(BlockScope currentScope,
82 // CodeStream codeStream, Expression expression, int operator, int
83 // assignmentImplicitConversion, boolean valueRequired) {
85 // // this cannot be assigned
90 // net.sourceforge.phpdt.internal.compiler.ast.Reference#generatePostIncrement()
92 // public void generatePostIncrement(BlockScope currentScope, CodeStream
93 // codeStream, CompoundAssignment postIncrement, boolean
96 // // this cannot be assigned
98 public boolean isImplicitThis() {
100 return (this.bits & IsImplicitThisMask) != 0;
103 public boolean isThis() {
108 public TypeBinding resolveType(BlockScope scope) {
110 constant = NotAConstant;
111 if (!this.isImplicitThis() && !checkAccess(scope.methodScope()))
113 return this.resolvedType = scope.enclosingSourceType();
116 public StringBuffer printExpression(int indent, StringBuffer output) {
118 if (this.isImplicitThis())
120 return output.append("this"); //$NON-NLS-1$
123 public String toStringExpression() {
125 if (this.isImplicitThis())
126 return ""; //$NON-NLS-1$
127 return "this"; //$NON-NLS-1$
130 public void traverse(IAbstractSyntaxTreeVisitor visitor,
131 BlockScope blockScope) {
133 visitor.visit(this, blockScope);
134 visitor.endVisit(this, blockScope);