Comments resolved
diff --git a/robolectric-shadows/shadows-core/src/main/java/org/robolectric/shadows/ShadowAccessibilityEvent.java b/robolectric-shadows/shadows-core/src/main/java/org/robolectric/shadows/ShadowAccessibilityEvent.java
index edc1032..db94550 100644
--- a/robolectric-shadows/shadows-core/src/main/java/org/robolectric/shadows/ShadowAccessibilityEvent.java
+++ b/robolectric-shadows/shadows-core/src/main/java/org/robolectric/shadows/ShadowAccessibilityEvent.java
@@ -24,7 +24,7 @@
private static final Map<StrictEqualityEventWrapper, StackTraceElement[]> obtainedInstances =
new HashMap<>();
- private static final SparseArray<StrictEqualityEventWrapper> orderedInstance = new SparseArray<>();
+ private static final SparseArray<StrictEqualityEventWrapper> orderedInstances = new SparseArray<>();
private static int sAllocationCount = 0;
private int eventType;
@@ -36,12 +36,16 @@
@RealObject
private AccessibilityEvent realAccessibilityEvent;
+ public void __constructor__() {
+ ReflectionHelpers.setStaticField(AccessibilityEvent.class, "CREATOR", ShadowAccessibilityEvent.CREATOR);
+ }
+
public static final Parcelable.Creator<AccessibilityEvent> CREATOR =
new Parcelable.Creator<AccessibilityEvent>() {
@Override
public AccessibilityEvent createFromParcel(Parcel source) {
- return obtain(orderedInstance.get(source.readInt()).mEvent);
+ return obtain(orderedInstances.valueAt(source.readInt()).mEvent);
}
@Override
@@ -58,8 +62,7 @@
sAllocationCount++;
StrictEqualityEventWrapper wrapper = new StrictEqualityEventWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
- orderedInstance.put(sAllocationCount, wrapper);
- ReflectionHelpers.setStaticField(AccessibilityEvent.class, "CREATOR", ShadowAccessibilityEvent.CREATOR);
+ orderedInstances.put(sAllocationCount, wrapper);
return obtainedInstance;
}
@@ -76,9 +79,8 @@
sAllocationCount++;
StrictEqualityEventWrapper wrapper = new StrictEqualityEventWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
- orderedInstance.put(sAllocationCount, wrapper);
+ orderedInstances.put(sAllocationCount, wrapper);
shadowObtained.eventType = eventType;
- ReflectionHelpers.setStaticField(AccessibilityEvent.class, "CREATOR", ShadowAccessibilityEvent.CREATOR);
return obtainedInstance;
}
@@ -117,7 +119,8 @@
*/
public static void resetObtainedInstances() {
obtainedInstances.clear();
- orderedInstance.clear();
+ orderedInstances.clear();
+ sAllocationCount = 0;
}
@Implementation
@@ -130,14 +133,15 @@
obtainedInstances.remove(wrapper);
int keyOfWrapper = -1;
- for (int i = 0; i < orderedInstance.size(); i++) {
- int key = orderedInstance.keyAt(i);
- if (orderedInstance.get(key).equals(wrapper)) {
+ for (int i = 0; i < orderedInstances.size(); i++) {
+ int key = orderedInstances.keyAt(i);
+ if (orderedInstances.get(key).equals(wrapper)) {
keyOfWrapper = key;
break;
}
}
- orderedInstance.remove(keyOfWrapper);
+ orderedInstances.remove(keyOfWrapper);
+ sAllocationCount--;
}
@Implementation
@@ -272,14 +276,13 @@
@Implementation
public void writeToParcel(Parcel dest, int flags) {
StrictEqualityEventWrapper wrapper = new StrictEqualityEventWrapper(realAccessibilityEvent);
- int keyofWrapper = -1;
- for (int i = 0; i < orderedInstance.size(); i++) {
- int key = orderedInstance.keyAt(i);
- if (orderedInstance.get(key).equals(wrapper)) {
- keyofWrapper = key;
- break;
+ int indexOfWrapper = -1;
+ for (int i = 0; i < orderedInstances.size(); i++) {
+ if (orderedInstances.valueAt(i).equals(wrapper)) {
+ indexOfWrapper = i;
+ break;
}
}
- dest.writeInt(keyofWrapper);
+ dest.writeInt(indexOfWrapper);
}
}
diff --git a/robolectric-shadows/shadows-core/src/main/resources/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java.vm b/robolectric-shadows/shadows-core/src/main/resources/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java.vm
index cf4ebd4..c32e1e2 100644
--- a/robolectric-shadows/shadows-core/src/main/resources/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java.vm
+++ b/robolectric-shadows/shadows-core/src/main/resources/org/robolectric/shadows/ShadowAccessibilityNodeInfo.java.vm
@@ -35,7 +35,7 @@
private static final Map<StrictEqualityNodeWrapper, StackTraceElement[]> obtainedInstances =
new HashMap<>();
- private static final SparseArray<StrictEqualityNodeWrapper> orderedInstance = new SparseArray<>();
+ private static final SparseArray<StrictEqualityNodeWrapper> orderedInstances = new SparseArray<>();
// Bitmasks for actions
public static final int UNDEFINED_SELECTION_INDEX = -1;
@@ -45,7 +45,7 @@
@Override
public AccessibilityNodeInfo createFromParcel(Parcel source) {
- return obtain(orderedInstance.get(source.readInt()).mInfo);
+ return obtain(orderedInstances.valueAt(source.readInt()).mInfo);
}
@Override
@@ -103,6 +103,10 @@
@RealObject
private AccessibilityNodeInfo realAccessibilityNodeInfo;
+ public void __constructor__() {
+ ReflectionHelpers.setStaticField(AccessibilityNodeInfo.class, "CREATOR", ShadowAccessibilityNodeInfo.CREATOR);
+ }
+
@Implementation
public static AccessibilityNodeInfo obtain(AccessibilityNodeInfo info) {
final ShadowAccessibilityNodeInfo shadowInfo =
@@ -112,9 +116,7 @@
sAllocationCount++;
StrictEqualityNodeWrapper wrapper = new StrictEqualityNodeWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
- orderedInstance.put(sAllocationCount, wrapper);
- ReflectionHelpers.setStaticField(
- AccessibilityNodeInfo.class, "CREATOR", ShadowAccessibilityNodeInfo.CREATOR);
+ orderedInstances.put(sAllocationCount, wrapper);
return obtainedInstance;
}
@@ -143,9 +145,7 @@
sAllocationCount++;
StrictEqualityNodeWrapper wrapper = new StrictEqualityNodeWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
- orderedInstance.put(sAllocationCount, wrapper);
- ReflectionHelpers.setStaticField(
- AccessibilityNodeInfo.class, "CREATOR", ShadowAccessibilityNodeInfo.CREATOR);
+ orderedInstances.put(sAllocationCount, wrapper);
return obtainedInstance;
}
@@ -186,7 +186,8 @@
*/
public static void resetObtainedInstances() {
obtainedInstances.clear();
- orderedInstance.clear();
+ orderedInstances.clear();
+ sAllocationCount = 0;
}
@Implementation
@@ -207,14 +208,15 @@
obtainedInstances.remove(wrapper);
int keyOfWrapper = -1;
- for (int i = 0; i < orderedInstance.size(); i++) {
- int key = orderedInstance.keyAt(i);
- if (orderedInstance.get(key).equals(wrapper)) {
+ for (int i = 0; i < orderedInstances.size(); i++) {
+ int key = orderedInstances.keyAt(i);
+ if (orderedInstances.get(key).equals(wrapper)) {
keyOfWrapper = key;
break;
}
}
- orderedInstance.remove(keyOfWrapper);
+ orderedInstances.remove(keyOfWrapper);
+ sAllocationCount--;
}
@Implementation
@@ -716,14 +718,13 @@
@Implementation
public void writeToParcel(Parcel dest, int flags) {
StrictEqualityNodeWrapper wrapper = new StrictEqualityNodeWrapper(realAccessibilityNodeInfo);
- int keyofWrapper = -1;
- for (int i = 0; i < orderedInstance.size(); i++) {
- int key = orderedInstance.keyAt(i);
- if (orderedInstance.get(key).equals(wrapper)) {
- keyofWrapper = key;
- break;
+ int indexOfWrapper = -1;
+ for (int i = 0; i < orderedInstances.size(); i++) {
+ if (orderedInstances.valueAt(i).equals(wrapper)) {
+ indexOfWrapper = i;
+ break;
}
}
- dest.writeInt(keyofWrapper);
+ dest.writeInt(indexOfWrapper);
}
}
\ No newline at end of file