Java 1.5 generification of JTypeOracle.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1644 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
index 184dd88..731306b 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
@@ -19,7 +19,6 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -29,31 +28,31 @@
*/
public class JTypeOracle {
- private final Map/* <JInterfaceType, Set<JClassType>> */couldBeImplementedMap = new IdentityHashMap();
+ private final Map<JInterfaceType, Set<JClassType>> couldBeImplementedMap = new IdentityHashMap<JInterfaceType, Set<JClassType>>();
- private final Map/* <JClassType, Set<JInterfaceType>> */couldImplementMap = new IdentityHashMap();
+ private final Map<JClassType, Set<JInterfaceType>> couldImplementMap = new IdentityHashMap<JClassType, Set<JInterfaceType>>();
- private final Set/* <JReferenceType> */hasClinitSet = new HashSet();
+ private final Set<JReferenceType> hasClinitSet = new HashSet<JReferenceType>();
- private final Map/* <JClassType, Set<JInterfaceType>> */implementsMap = new IdentityHashMap();
+ private final Map<JClassType, Set<JInterfaceType>> implementsMap = new IdentityHashMap<JClassType, Set<JInterfaceType>>();
- private final Set/* <JReferenceType> */instantiatedTypes = new HashSet();
+ private final Set<JReferenceType> instantiatedTypes = new HashSet<JReferenceType>();
- private final Map/* <JInterfaceType, Set<JClassType>> */isImplementedMap = new IdentityHashMap();
+ private final Map<JInterfaceType, Set<JClassType>> isImplementedMap = new IdentityHashMap<JInterfaceType, Set<JClassType>>();
private JClassType javaLangObject = null;
private final JProgram program;
- private final Map/* <JClassType, Set<JClassType>> */subClassMap = new IdentityHashMap();
+ private final Map<JClassType, Set<JClassType>> subClassMap = new IdentityHashMap<JClassType, Set<JClassType>>();
- private final Map/* <JInterfaceType, Set<JInterfaceType>> */subInterfaceMap = new IdentityHashMap();
+ private final Map<JInterfaceType, Set<JInterfaceType>> subInterfaceMap = new IdentityHashMap<JInterfaceType, Set<JInterfaceType>>();
- private final Map/* <JClassType, Set<JClassType>> */superClassMap = new IdentityHashMap();
+ private final Map<JClassType, Set<JClassType>> superClassMap = new IdentityHashMap<JClassType, Set<JClassType>>();
- private final Map/* <JInterfaceType, Set<JInterfaceType>> */superInterfaceMap = new IdentityHashMap();
+ private final Map<JInterfaceType, Set<JInterfaceType>> superInterfaceMap = new IdentityHashMap<JInterfaceType, Set<JInterfaceType>>();
- private final Map/* <JMethod, Map<JClassType, Set<JMethod>>> */virtualUpRefMap = new IdentityHashMap();
+ private final Map<JMethod, Map<JClassType, Set<JMethod>>> virtualUpRefMap = new IdentityHashMap<JMethod, Map<JClassType, Set<JMethod>>>();
public JTypeOracle(JProgram program) {
this.program = program;
@@ -205,7 +204,7 @@
couldBeImplementedMap.clear();
for (int i = 0; i < program.getDeclaredTypes().size(); ++i) {
- JReferenceType type = (JReferenceType) program.getDeclaredTypes().get(i);
+ JReferenceType type = program.getDeclaredTypes().get(i);
if (type instanceof JClassType) {
recordSuperSubInfo((JClassType) type);
} else {
@@ -213,19 +212,19 @@
}
}
for (int i = 0; i < program.getDeclaredTypes().size(); ++i) {
- JReferenceType type = (JReferenceType) program.getDeclaredTypes().get(i);
+ JReferenceType type = program.getDeclaredTypes().get(i);
if (type instanceof JClassType) {
computeImplements((JClassType) type);
}
}
for (int i = 0; i < program.getDeclaredTypes().size(); ++i) {
- JReferenceType type = (JReferenceType) program.getDeclaredTypes().get(i);
+ JReferenceType type = program.getDeclaredTypes().get(i);
if (type instanceof JClassType) {
computeCouldImplement((JClassType) type);
}
}
for (int i = 0; i < program.getDeclaredTypes().size(); ++i) {
- JReferenceType type = (JReferenceType) program.getDeclaredTypes().get(i);
+ JReferenceType type = program.getDeclaredTypes().get(i);
if (type instanceof JClassType) {
computeVirtualUpRefs((JClassType) type);
}
@@ -240,20 +239,19 @@
}
public JMethod[] getAllVirtualOverrides(JMethod method) {
- Set/* <JMethod> */results = new HashSet/* <JMethod> */();
- Map/* <JClassType, Set<JMethod>> */overrideMap = getOrCreateMap(
- virtualUpRefMap, method);
- for (Iterator it = overrideMap.keySet().iterator(); it.hasNext();) {
- JClassType classType = (JClassType) it.next();
+ Set<JMethod> results = new HashSet<JMethod>();
+ Map<JClassType, Set<JMethod>> overrideMap = getOrCreateMap(virtualUpRefMap,
+ method);
+ for (JClassType classType : overrideMap.keySet()) {
if (instantiatedTypes.contains(classType)) {
- Set/* <JMethod> */set = (Set) overrideMap.get(classType);
+ Set<JMethod> set = overrideMap.get(classType);
results.addAll(set);
}
}
- return (JMethod[]) results.toArray(new JMethod[results.size()]);
+ return results.toArray(new JMethod[results.size()]);
}
- public Set/* <JReferenceType> */getInstantiatedTypes() {
+ public Set<JReferenceType> getInstantiatedTypes() {
return instantiatedTypes;
}
@@ -300,18 +298,17 @@
public void recomputeClinits() {
hasClinitSet.clear();
for (int i = 0; i < program.getDeclaredTypes().size(); ++i) {
- JReferenceType type = (JReferenceType) program.getDeclaredTypes().get(i);
+ JReferenceType type = program.getDeclaredTypes().get(i);
computeHasClinit(type);
}
}
- public void setInstantiatedTypes(Set/* <JReferenceType> */instantiatedTypes) {
+ public void setInstantiatedTypes(Set<JReferenceType> instantiatedTypes) {
this.instantiatedTypes.clear();
this.instantiatedTypes.addAll(instantiatedTypes);
}
- private/* <K, V> */void add(Map/* <K, Set<V>> */map, Object key,
- Object value) {
+ private <K, V> void add(Map<K, Set<V>> map, K key, V value) {
getOrCreate(map, key).add(value);
}
@@ -320,31 +317,26 @@
* super types or sub types.
*/
private void computeCouldImplement(JClassType type) {
- Set/* <JInterfaceType> */couldImplementSet = getOrCreate(
- couldImplementMap, type);
+ Set<JInterfaceType> couldImplementSet = getOrCreate(couldImplementMap, type);
// all of my direct implements are trivially true
couldImplementSet.addAll(getOrCreate(implementsMap, type));
- List/* <JClassType> */subclasses = new ArrayList/* <JClassType> */();
+ List<JClassType> subclasses = new ArrayList<JClassType>();
subclasses.addAll(getOrCreate(subClassMap, type));
- for (Iterator itSub = subclasses.iterator(); itSub.hasNext();) {
- JClassType subclass = (JClassType) itSub.next();
- for (Iterator itIntf = subclass.implments.iterator(); itIntf.hasNext();) {
- JInterfaceType intf = (JInterfaceType) itIntf.next();
+ for (JClassType subclass : subclasses) {
+ for (JInterfaceType intf : subclass.implments) {
couldImplementSet.add(intf);
- for (Iterator itIsUp = getOrCreate(superInterfaceMap, intf).iterator(); itIsUp.hasNext();) {
- JInterfaceType isup = (JInterfaceType) itIsUp.next();
+ for (JInterfaceType isup : getOrCreate(superInterfaceMap, intf)) {
couldImplementSet.add(isup);
}
}
}
- for (Iterator itCouldImpl = couldImplementSet.iterator(); itCouldImpl.hasNext();) {
- JInterfaceType couldImpl = (JInterfaceType) itCouldImpl.next();
+ for (JInterfaceType couldImpl : couldImplementSet) {
add(couldBeImplementedMap, couldImpl, type);
}
}
private void computeHasClinit(JReferenceType type) {
- JMethod method = (JMethod) type.methods.get(0);
+ JMethod method = type.methods.get(0);
JMethodBody body = (JMethodBody) method.getBody();
if (!body.getStatements().isEmpty()) {
hasClinitSet.add(type);
@@ -355,23 +347,19 @@
* Compute all of the things I implement directly, through super types.
*/
private void computeImplements(JClassType type) {
- Set/* <JInterfaceType> */implementsSet = getOrCreate(implementsMap, type);
- List/* <JClassType> */list = new ArrayList/* <JClassType> */();
+ Set<JInterfaceType> implementsSet = getOrCreate(implementsMap, type);
+ List<JClassType> list = new ArrayList<JClassType>();
list.add(type);
list.addAll(getOrCreate(superClassMap, type));
- for (Iterator itSuper = list.iterator(); itSuper.hasNext();) {
- JClassType superclass = (JClassType) itSuper.next();
- for (Iterator itIntf = superclass.implments.iterator(); itIntf.hasNext();) {
- JInterfaceType intf = (JInterfaceType) itIntf.next();
+ for (JClassType superclass : list) {
+ for (JInterfaceType intf : superclass.implments) {
implementsSet.add(intf);
- for (Iterator itIsUp = getOrCreate(superInterfaceMap, intf).iterator(); itIsUp.hasNext();) {
- JInterfaceType isup = (JInterfaceType) itIsUp.next();
+ for (JInterfaceType isup : getOrCreate(superInterfaceMap, intf)) {
implementsSet.add(isup);
}
}
}
- for (Iterator itImpl = implementsSet.iterator(); itImpl.hasNext();) {
- JInterfaceType impl = (JInterfaceType) itImpl.next();
+ for (JInterfaceType impl : implementsSet) {
add(isImplementedMap, impl, type);
}
}
@@ -393,13 +381,10 @@
* I define implementations for them. If I don't, then check all my super
* classes to find virtual overrides.
*/
- for (Iterator itIntf = type.implments.iterator(); itIntf.hasNext();) {
- JInterfaceType intf = (JInterfaceType) itIntf.next();
+ for (JInterfaceType intf : type.implments) {
computeVirtualUpRefs(type, intf);
- Set/* <JInterfaceType> */superIntfs = getOrCreate(superInterfaceMap,
- intf);
- for (Iterator itSuper = superIntfs.iterator(); itSuper.hasNext();) {
- JInterfaceType superIntf = (JInterfaceType) itSuper.next();
+ Set<JInterfaceType> superIntfs = getOrCreate(superInterfaceMap, intf);
+ for (JInterfaceType superIntf : superIntfs) {
computeVirtualUpRefs(type, superIntf);
}
}
@@ -411,10 +396,8 @@
* classes to find virtual overrides.
*/
private void computeVirtualUpRefs(JClassType type, JInterfaceType intf) {
- outer : for (Iterator itIntf = intf.methods.iterator(); itIntf.hasNext();) {
- JMethod intfMethod = (JMethod) itIntf.next();
- for (Iterator itType = type.methods.iterator(); itType.hasNext();) {
- JMethod classMethod = (JMethod) itType.next();
+ outer : for (JMethod intfMethod : intf.methods) {
+ for (JMethod classMethod : type.methods) {
if (JProgram.methodsDoMatch(intfMethod, classMethod)) {
// this class directly implements the interface method
continue outer;
@@ -424,8 +407,7 @@
// this class does not directly implement the interface method
// if any super classes do, create a virtual up ref
for (JClassType superType = type.extnds; superType != javaLangObject; superType = superType.extnds) {
- for (Iterator itSuper = superType.methods.iterator(); itSuper.hasNext();) {
- JMethod superMethod = (JMethod) itSuper.next();
+ for (JMethod superMethod : superType.methods) {
if (JProgram.methodsDoMatch(intfMethod, superMethod)) {
// this super class directly implements the interface method
// create a virtual up ref
@@ -434,9 +416,9 @@
// + "." + superMethod.getName() + " to " + intf.getName() + "."
// + intfMethod.getName() + " via " + type.getName());
- Map/* <JClassType, Set<JMethod>> */classToMethodMap = getOrCreateMap(
+ Map<JClassType, Set<JMethod>> classToMethodMap = getOrCreateMap(
virtualUpRefMap, superMethod);
- Set/* <JMethod> */methodSet = getOrCreate(classToMethodMap, type);
+ Set<JMethod> methodSet = getOrCreate(classToMethodMap, type);
methodSet.add(intfMethod);
// do not search additional super types
@@ -447,21 +429,19 @@
}
}
- private/* <K, V> */Set/* <V> */getOrCreate(Map/* <K, Set<V>> */map,
- Object key) {
- Set/* <V> */set = (Set) map.get(key);
+ private <K, V> Set<V> getOrCreate(Map<K, Set<V>> map, K key) {
+ Set<V> set = map.get(key);
if (set == null) {
- set = new HashSet/* <V> */();
+ set = new HashSet<V>();
map.put(key, set);
}
return set;
}
- private/* <K, K2, V> */Map/* <K2, V> */getOrCreateMap(
- Map/* <K, Map<K2, V>> */map, Object key) {
- Map/* <K2, V> */map2 = (Map) map.get(key);
+ private <K, K2, V> Map<K2, V> getOrCreateMap(Map<K, Map<K2, V>> map, K key) {
+ Map<K2, V> map2 = map.get(key);
if (map2 == null) {
- map2 = new HashMap/* <K2, V> */();
+ map2 = new HashMap<K2, V>();
map.put(key, map2);
}
return map2;
@@ -471,7 +451,7 @@
* Record the all of my super classes (and myself as a subclass of them).
*/
private void recordSuperSubInfo(JClassType type) {
- Set/* <JClassType> */superSet = getOrCreate(superClassMap, type);
+ Set<JClassType> superSet = getOrCreate(superClassMap, type);
for (JClassType t = type.extnds; t != null; t = t.extnds) {
superSet.add(t);
add(subClassMap, t, type);
@@ -483,7 +463,7 @@
* them).
*/
private void recordSuperSubInfo(JInterfaceType type) {
- Set/* <JInterfaceType> */superSet = getOrCreate(superInterfaceMap, type);
+ Set<JInterfaceType> superSet = getOrCreate(superInterfaceMap, type);
recordSuperSubInfo(type, superSet, type);
}
@@ -491,9 +471,8 @@
* Recursively record all of my super interfaces.
*/
private void recordSuperSubInfo(JInterfaceType base,
- Set/* <JInterfaceType> */superSet, JInterfaceType cur) {
- for (Iterator it = cur.implments.iterator(); it.hasNext();) {
- JInterfaceType intf = (JInterfaceType) it.next();
+ Set<JInterfaceType> superSet, JInterfaceType cur) {
+ for (JInterfaceType intf : cur.implments) {
superSet.add(intf);
add(subInterfaceMap, intf, base);
recordSuperSubInfo(base, superSet, intf);