1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 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 org.eclipse.jdt.internal.compiler.ast;
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.codegen.*;
15 import org.eclipse.jdt.internal.compiler.flow.FlowContext;
16 import org.eclipse.jdt.internal.compiler.flow.FlowInfo;
17 import org.eclipse.jdt.internal.compiler.lookup.*;
19 public class ThisReference extends Reference {
21 public static ThisReference implicitThis(){
23 ThisReference implicitThis = new ThisReference(0, 0);
24 implicitThis.bits |= IsImplicitThisMask;
28 public ThisReference(int sourceStart, int sourceEnd) {
30 this.sourceStart = sourceStart;
31 this.sourceEnd = sourceEnd;
35 * @see Reference#analyseAssignment(...)
37 public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
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().fieldsOrThisBeforeConstructorInvocation(this);
50 // static may not refer to this/super
51 if (methodScope.isStatic) {
52 methodScope.problemReporter().errorThisSuperInStatic(this);
59 * @see Reference#generateAssignment(...)
61 public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
63 // this cannot be assigned
66 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
68 int pc = codeStream.position;
71 if ((this.bits & IsImplicitThisMask) == 0) codeStream.recordPositionsFrom(pc, this.sourceStart);
75 * @see Reference#generateCompoundAssignment(...)
77 public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
79 // this cannot be assigned
83 * @see org.eclipse.jdt.internal.compiler.ast.Reference#generatePostIncrement()
85 public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
87 // this cannot be assigned
90 public boolean isImplicitThis() {
92 return (this.bits & IsImplicitThisMask) != 0;
95 public boolean isThis() {
100 public StringBuffer printExpression(int indent, StringBuffer output){
102 if (this.isImplicitThis()) return output;
103 return output.append("this"); //$NON-NLS-1$
106 public TypeBinding resolveType(BlockScope scope) {
108 constant = NotAConstant;
109 if (!this.isImplicitThis() &&!checkAccess(scope.methodScope())) {
112 return this.resolvedType = scope.enclosingSourceType();
115 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
117 visitor.visit(this, blockScope);
118 visitor.endVisit(this, blockScope);