Makefile fixup
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / ClassLiteralAccess.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
12
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.*;
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.resolvedType, syntheticField);
62                 codeStream.recordPositionsFrom(pc, this.sourceStart);
63         }
64
65         public StringBuffer printExpression(int indent, StringBuffer output) {
66
67                 return type.print(0, output).append(".class"); //$NON-NLS-1$
68         }
69
70         public TypeBinding resolveType(BlockScope scope) {
71
72                 constant = NotAConstant;
73                 if ((targetType = type.resolveType(scope)) == null)
74                         return null;
75
76                 if (targetType.isArrayType()
77                         && ((ArrayBinding) targetType).leafComponentType == VoidBinding) {
78                         scope.problemReporter().cannotAllocateVoidArray(this);
79                         return null;
80                 }
81
82                 return this.resolvedType = scope.getJavaLangClass();
83         }
84
85         public void traverse(
86                 ASTVisitor visitor,
87                 BlockScope blockScope) {
88
89                 if (visitor.visit(this, blockScope)) {
90                         type.traverse(visitor, blockScope);
91                 }
92                 visitor.endVisit(this, blockScope);
93         }
94 }