Added DESC_INC and IMG_INC for the image of include/require in outline (maybe we...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ClassLiteralAccess.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.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.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.*;
15 import net.sourceforge.phpdt.internal.compiler.flow.*;
16 import net.sourceforge.phpdt.internal.compiler.lookup.*;
17
18 public class ClassLiteralAccess extends Expression {
19         
20         public TypeReference type;
21         public TypeBinding targetType;
22         FieldBinding syntheticField;
23
24         public ClassLiteralAccess(int sourceEnd, TypeReference t) {
25                 type = t;
26                 this.sourceStart = t.sourceStart;
27                 this.sourceEnd = sourceEnd;
28         }
29
30         public FlowInfo analyseCode(
31                 BlockScope currentScope,
32                 FlowContext flowContext,
33                 FlowInfo flowInfo) {
34
35                 // if reachable, request the addition of a synthetic field for caching the class descriptor
36                 SourceTypeBinding sourceType =
37                         currentScope.outerMostMethodScope().enclosingSourceType();
38                 if (!(sourceType.isInterface()
39                         // no field generated in interface case (would'nt verify) see 1FHHEZL
40                         || sourceType.isBaseType())) {
41                         syntheticField = sourceType.addSyntheticField(targetType, currentScope);
42                 }
43                 return flowInfo;
44         }
45
46         /**
47          * MessageSendDotClass code generation
48          *
49          * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
50          * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
51          * @param valueRequired boolean
52          */
53         public void generateCode(
54                 BlockScope currentScope,
55                 CodeStream codeStream,
56                 boolean valueRequired) {
57                 int pc = codeStream.position;
58
59                 // in interface case, no caching occurs, since cannot make a cache field for interface
60                 if (valueRequired)
61                         codeStream.generateClassLiteralAccessForType(type.binding, syntheticField);
62                 codeStream.recordPositionsFrom(pc, this.sourceStart);
63         }
64
65         public TypeBinding resolveType(BlockScope scope) {
66
67                 constant = NotAConstant;
68                 if ((targetType = type.resolveType(scope)) == null)
69                         return null;
70
71                 if (targetType.isArrayType()
72                         && ((ArrayBinding) targetType).leafComponentType == VoidBinding) {
73                         scope.problemReporter().cannotAllocateVoidArray(this);
74                         return null;
75                 }
76
77                 return scope.getJavaLangClass();
78         }
79
80         public String toStringExpression() {
81
82                 String s = ""; //$NON-NLS-1$
83                 s = s + type.toString(0) + ".class"; //$NON-NLS-1$
84                 return s;
85         }
86
87         public void traverse(
88                 IAbstractSyntaxTreeVisitor visitor,
89                 BlockScope blockScope) {
90
91                 if (visitor.visit(this, blockScope)) {
92                         type.traverse(visitor, blockScope);
93                 }
94                 visitor.endVisit(this, blockScope);
95         }
96 }