comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.d @ 88:9e0ab372d5d8

Revert from TypeInfo/ClassInfo to java.lang.Class
author Frank Benoit <benoit@tionex.de>
date Sun, 19 Apr 2009 11:10:09 +0200
parents 6be48cf9f95c
children
comparison
equal deleted inserted replaced
87:8594250b1d1c 88:9e0ab372d5d8
10 ******************************************************************************/ 10 ******************************************************************************/
11 11
12 module org.eclipse.core.internal.databinding.ClassLookupSupport; 12 module org.eclipse.core.internal.databinding.ClassLookupSupport;
13 13
14 import java.lang.all; 14 import java.lang.all;
15 import java.nonstandard.RuntimeTraits;
16 15
17 import java.util.ArrayList; 16 import java.util.ArrayList;
18 import java.util.Collection; 17 import java.util.Collection;
19 import java.util.HashMap; 18 import java.util.HashMap;
20 import java.util.HashSet; 19 import java.util.HashSet;
36 /** 35 /**
37 * For a given class or interface, return an array containing the given type and all its direct and indirect supertypes. 36 * For a given class or interface, return an array containing the given type and all its direct and indirect supertypes.
38 * @param type 37 * @param type
39 * @return an array containing the given type and all its direct and indirect supertypes 38 * @return an array containing the given type and all its direct and indirect supertypes
40 */ 39 */
41 public static TypeInfo[] getTypeHierarchyFlattened(TypeInfo type) { 40 public static Class[] getTypeHierarchyFlattened(Class type) {
42 List classes = null; 41 List classes = null;
43 //cache reference to lookup to protect against concurrent flush 42 //cache reference to lookup to protect against concurrent flush
44 HashMap lookup = classSearchOrderLookup; 43 HashMap lookup = classSearchOrderLookup;
45 if (lookup !is null) 44 if (lookup !is null)
46 classes = cast(List) lookup.get(type); 45 classes = cast(List) lookup.get(type);
50 computeClassOrder(type, classes); 49 computeClassOrder(type, classes);
51 if (lookup is null) 50 if (lookup is null)
52 classSearchOrderLookup = lookup = new HashMap(); 51 classSearchOrderLookup = lookup = new HashMap();
53 lookup.put(type, cast(Object)classes); 52 lookup.put(type, cast(Object)classes);
54 } 53 }
55 return cast(TypeInfo[]) classes.toArray(new TypeInfo[classes.size()]); 54 return cast(Class[]) classes.toArray(new Class[classes.size()]);
56 } 55 }
57 56
58 /** 57 /**
59 * Builds and returns a table of adapters for the given adaptable type. 58 * Builds and returns a table of adapters for the given adaptable type.
60 * The table is keyed by adapter class name. The 59 * The table is keyed by adapter class name. The
63 * first found in the search order is considered. 62 * first found in the search order is considered.
64 * 63 *
65 * Note that it is important to maintain a consistent class and interface 64 * Note that it is important to maintain a consistent class and interface
66 * lookup order. See the class comment for more details. 65 * lookup order. See the class comment for more details.
67 */ 66 */
68 private static void computeClassOrder(TypeInfo adaptable, Collection classes) { 67 private static void computeClassOrder(Class adaptable, Collection classes) {
69 TypeInfo clazz = adaptable; 68 Class clazz = adaptable;
70 Set seen = new HashSet(4); 69 Set seen = new HashSet(4);
71 while (clazz !is null) { 70 while (clazz !is null) {
72 classes.add(clazz); 71 classes.add(clazz);
73 computeInterfaceOrder(getInterfaces(clazz), classes, seen); 72 computeInterfaceOrder(clazz.getInterfaces(), classes, seen);
74 clazz = isInterface(clazz) ? typeid(Object) : getSuperclass(clazz); 73 clazz = clazz.isInterface() ? Class.fromType!(Object) : clazz.getSuperclass();
75 } 74 }
76 } 75 }
77 76
78 private static void computeInterfaceOrder(TypeInfo[] interfaces, Collection classes, Set seen) { 77 private static void computeInterfaceOrder(Class[] interfaces, Collection classes, Set seen) {
79 List newInterfaces = new ArrayList(interfaces.length); 78 List newInterfaces = new ArrayList(interfaces.length);
80 for (int i = 0; i < interfaces.length; i++) { 79 for (int i = 0; i < interfaces.length; i++) {
81 TypeInfo interfac = interfaces[i]; 80 Class interfac = interfaces[i];
82 if (seen.add(interfac)) { 81 if (seen.add(interfac)) {
83 //note we cannot recurse here without changing the resulting interface order 82 //note we cannot recurse here without changing the resulting interface order
84 classes.add(interfac); 83 classes.add(interfac);
85 newInterfaces.add(interfac); 84 newInterfaces.add(interfac);
86 } 85 }
87 } 86 }
88 for (Iterator it = newInterfaces.iterator(); it.hasNext();) 87 for (Iterator it = newInterfaces.iterator(); it.hasNext();)
89 computeInterfaceOrder(getInterfaces(cast(TypeInfo) it.next()), classes, seen); 88 computeInterfaceOrder((cast(Class) it.next()).getInterfaces(), classes, seen);
90 } 89 }
91 90
92 91
93 } 92 }