fixed switch { .. default: case 'test': ... bug
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / ClassLiteralAccess.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.phpeclipse.internal.compiler.ast;
12
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.ArrayBinding;
17 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
18 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
19 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
20 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
21
22 public class ClassLiteralAccess extends Expression {
23         
24         public TypeReference type;
25         public TypeBinding targetType;
26         FieldBinding syntheticField;
27
28         public ClassLiteralAccess(int sourceEnd, TypeReference t) {
29                 type = t;
30                 this.sourceStart = t.sourceStart;
31                 this.sourceEnd = sourceEnd;
32         }
33
34         public FlowInfo analyseCode(
35                 BlockScope currentScope,
36                 FlowContext flowContext,
37                 FlowInfo flowInfo) {
38
39                 // if reachable, request the addition of a synthetic field for caching the class descriptor
40                 SourceTypeBinding sourceType =
41                         currentScope.outerMostMethodScope().enclosingSourceType();
42                 if (!(sourceType.isInterface()
43                         // no field generated in interface case (would'nt verify) see 1FHHEZL
44                         || sourceType.isBaseType())) {
45                         syntheticField = sourceType.addSyntheticField(targetType, currentScope);
46                 }
47                 return flowInfo;
48         }
49
50         /**
51          * MessageSendDotClass code generation
52          *
53          * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
54          * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
55          * @param valueRequired boolean
56          */
57 //      public void generateCode(
58 //              BlockScope currentScope,
59 //              CodeStream codeStream,
60 //              boolean valueRequired) {
61 //              int pc = codeStream.position;
62 //
63 //              // in interface case, no caching occurs, since cannot make a cache field for interface
64 //              if (valueRequired)
65 //                      codeStream.generateClassLiteralAccessForType(type.resolvedType, syntheticField);
66 //              codeStream.recordPositionsFrom(pc, this.sourceStart);
67 //      }
68
69         public TypeBinding resolveType(BlockScope scope) {
70
71                 constant = NotAConstant;
72                 if ((targetType = type.resolveType(scope)) == null)
73                         return null;
74
75                 if (targetType.isArrayType()
76                         && ((ArrayBinding) targetType).leafComponentType == VoidBinding) {
77                         scope.problemReporter().cannotAllocateVoidArray(this);
78                         return null;
79                 }
80
81                 return this.resolvedType = scope.getJavaLangClass();
82         }
83
84         public String toStringExpression() {
85
86                 String s = ""; //$NON-NLS-1$
87                 s = s + type.toString(0) + ".class"; //$NON-NLS-1$
88                 return s;
89         }
90
91         public void traverse(
92                 IAbstractSyntaxTreeVisitor visitor,
93                 BlockScope blockScope) {
94
95                 if (visitor.visit(this, blockScope)) {
96                         type.traverse(visitor, blockScope);
97                 }
98                 visitor.endVisit(this, blockScope);
99         }
100 }