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 TypeBinding type = this.resolvedType = this.qualification.resolveType(scope, true /* check bounds*/);
76 if (type == null) return null;
77 // X.this is not a raw type as denoting enclosing instance
78 if (type.isRawType()) {
79 RawTypeBinding rawType = (RawTypeBinding) type;
80 type = this.resolvedType = rawType.type; // unwrap
82 // the qualification MUST exactly match some enclosing type name
83 // Its possible to qualify 'this' by the name of the current class
85 this.currentCompatibleType = scope.referenceType().binding;
86 while (this.currentCompatibleType != null
87 && this.currentCompatibleType != type) {
89 this.currentCompatibleType = this.currentCompatibleType.isStatic() ? null : this.currentCompatibleType.enclosingType();
91 bits &= ~DepthMASK; // flush previous depth if any
92 bits |= (depth & 0xFF) << DepthSHIFT; // encoded depth into 8 bits
94 if (this.currentCompatibleType == null) {
95 scope.problemReporter().noSuchEnclosingInstance(type, this, false);
99 // Ensure one cannot write code like: B() { super(B.this); }
101 checkAccess(scope.methodScope());
102 } // if depth>0, path emulation will diagnose bad scenarii
106 public StringBuffer printExpression(int indent, StringBuffer output) {
108 return qualification.print(0, output).append(".this"); //$NON-NLS-1$
111 public void traverse(
113 BlockScope blockScope) {
115 if (visitor.visit(this, blockScope)) {
116 qualification.traverse(visitor, blockScope);
118 visitor.endVisit(this, blockScope);