Made all bundles require a Java 1.4 EE, and backported some classescode to Java 1.4
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / QualifiedThisReference.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
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;
19
20 public class QualifiedThisReference extends ThisReference {
21
22         public TypeReference qualification;
23
24         ReferenceBinding currentCompatibleType;
25
26         public QualifiedThisReference(TypeReference name, int sourceStart,
27                         int sourceEnd) {
28                 super(sourceStart, sourceEnd);
29                 qualification = name;
30                 this.sourceStart = name.sourceStart;
31         }
32
33         public FlowInfo analyseCode(BlockScope currentScope,
34                         FlowContext flowContext, FlowInfo flowInfo) {
35
36                 return flowInfo;
37         }
38
39         public FlowInfo analyseCode(BlockScope currentScope,
40                         FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {
41
42                 return flowInfo;
43         }
44
45         /**
46          * Code generation for QualifiedThisReference
47          * 
48          * @param currentScope
49          *            net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
50          * @param codeStream
51          *            net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
52          * @param valueRequired
53          *            boolean
54          */
55         // public void generateCode(
56         // BlockScope currentScope,
57         // CodeStream codeStream,
58         // boolean valueRequired) {
59         //
60         // int pc = codeStream.position;
61         // if (valueRequired) {
62         // if ((bits & DepthMASK) != 0) {
63         // Object[] emulationPath =
64         // currentScope.getEmulationPath(this.currentCompatibleType, true /*only
65         // exact match*/, false/*consider enclosing arg*/);
66         // codeStream.generateOuterAccess(emulationPath, this,
67         // this.currentCompatibleType, currentScope);
68         // } else {
69         // // nothing particular after all
70         // codeStream.aload_0();
71         // }
72         // }
73         // codeStream.recordPositionsFrom(pc, this.sourceStart);
74         // }
75         public TypeBinding resolveType(BlockScope scope) {
76
77                 constant = NotAConstant;
78                 this.resolvedType = qualification.resolveType(scope);
79                 if (this.resolvedType == null)
80                         return null;
81
82                 // the qualification MUST exactly match some enclosing type name
83                 // Its possible to qualify 'this' by the name of the current class
84                 int depth = 0;
85                 this.currentCompatibleType = scope.referenceType().binding;
86                 while (this.currentCompatibleType != null
87                                 && this.currentCompatibleType != this.resolvedType) {
88                         depth++;
89                         this.currentCompatibleType = this.currentCompatibleType.isStatic() ? null
90                                         : this.currentCompatibleType.enclosingType();
91                 }
92                 bits &= ~DepthMASK; // flush previous depth if any
93                 bits |= (depth & 0xFF) << DepthSHIFT; // encoded depth into 8 bits
94
95                 if (this.currentCompatibleType == null) {
96                         scope.problemReporter().noSuchEnclosingInstance(this.resolvedType,
97                                         this, false);
98                         return this.resolvedType;
99                 }
100
101                 // Ensure one cannot write code like: B() { super(B.this); }
102                 if (depth == 0) {
103                         checkAccess(scope.methodScope());
104                 } // if depth>0, path emulation will diagnose bad scenarii
105                 return this.resolvedType;
106         }
107
108         public String toStringExpression() {
109
110                 return qualification.toString(0) + ".this"; //$NON-NLS-1$
111         }
112
113         public void traverse(ASTVisitor visitor, BlockScope blockScope) {
114
115                 if (visitor.visit(this, blockScope)) {
116                         qualification.traverse(visitor, blockScope);
117                 }
118                 visitor.endVisit(this, blockScope);
119         }
120 }