]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/typesets/TypeSetEnvironment.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core refactoring / org / eclipse / jdt / internal / corext / refactoring / typeconstraints / typesets / TypeSetEnvironment.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2005, 2011 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
12package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets;
13
14import java.util.LinkedHashMap;
15import java.util.Map;
16
17import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType;
18import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment;
19
20
21
22public class TypeSetEnvironment {
23
24 private final TypeEnvironment fTypeEnvironment;
25 private final TypeUniverseSet fUniverse;
26 private final EmptyTypeSet fEmptyTypeSet;
27
28 private final Map<TType, SubTypesOfSingleton> fSubtypesOfSingletons= new LinkedHashMap<TType, SubTypesOfSingleton>();//@perf
29 private final Map<TypeSet, SubTypesSet> fSubTypesSets= new LinkedHashMap<TypeSet, SubTypesSet>();//@perf
30 private final Map<TType, SuperTypesOfSingleton> fSuperTypesOfSingletons= new LinkedHashMap<TType, SuperTypesOfSingleton>();//@perf
31 private final Map<Object, SuperTypesSet> fSuperTypesSets= new LinkedHashMap<Object, SuperTypesSet>();//@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 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 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 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 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 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}