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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
16 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
17 import net.sourceforge.phpdt.internal.compiler.lookup.ArrayBinding;
18 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
19 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
20 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
23 public class ClassLiteralAccess extends Expression {
25 public TypeReference type;
26 public TypeBinding targetType;
27 FieldBinding syntheticField;
29 public ClassLiteralAccess(int sourceEnd, TypeReference t) {
31 this.sourceStart = t.sourceStart;
32 this.sourceEnd = sourceEnd;
35 public FlowInfo analyseCode(
36 BlockScope currentScope,
37 FlowContext flowContext,
40 // if reachable, request the addition of a synthetic field for caching the class descriptor
41 SourceTypeBinding sourceType =
42 currentScope.outerMostMethodScope().enclosingSourceType();
43 if (!(sourceType.isInterface()
44 // no field generated in interface case (would'nt verify) see 1FHHEZL
45 || sourceType.isBaseType())) {
46 syntheticField = sourceType.addSyntheticField(targetType, currentScope);
52 * MessageSendDotClass code generation
54 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
55 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
56 * @param valueRequired boolean
58 public void generateCode(
59 BlockScope currentScope,
60 CodeStream codeStream,
61 boolean valueRequired) {
62 int pc = codeStream.position;
64 // in interface case, no caching occurs, since cannot make a cache field for interface
66 codeStream.generateClassLiteralAccessForType(type.binding, syntheticField);
67 codeStream.recordPositionsFrom(pc, this.sourceStart);
70 public TypeBinding resolveType(BlockScope scope) {
72 constant = NotAConstant;
73 if ((targetType = type.resolveType(scope)) == null)
76 if (targetType.isArrayType()
77 && ((ArrayBinding) targetType).leafComponentType == VoidBinding) {
78 scope.problemReporter().cannotAllocateVoidArray(this);
82 return scope.getJavaLangClass();
85 public String toStringExpression() {
87 String s = ""; //$NON-NLS-1$
88 s = s + type.toString(0) + ".class"; //$NON-NLS-1$
93 IAbstractSyntaxTreeVisitor visitor,
94 BlockScope blockScope) {
96 if (visitor.visit(this, blockScope)) {
97 type.traverse(visitor, blockScope);
99 visitor.endVisit(this, blockScope);