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.*;
16 import org.eclipse.jdt.internal.compiler.lookup.*;
18 public class QualifiedThisReference extends ThisReference {
20 public TypeReference qualification;
21 ReferenceBinding currentCompatibleType;
23 public QualifiedThisReference(TypeReference name, int sourceStart, int sourceEnd) {
24 super(sourceStart, sourceEnd);
26 this.sourceStart = name.sourceStart;
29 public FlowInfo analyseCode(
30 BlockScope currentScope,
31 FlowContext flowContext,
37 public FlowInfo analyseCode(
38 BlockScope currentScope,
39 FlowContext flowContext,
41 boolean valueRequired) {
47 * Code generation for QualifiedThisReference
49 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
50 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
51 * @param valueRequired boolean
53 public void generateCode(
54 BlockScope currentScope,
55 CodeStream codeStream,
56 boolean valueRequired) {
58 int pc = codeStream.position;
60 if ((bits & DepthMASK) != 0) {
61 Object[] emulationPath =
62 currentScope.getEmulationPath(this.currentCompatibleType, true /*only exact match*/, false/*consider enclosing arg*/);
63 codeStream.generateOuterAccess(emulationPath, this, this.currentCompatibleType, currentScope);
65 // nothing particular after all
69 codeStream.recordPositionsFrom(pc, this.sourceStart);
72 public TypeBinding resolveType(BlockScope scope) {
74 constant = NotAConstant;
75 this.resolvedType = this.qualification.resolveType(scope);
76 if (this.resolvedType == null) return null;
78 // the qualification MUST exactly match some enclosing type name
79 // Its possible to qualify 'this' by the name of the current class
81 this.currentCompatibleType = scope.referenceType().binding;
82 while (this.currentCompatibleType != null
83 && this.currentCompatibleType != this.resolvedType) {
85 this.currentCompatibleType = this.currentCompatibleType.isStatic() ? null : this.currentCompatibleType.enclosingType();
87 bits &= ~DepthMASK; // flush previous depth if any
88 bits |= (depth & 0xFF) << DepthSHIFT; // encoded depth into 8 bits
90 if (this.currentCompatibleType == null) {
91 scope.problemReporter().noSuchEnclosingInstance(this.resolvedType, this, false);
92 return this.resolvedType;
95 // Ensure one cannot write code like: B() { super(B.this); }
97 checkAccess(scope.methodScope());
98 } // if depth>0, path emulation will diagnose bad scenarii
99 return this.resolvedType;
102 public StringBuffer printExpression(int indent, StringBuffer output) {
104 return qualification.print(0, output).append(".this"); //$NON-NLS-1$
107 public void traverse(
109 BlockScope blockScope) {
111 if (visitor.visit(this, blockScope)) {
112 qualification.traverse(visitor, blockScope);
114 visitor.endVisit(this, blockScope);