KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > typeconstraints > typesets > TypeSetEnvironment


1 /*******************************************************************************
2  * Copyright (c) 2005 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
12 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets;
13
14 import java.util.LinkedHashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType;
18 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment;
19
20
21
22 public class TypeSetEnvironment {
23
24     private final TypeEnvironment fTypeEnvironment;
25     private final TypeUniverseSet fUniverse;
26     private final EmptyTypeSet fEmptyTypeSet;
27     
28     private final Map JavaDoc/*<TType, SubTypesOfSingleton>*/ fSubtypesOfSingletons= new LinkedHashMap JavaDoc();//@perf
29
private final Map JavaDoc/*<TType, SubTypesSet>*/ fSubTypesSets= new LinkedHashMap JavaDoc();//@perf
30
private final Map JavaDoc/*<TType, SuperTypesOfSingleton>*/ fSuperTypesOfSingletons= new LinkedHashMap JavaDoc();//@perf
31
private final Map JavaDoc/*<TType, SuperTypesSet>*/ fSuperTypesSets= new LinkedHashMap JavaDoc();//@perf
32

33     private int fgCommonExprHits= 0;
34     private int fgCommonExprMisses= 0;
35
36     public TypeSetEnvironment(TypeEnvironment typeEnvironment) {
37         fTypeEnvironment= typeEnvironment;
38         fUniverse= new TypeUniverseSet(this);
39         fEmptyTypeSet= new EmptyTypeSet(this);
40     }
41
42     public TType getJavaLangObject() {
43         return fTypeEnvironment.getJavaLangObject();
44     }
45
46     public TypeUniverseSet getUniverseTypeSet() {
47         return fUniverse;
48     }
49
50     public EmptyTypeSet getEmptyTypeSet() {
51         return fEmptyTypeSet;
52     }
53
54     public SubTypesOfSingleton createSubTypesOfSingleton(TType superType) {
55         if (superType.isJavaLangObject())
56             return this.getUniverseTypeSet();
57         if (fSubtypesOfSingletons.containsKey(superType)) {
58             fgCommonExprHits++;
59             return (SubTypesOfSingleton) fSubtypesOfSingletons.get(superType);
60         } else {
61             SubTypesOfSingleton s= new SubTypesOfSingleton(superType, this);
62     
63             fgCommonExprMisses++;
64             fSubtypesOfSingletons.put(superType, s);
65             return s;
66         }
67     }
68
69     public SubTypesSet createSubTypesSet(TypeSet superTypes) {
70         if (fSubTypesSets.containsKey(superTypes)) {
71             fgCommonExprHits++;
72             return (SubTypesSet) fSubTypesSets.get(superTypes);
73         } else {
74             SubTypesSet s= new SubTypesSet(superTypes);
75     
76             fgCommonExprMisses++;
77             fSubTypesSets.put(superTypes, s);
78             return s;
79         }
80     }
81
82     public SuperTypesOfSingleton createSuperTypesOfSingleton(TType subType) {
83         if (fSuperTypesOfSingletons.containsKey(subType)) {
84             fgCommonExprHits++;
85             return (SuperTypesOfSingleton) fSuperTypesOfSingletons.get(subType);
86         } else {
87             SuperTypesOfSingleton s= new SuperTypesOfSingleton(subType, this);
88     
89             fgCommonExprMisses++;
90             fSuperTypesOfSingletons.put(subType, s);
91             return s;
92         }
93     }
94
95     public SuperTypesSet createSuperTypesSet(TType subType) {
96         if (fSuperTypesSets.containsKey(subType)) {
97             fgCommonExprHits++;
98             return (SuperTypesSet) fSuperTypesSets.get(subType);
99         } else {
100             SuperTypesSet s= new SuperTypesSet(subType, this);
101     
102             fgCommonExprMisses++;
103             fSuperTypesSets.put(subType, s);
104             return s;
105         }
106     }
107
108     public SuperTypesSet createSuperTypesSet(TypeSet subTypes) {
109         if (fSuperTypesSets.containsKey(subTypes))
110             return (SuperTypesSet) fSuperTypesSets.get(subTypes);
111         else {
112             SuperTypesSet s= new SuperTypesSet(subTypes, this);
113     
114             fSuperTypesSets.put(subTypes, s);
115             return s;
116         }
117     }
118
119     public void dumpStats() {
120         System.out.println("Common expression hits: " + fgCommonExprHits); //$NON-NLS-1$
121
System.out.println("Common expression misses: " + fgCommonExprMisses); //$NON-NLS-1$
122
}
123
124 }
125
Popular Tags