Initial commit
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
package com.thoughtworks.xstream.converters.reflection;
|
||||
|
||||
import com.thoughtworks.xstream.core.Caching;
|
||||
import com.thoughtworks.xstream.core.JVM;
|
||||
import com.thoughtworks.xstream.core.util.OrderRetainingMap;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class FieldDictionary implements Caching {
|
||||
private static final DictionaryEntry OBJECT_DICTIONARY_ENTRY;
|
||||
static /* synthetic */ Class class$java$lang$Object;
|
||||
private transient Map dictionaryEntries;
|
||||
private transient FieldUtil fieldUtil;
|
||||
private final FieldKeySorter sorter;
|
||||
|
||||
private static final class DictionaryEntry {
|
||||
private final Map keyedByFieldKey;
|
||||
private final Map keyedByFieldName;
|
||||
|
||||
public DictionaryEntry(Map map, Map map2) {
|
||||
this.keyedByFieldName = map;
|
||||
this.keyedByFieldKey = map2;
|
||||
}
|
||||
|
||||
public Map getKeyedByFieldKey() {
|
||||
return this.keyedByFieldKey;
|
||||
}
|
||||
|
||||
public Map getKeyedByFieldName() {
|
||||
return this.keyedByFieldName;
|
||||
}
|
||||
}
|
||||
|
||||
interface FieldUtil {
|
||||
boolean isSynthetic(Field field);
|
||||
}
|
||||
|
||||
static {
|
||||
Map map = Collections.EMPTY_MAP;
|
||||
OBJECT_DICTIONARY_ENTRY = new DictionaryEntry(map, map);
|
||||
}
|
||||
|
||||
public FieldDictionary() {
|
||||
this(new ImmutableFieldKeySorter());
|
||||
}
|
||||
|
||||
private DictionaryEntry buildDictionaryEntryForClass(Class cls, DictionaryEntry dictionaryEntry) {
|
||||
HashMap hashMap = new HashMap(dictionaryEntry.getKeyedByFieldName());
|
||||
OrderRetainingMap orderRetainingMap = new OrderRetainingMap(dictionaryEntry.getKeyedByFieldKey());
|
||||
Field[] declaredFields = cls.getDeclaredFields();
|
||||
if (JVM.reverseFieldDefinition()) {
|
||||
int length = declaredFields.length >> 1;
|
||||
while (true) {
|
||||
int i = length - 1;
|
||||
if (length <= 0) {
|
||||
break;
|
||||
}
|
||||
int length2 = (declaredFields.length - i) - 1;
|
||||
Field field = declaredFields[i];
|
||||
declaredFields[i] = declaredFields[length2];
|
||||
declaredFields[length2] = field;
|
||||
length = i;
|
||||
}
|
||||
}
|
||||
for (int i2 = 0; i2 < declaredFields.length; i2++) {
|
||||
Field field2 = declaredFields[i2];
|
||||
if (!this.fieldUtil.isSynthetic(field2) || !field2.getName().startsWith("$jacoco")) {
|
||||
if (!field2.isAccessible()) {
|
||||
field2.setAccessible(true);
|
||||
}
|
||||
FieldKey fieldKey = new FieldKey(field2.getName(), field2.getDeclaringClass(), i2);
|
||||
Field field3 = (Field) hashMap.get(field2.getName());
|
||||
if (field3 == null || (field3.getModifiers() & 8) != 0 || (field3 != null && (field2.getModifiers() & 8) == 0)) {
|
||||
hashMap.put(field2.getName(), field2);
|
||||
}
|
||||
orderRetainingMap.put(fieldKey, field2);
|
||||
}
|
||||
}
|
||||
return new DictionaryEntry(hashMap, this.sorter.sort(cls, orderRetainingMap));
|
||||
}
|
||||
|
||||
private Map buildMap(Class cls, boolean z) {
|
||||
LinkedList linkedList = new LinkedList();
|
||||
DictionaryEntry dictionaryEntry = null;
|
||||
while (dictionaryEntry == null) {
|
||||
Class cls2 = class$java$lang$Object;
|
||||
if (cls2 == null) {
|
||||
cls2 = class$("java.lang.Object");
|
||||
class$java$lang$Object = cls2;
|
||||
}
|
||||
dictionaryEntry = (cls2.equals(cls) || cls == null) ? OBJECT_DICTIONARY_ENTRY : getDictionaryEntry(cls);
|
||||
if (dictionaryEntry == null) {
|
||||
linkedList.addFirst(cls);
|
||||
cls = cls.getSuperclass();
|
||||
}
|
||||
}
|
||||
Iterator it = linkedList.iterator();
|
||||
while (it.hasNext()) {
|
||||
Class cls3 = (Class) it.next();
|
||||
dictionaryEntry = buildDictionaryEntryForClass(cls3, dictionaryEntry);
|
||||
synchronized (this) {
|
||||
DictionaryEntry dictionaryEntry2 = getDictionaryEntry(cls3);
|
||||
if (dictionaryEntry2 == null) {
|
||||
this.dictionaryEntries.put(cls3, dictionaryEntry);
|
||||
} else {
|
||||
dictionaryEntry = dictionaryEntry2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return z ? dictionaryEntry.getKeyedByFieldKey() : dictionaryEntry.getKeyedByFieldName();
|
||||
}
|
||||
|
||||
static /* synthetic */ Class class$(String str) {
|
||||
try {
|
||||
return Class.forName(str);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new NoClassDefFoundError().initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized DictionaryEntry getDictionaryEntry(Class cls) {
|
||||
return (DictionaryEntry) this.dictionaryEntries.get(cls);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
this.dictionaryEntries = new HashMap();
|
||||
if (JVM.is15()) {
|
||||
try {
|
||||
this.fieldUtil = (FieldUtil) JVM.loadClassForName("com.thoughtworks.xstream.converters.reflection.FieldUtil15", true).newInstance();
|
||||
} catch (Exception unused) {
|
||||
}
|
||||
}
|
||||
if (this.fieldUtil == null) {
|
||||
this.fieldUtil = new FieldUtil14();
|
||||
}
|
||||
}
|
||||
|
||||
public Field field(Class cls, String str, Class cls2) {
|
||||
Field fieldOrNull = fieldOrNull(cls, str, cls2);
|
||||
if (fieldOrNull != null) {
|
||||
return fieldOrNull;
|
||||
}
|
||||
throw new MissingFieldException(cls.getName(), str);
|
||||
}
|
||||
|
||||
/* JADX WARN: Multi-variable type inference failed */
|
||||
/* JADX WARN: Type inference failed for: r0v2, types: [com.thoughtworks.xstream.converters.reflection.FieldKey] */
|
||||
public Field fieldOrNull(Class cls, String str, Class cls2) {
|
||||
Map buildMap = buildMap(cls, cls2 != null);
|
||||
if (cls2 != null) {
|
||||
str = new FieldKey(str, cls2, -1);
|
||||
}
|
||||
return (Field) buildMap.get(str);
|
||||
}
|
||||
|
||||
public Iterator fieldsFor(Class cls) {
|
||||
return buildMap(cls, true).values().iterator();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.core.Caching
|
||||
public synchronized void flushCache() {
|
||||
this.dictionaryEntries.clear();
|
||||
if (this.sorter instanceof Caching) {
|
||||
((Caching) this.sorter).flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
protected Object readResolve() {
|
||||
init();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Iterator serializableFieldsFor(Class cls) {
|
||||
return fieldsFor(cls);
|
||||
}
|
||||
|
||||
public FieldDictionary(FieldKeySorter fieldKeySorter) {
|
||||
this.sorter = fieldKeySorter;
|
||||
init();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user