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.*;
15 import net.sourceforge.phpdt.internal.compiler.flow.*;
16 import net.sourceforge.phpdt.internal.compiler.lookup.*;
18 public class ClassLiteralAccess extends Expression {
20 public TypeReference type;
21 public TypeBinding targetType;
22 FieldBinding syntheticField;
24 public ClassLiteralAccess(int sourceEnd, TypeReference t) {
26 this.sourceStart = t.sourceStart;
27 this.sourceEnd = sourceEnd;
30 public FlowInfo analyseCode(
31 BlockScope currentScope,
32 FlowContext flowContext,
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);
47 * MessageSendDotClass code generation
49 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
50 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
51 * @param valueRequired boolean
53 public void generateCode(
54 BlockScope currentScope,
55 CodeStream codeStream,
56 boolean valueRequired) {
57 int pc = codeStream.position;
59 // in interface case, no caching occurs, since cannot make a cache field for interface
61 codeStream.generateClassLiteralAccessForType(type.binding, syntheticField);
62 codeStream.recordPositionsFrom(pc, this.sourceStart);
65 public TypeBinding resolveType(BlockScope scope) {
67 constant = NotAConstant;
68 if ((targetType = type.resolveType(scope)) == null)
71 if (targetType.isArrayType()
72 && ((ArrayBinding) targetType).leafComponentType == VoidBinding) {
73 scope.problemReporter().cannotAllocateVoidArray(this);
77 return scope.getJavaLangClass();
80 public String toStringExpression() {
82 String s = ""; //$NON-NLS-1$
83 s = s + type.toString(0) + ".class"; //$NON-NLS-1$
88 IAbstractSyntaxTreeVisitor visitor,
89 BlockScope blockScope) {
91 if (visitor.visit(this, blockScope)) {
92 type.traverse(visitor, blockScope);
94 visitor.endVisit(this, blockScope);