01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.eval;
11:
12: import org.eclipse.jdt.internal.compiler.ClassFile;
13: import org.eclipse.jdt.internal.compiler.CompilationResult;
14: import org.eclipse.jdt.internal.compiler.ast.ASTNode;
15: import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
16: import org.eclipse.jdt.internal.compiler.problem.AbortType;
17:
18: public class CodeSnippetTypeDeclaration extends TypeDeclaration {
19:
20: public CodeSnippetTypeDeclaration(
21: CompilationResult compilationResult) {
22: super (compilationResult);
23: }
24:
25: /**
26: * Generic bytecode generation for type
27: */
28: public void generateCode(ClassFile enclosingClassFile) {
29: if ((this .bits & ASTNode.HasBeenGenerated) != 0)
30: return;
31: this .bits |= ASTNode.HasBeenGenerated;
32:
33: if (this .ignoreFurtherInvestigation) {
34: if (this .binding == null)
35: return;
36: CodeSnippetClassFile.createProblemType(this , this .scope
37: .referenceCompilationUnit().compilationResult);
38: return;
39: }
40: try {
41: // create the result for a compiled type
42: ClassFile classFile = new CodeSnippetClassFile(
43: this .binding, enclosingClassFile, false);
44: // generate all fiels
45: classFile.addFieldInfos();
46: if (this .binding.isMemberType()) {
47: classFile.recordInnerClasses(this .binding);
48: } else if (this .binding.isLocalType()) {
49: enclosingClassFile.recordInnerClasses(this .binding);
50: classFile.recordInnerClasses(this .binding);
51: }
52:
53: if (this .memberTypes != null) {
54: for (int i = 0, max = this .memberTypes.length; i < max; i++) {
55: TypeDeclaration memberType = this .memberTypes[i];
56: classFile.recordInnerClasses(memberType.binding);
57: memberType.generateCode(this .scope, classFile);
58: }
59: }
60: // generate all methods
61: classFile.setForMethodInfos();
62: if (this .methods != null) {
63: for (int i = 0, max = this .methods.length; i < max; i++) {
64: this .methods[i].generateCode(this .scope, classFile);
65: }
66: }
67:
68: // generate all methods
69: classFile.addSpecialMethods();
70:
71: if (this .ignoreFurtherInvestigation) { // trigger problem type generation for code gen errors
72: throw new AbortType(this .scope
73: .referenceCompilationUnit().compilationResult,
74: null);
75: }
76:
77: // finalize the compiled type result
78: classFile.addAttributes();
79: this .scope.referenceCompilationUnit().compilationResult
80: .record(this .binding.constantPoolName(), classFile);
81: } catch (AbortType e) {
82: if (this.binding == null)
83: return;
84: CodeSnippetClassFile.createProblemType(this, this.scope
85: .referenceCompilationUnit().compilationResult);
86: }
87: }
88: }
|