01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.walker;
06:
07: import com.tc.object.bytecode.ByteCodeUtil;
08:
09: import java.lang.reflect.Field;
10: import java.lang.reflect.Modifier;
11: import java.util.Collections;
12: import java.util.HashMap;
13: import java.util.Iterator;
14: import java.util.Map;
15: import java.util.Set;
16: import java.util.TreeSet;
17:
18: class AllFields {
19: private static final Class OBJECT = Object.class;
20:
21: private final Set fields = new TreeSet();
22:
23: Iterator getFields() {
24: return Collections.unmodifiableSet(fields).iterator();
25: }
26:
27: static AllFields getAllFields(Object o, boolean ignoreTC) {
28: return getAllFields(o, ignoreTC, null);
29: }
30:
31: static AllFields getAllFields(Object o, boolean ignoreTC,
32: WalkTest walkTest) {
33: // XXX: cache?
34:
35: AllFields allFields = new AllFields();
36:
37: Map fieldNames = new HashMap();
38:
39: Class c = o.getClass();
40: while (c != OBJECT
41: && (walkTest == null || walkTest
42: .includeFieldsForType(c))) {
43: Field[] fields = c.getDeclaredFields();
44: for (int i = 0; i < fields.length; i++) {
45: Field f = fields[i];
46:
47: if (Modifier.isStatic(f.getModifiers())) {
48: continue;
49: }
50:
51: if (ignoreTC
52: && f.getName().startsWith(
53: ByteCodeUtil.TC_FIELD_PREFIX)) {
54: continue;
55: }
56:
57: FieldData key = new FieldData(f);
58:
59: FieldData prev = (FieldData) fieldNames.put(
60: f.getName(), key);
61: if (prev != null) {
62: key.setShadowed(true);
63: prev.setShadowed(true);
64: }
65:
66: allFields.fields.add(key);
67: }
68:
69: c = c.getSuperclass();
70: }
71:
72: return allFields;
73:
74: }
75:
76: }
|