001: /*******************************************************************************
002: * Copyright (c) 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets;
011:
012: import java.util.LinkedHashMap;
013: import java.util.Map;
014:
015: import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType;
016: import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment;
017:
018: public class TypeSetEnvironment {
019:
020: private final TypeEnvironment fTypeEnvironment;
021: private final TypeUniverseSet fUniverse;
022: private final EmptyTypeSet fEmptyTypeSet;
023:
024: private final Map/*<TType, SubTypesOfSingleton>*/fSubtypesOfSingletons = new LinkedHashMap();//@perf
025: private final Map/*<TType, SubTypesSet>*/fSubTypesSets = new LinkedHashMap();//@perf
026: private final Map/*<TType, SuperTypesOfSingleton>*/fSuperTypesOfSingletons = new LinkedHashMap();//@perf
027: private final Map/*<TType, SuperTypesSet>*/fSuperTypesSets = new LinkedHashMap();//@perf
028:
029: private int fgCommonExprHits = 0;
030: private int fgCommonExprMisses = 0;
031:
032: public TypeSetEnvironment(TypeEnvironment typeEnvironment) {
033: fTypeEnvironment = typeEnvironment;
034: fUniverse = new TypeUniverseSet(this );
035: fEmptyTypeSet = new EmptyTypeSet(this );
036: }
037:
038: public TType getJavaLangObject() {
039: return fTypeEnvironment.getJavaLangObject();
040: }
041:
042: public TypeUniverseSet getUniverseTypeSet() {
043: return fUniverse;
044: }
045:
046: public EmptyTypeSet getEmptyTypeSet() {
047: return fEmptyTypeSet;
048: }
049:
050: public SubTypesOfSingleton createSubTypesOfSingleton(TType super Type) {
051: if (super Type.isJavaLangObject())
052: return this .getUniverseTypeSet();
053: if (fSubtypesOfSingletons.containsKey(super Type)) {
054: fgCommonExprHits++;
055: return (SubTypesOfSingleton) fSubtypesOfSingletons
056: .get(super Type);
057: } else {
058: SubTypesOfSingleton s = new SubTypesOfSingleton(super Type,
059: this );
060:
061: fgCommonExprMisses++;
062: fSubtypesOfSingletons.put(super Type, s);
063: return s;
064: }
065: }
066:
067: public SubTypesSet createSubTypesSet(TypeSet super Types) {
068: if (fSubTypesSets.containsKey(super Types)) {
069: fgCommonExprHits++;
070: return (SubTypesSet) fSubTypesSets.get(super Types);
071: } else {
072: SubTypesSet s = new SubTypesSet(super Types);
073:
074: fgCommonExprMisses++;
075: fSubTypesSets.put(super Types, s);
076: return s;
077: }
078: }
079:
080: public SuperTypesOfSingleton createSuperTypesOfSingleton(
081: TType subType) {
082: if (fSuperTypesOfSingletons.containsKey(subType)) {
083: fgCommonExprHits++;
084: return (SuperTypesOfSingleton) fSuperTypesOfSingletons
085: .get(subType);
086: } else {
087: SuperTypesOfSingleton s = new SuperTypesOfSingleton(
088: subType, this );
089:
090: fgCommonExprMisses++;
091: fSuperTypesOfSingletons.put(subType, s);
092: return s;
093: }
094: }
095:
096: public SuperTypesSet createSuperTypesSet(TType subType) {
097: if (fSuperTypesSets.containsKey(subType)) {
098: fgCommonExprHits++;
099: return (SuperTypesSet) fSuperTypesSets.get(subType);
100: } else {
101: SuperTypesSet s = new SuperTypesSet(subType, this );
102:
103: fgCommonExprMisses++;
104: fSuperTypesSets.put(subType, s);
105: return s;
106: }
107: }
108:
109: public SuperTypesSet createSuperTypesSet(TypeSet subTypes) {
110: if (fSuperTypesSets.containsKey(subTypes))
111: return (SuperTypesSet) fSuperTypesSets.get(subTypes);
112: else {
113: SuperTypesSet s = new SuperTypesSet(subTypes, this );
114:
115: fSuperTypesSets.put(subTypes, s);
116: return s;
117: }
118: }
119:
120: public void dumpStats() {
121: System.out
122: .println("Common expression hits: " + fgCommonExprHits); //$NON-NLS-1$
123: System.out
124: .println("Common expression misses: " + fgCommonExprMisses); //$NON-NLS-1$
125: }
126:
127: }
|