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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
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.*;
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.resolvedType, syntheticField);
62 codeStream.recordPositionsFrom(pc, this.sourceStart);
65 public StringBuffer printExpression(int indent, StringBuffer output) {
67 return type.print(0, output).append(".class"); //$NON-NLS-1$
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 this.resolvedType = scope.getJavaLangClass();
87 BlockScope blockScope) {
89 if (visitor.visit(this, blockScope)) {
90 type.traverse(visitor, blockScope);
92 visitor.endVisit(this, blockScope);