[infer][java] Simplify some of the models

Reviewed By: jvillard

Differential Revision: D5267207

fbshipit-source-id: 7a7c3fc
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent 7d680b3b0c
commit e200b6cdcc

@ -12,7 +12,7 @@ package java.util;
import com.facebook.infer.builtins.InferUndefined; import com.facebook.infer.builtins.InferUndefined;
// could make List an abstract class directly instead, but that breaks other models // could make List an abstract class directly instead, but that breaks other models
public abstract class AbstractList<T> extends AbstractCollection<T> { public abstract class AbstractList<T> {
// need three-value state for unknown (-1), false (0), or true (1) // need three-value state for unknown (-1), false (0), or true (1)
// the reason we can't use a bool is that we want to return either true or false each time we call // the reason we can't use a bool is that we want to return either true or false each time we call

@ -12,9 +12,7 @@ package java.util;
import java.io.Serializable; import java.io.Serializable;
// abstract so we don't have to implement every method of List // abstract so we don't have to implement every method of List
public abstract class ArrayList<T> public abstract class ArrayList<T> extends AbstractList<T> {
extends AbstractList<T>
implements RandomAccess, Cloneable, Serializable {
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {

@ -24,16 +24,14 @@ import com.facebook.infer.builtins.InferUndefined;
* get(key). * get(key).
*/ */
public abstract class HashMap<K,V> extends AbstractMap<K,V> public abstract class HashMap<K,V> {
implements Map<K,V>, Cloneable, Serializable {
private Object lastKey1 = null; private K lastKey1 = null;
private Object lastKey2 = null; private K lastKey2 = null;
public boolean containsKey(Object key) { public boolean containsKey(K key) {
// doesn't actually check if _containsKey(key). If you just put a // doesn't actually check if _containsKey(key). If you just put a
// key in the map, why would you check if it's still there? // key in the map, why would you check if it's still there?
if (InferUndefined.boolean_undefined()) { if (InferUndefined.boolean_undefined()) {
pushKey(key); pushKey(key);
return true; return true;
@ -42,7 +40,7 @@ public abstract class HashMap<K,V> extends AbstractMap<K,V>
} }
} }
public V get(Object key) { public V get(K key) {
if (_containsKey(key)) { if (_containsKey(key)) {
return (V)InferUndefined.object_undefined(); return (V)InferUndefined.object_undefined();
} else if (InferUndefined.boolean_undefined()) { } else if (InferUndefined.boolean_undefined()) {
@ -64,17 +62,16 @@ public abstract class HashMap<K,V> extends AbstractMap<K,V>
/** some sort of circular buffer simulator */ /** some sort of circular buffer simulator */
private void pushKey(Object key) { private void pushKey(K key) {
lastKey2 = lastKey1; lastKey2 = lastKey1;
lastKey1 = key; lastKey1 = key;
} }
private boolean _containsKey(Object key) { private boolean _containsKey(K key) {
return areEqual(key, lastKey1) || areEqual(key, lastKey2); return areEqual(key, lastKey1) || areEqual(key, lastKey2);
} }
/* does explicit dynamic dispatch to help Infer out */ private boolean areEqual(K x, K y) {
private static boolean areEqual(Object x, Object y) {
return x == y; return x == y;
} }

@ -12,9 +12,7 @@ package java.util;
import java.io.Serializable; import java.io.Serializable;
// abstract so we don't have to implement every method of List // abstract so we don't have to implement every method of List
public abstract class List<T> public abstract class List<T> extends AbstractList<T> {
extends AbstractList<T>
implements Collection<T>, Iterable<T> {
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {

@ -18,7 +18,7 @@ import java.io.IOException;
import java.lang.IllegalArgumentException; import java.lang.IllegalArgumentException;
public class Scanner extends Object { public class Scanner {
InputStream src; InputStream src;
private void init(InputStream source) { private void init(InputStream source) {

@ -11,9 +11,9 @@ package java.util;
import com.facebook.infer.builtins.InferUndefined; import com.facebook.infer.builtins.InferUndefined;
public abstract class Vector<E> extends AbstractList<E> { public abstract class Vector<E> {
protected Object[] elementData; protected E[] elementData;
E elementData(int index) { E elementData(int index) {
return (E) elementData[index]; return (E) elementData[index];

Loading…
Cancel
Save