KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > ClassFilePool


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.compiler;
12
13 import java.util.Arrays JavaDoc;
14
15 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
16
17 public class ClassFilePool {
18     public static final int POOL_SIZE = 7;
19     ClassFile[] classFiles;
20     
21 private ClassFilePool() {
22     // prevent instantiation
23
this.classFiles = new ClassFile[POOL_SIZE];
24 }
25
26 public static ClassFilePool newInstance() {
27     return new ClassFilePool();
28 }
29
30 public void release(ClassFile classFile) {
31     for (int i = 0; i < POOL_SIZE; i++) {
32         ClassFile currentClassFile = this.classFiles[i];
33         if (currentClassFile == classFile) {
34             classFile.isShared = false;
35             return;
36         }
37     }
38 }
39     
40 public ClassFile acquire(SourceTypeBinding typeBinding) {
41     for (int i = 0; i < POOL_SIZE; i++) {
42         ClassFile classFile = this.classFiles[i];
43         if (classFile == null) {
44             ClassFile newClassFile = new ClassFile(typeBinding);
45             this.classFiles[i] = newClassFile;
46             newClassFile.isShared = true;
47             return newClassFile;
48         }
49         if (classFile.isShared) {
50             continue;
51         }
52         classFile.reset(typeBinding);
53         classFile.isShared = true;
54         return classFile;
55     }
56     return new ClassFile(typeBinding);
57 }
58 public void reset() {
59     Arrays.fill(this.classFiles, null);
60 }
61 // TypeBinding mostEnclosingType(TypeBinding binding) {
62
// TypeBinding currentBinding = binding;
63
// while (currentBinding.enclosingType() != null) {
64
// currentBinding = currentBinding.enclosingType();
65
// }
66
// return currentBinding;
67
// }
68
}
69
70
Popular Tags