1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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 net.sourceforge.phpeclipse.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
20 public class QualifiedThisReference extends ThisReference {
22 public TypeReference qualification;
23 ReferenceBinding currentCompatibleType;
25 public QualifiedThisReference(TypeReference name, int sourceStart, int sourceEnd) {
26 super(sourceStart, sourceEnd);
28 this.sourceStart = name.sourceStart;
31 public FlowInfo analyseCode(
32 BlockScope currentScope,
33 FlowContext flowContext,
39 public FlowInfo analyseCode(
40 BlockScope currentScope,
41 FlowContext flowContext,
43 boolean valueRequired) {
49 * Code generation for QualifiedThisReference
51 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
52 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
53 * @param valueRequired boolean
55 // public void generateCode(
56 // BlockScope currentScope,
57 // CodeStream codeStream,
58 // boolean valueRequired) {
60 // int pc = codeStream.position;
61 // if (valueRequired) {
62 // if ((bits & DepthMASK) != 0) {
63 // Object[] emulationPath =
64 // currentScope.getEmulationPath(this.currentCompatibleType, true /*only exact match*/, false/*consider enclosing arg*/);
65 // codeStream.generateOuterAccess(emulationPath, this, this.currentCompatibleType, currentScope);
67 // // nothing particular after all
68 // codeStream.aload_0();
71 // codeStream.recordPositionsFrom(pc, this.sourceStart);
74 public TypeBinding resolveType(BlockScope scope) {
76 constant = NotAConstant;
77 this.resolvedType = qualification.resolveType(scope);
78 if (this.resolvedType == null) return null;
80 // the qualification MUST exactly match some enclosing type name
81 // Its possible to qualify 'this' by the name of the current class
83 this.currentCompatibleType = scope.referenceType().binding;
84 while (this.currentCompatibleType != null
85 && this.currentCompatibleType != this.resolvedType) {
87 this.currentCompatibleType = this.currentCompatibleType.isStatic() ? null : this.currentCompatibleType.enclosingType();
89 bits &= ~DepthMASK; // flush previous depth if any
90 bits |= (depth & 0xFF) << DepthSHIFT; // encoded depth into 8 bits
92 if (this.currentCompatibleType == null) {
93 scope.problemReporter().noSuchEnclosingInstance(this.resolvedType, this, false);
94 return this.resolvedType;
97 // Ensure one cannot write code like: B() { super(B.this); }
99 checkAccess(scope.methodScope());
100 } // if depth>0, path emulation will diagnose bad scenarii
101 return this.resolvedType;
104 public String toStringExpression() {
106 return qualification.toString(0) + ".this"; //$NON-NLS-1$
109 public void traverse(
110 IAbstractSyntaxTreeVisitor visitor,
111 BlockScope blockScope) {
113 if (visitor.visit(this, blockScope)) {
114 qualification.traverse(visitor, blockScope);
116 visitor.endVisit(this, blockScope);