KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > eval > CodeSnippetTypeDeclaration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.eval;
12
13 import org.eclipse.jdt.internal.compiler.ClassFile;
14 import org.eclipse.jdt.internal.compiler.CompilationResult;
15 import org.eclipse.jdt.internal.compiler.ast.ASTNode;
16 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17 import org.eclipse.jdt.internal.compiler.problem.AbortType;
18
19 public class CodeSnippetTypeDeclaration extends TypeDeclaration {
20
21 public CodeSnippetTypeDeclaration(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) return;
30     this.bits |= ASTNode.HasBeenGenerated;
31     
32     if (this.ignoreFurtherInvestigation) {
33         if (this.binding == null)
34             return;
35         CodeSnippetClassFile.createProblemType(this, this.scope.referenceCompilationUnit().compilationResult);
36         return;
37     }
38     try {
39         // create the result for a compiled type
40
ClassFile classFile = new CodeSnippetClassFile(this.binding, enclosingClassFile, false);
41         // generate all fiels
42
classFile.addFieldInfos();
43         if (this.binding.isMemberType()) {
44             classFile.recordInnerClasses(this.binding);
45         } else if (this.binding.isLocalType()) {
46             enclosingClassFile.recordInnerClasses(this.binding);
47             classFile.recordInnerClasses(this.binding);
48         }
49
50         if (this.memberTypes != null) {
51             for (int i = 0, max = this.memberTypes.length; i < max; i++) {
52                 TypeDeclaration memberType = this.memberTypes[i];
53                 classFile.recordInnerClasses(memberType.binding);
54                 memberType.generateCode(this.scope, classFile);
55             }
56         }
57         // generate all methods
58
classFile.setForMethodInfos();
59         if (this.methods != null) {
60             for (int i = 0, max = this.methods.length; i < max; i++) {
61                 this.methods[i].generateCode(this.scope, classFile);
62             }
63         }
64         
65         // generate all methods
66
classFile.addSpecialMethods();
67
68         if (this.ignoreFurtherInvestigation){ // trigger problem type generation for code gen errors
69
throw new AbortType(this.scope.referenceCompilationUnit().compilationResult, null);
70         }
71
72         // finalize the compiled type result
73
classFile.addAttributes();
74         this.scope.referenceCompilationUnit().compilationResult.record(this.binding.constantPoolName(), classFile);
75     } catch (AbortType e) {
76         if (this.binding == null)
77             return;
78         CodeSnippetClassFile.createProblemType(this, this.scope.referenceCompilationUnit().compilationResult);
79     }
80 }
81 }
82
Popular Tags