From e200b6cdcc5915163ff0d2053ed5367a6bc86d66 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Fri, 23 Jun 2017 10:30:28 -0700 Subject: [PATCH] [infer][java] Simplify some of the models Reviewed By: jvillard Differential Revision: D5267207 fbshipit-source-id: 7a7c3fc --- .../java/src/java/util/AbstractList.java | 2 +- .../models/java/src/java/util/ArrayList.java | 4 +--- infer/models/java/src/java/util/HashMap.java | 19 ++++++++----------- infer/models/java/src/java/util/List.java | 4 +--- infer/models/java/src/java/util/Scanner.java | 2 +- infer/models/java/src/java/util/Vector.java | 4 ++-- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/infer/models/java/src/java/util/AbstractList.java b/infer/models/java/src/java/util/AbstractList.java index 52ef020bb..d79763dbe 100644 --- a/infer/models/java/src/java/util/AbstractList.java +++ b/infer/models/java/src/java/util/AbstractList.java @@ -12,7 +12,7 @@ package java.util; import com.facebook.infer.builtins.InferUndefined; // could make List an abstract class directly instead, but that breaks other models -public abstract class AbstractList extends AbstractCollection { +public abstract class AbstractList { // 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 diff --git a/infer/models/java/src/java/util/ArrayList.java b/infer/models/java/src/java/util/ArrayList.java index 8d992ce43..88aab7598 100644 --- a/infer/models/java/src/java/util/ArrayList.java +++ b/infer/models/java/src/java/util/ArrayList.java @@ -12,9 +12,7 @@ package java.util; import java.io.Serializable; // abstract so we don't have to implement every method of List -public abstract class ArrayList - extends AbstractList - implements RandomAccess, Cloneable, Serializable { +public abstract class ArrayList extends AbstractList { @Override public boolean isEmpty() { diff --git a/infer/models/java/src/java/util/HashMap.java b/infer/models/java/src/java/util/HashMap.java index 88e049393..9ae4d1b6c 100644 --- a/infer/models/java/src/java/util/HashMap.java +++ b/infer/models/java/src/java/util/HashMap.java @@ -24,16 +24,14 @@ import com.facebook.infer.builtins.InferUndefined; * get(key). */ -public abstract class HashMap extends AbstractMap - implements Map, Cloneable, Serializable { +public abstract class HashMap { - private Object lastKey1 = null; - private Object lastKey2 = null; + private K lastKey1 = 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 // key in the map, why would you check if it's still there? - if (InferUndefined.boolean_undefined()) { pushKey(key); return true; @@ -42,7 +40,7 @@ public abstract class HashMap extends AbstractMap } } - public V get(Object key) { + public V get(K key) { if (_containsKey(key)) { return (V)InferUndefined.object_undefined(); } else if (InferUndefined.boolean_undefined()) { @@ -64,17 +62,16 @@ public abstract class HashMap extends AbstractMap /** some sort of circular buffer simulator */ - private void pushKey(Object key) { + private void pushKey(K key) { lastKey2 = lastKey1; lastKey1 = key; } - private boolean _containsKey(Object key) { + private boolean _containsKey(K key) { return areEqual(key, lastKey1) || areEqual(key, lastKey2); } - /* does explicit dynamic dispatch to help Infer out */ - private static boolean areEqual(Object x, Object y) { + private boolean areEqual(K x, K y) { return x == y; } diff --git a/infer/models/java/src/java/util/List.java b/infer/models/java/src/java/util/List.java index c43b9ddad..55c981a5d 100644 --- a/infer/models/java/src/java/util/List.java +++ b/infer/models/java/src/java/util/List.java @@ -12,9 +12,7 @@ package java.util; import java.io.Serializable; // abstract so we don't have to implement every method of List -public abstract class List - extends AbstractList - implements Collection, Iterable { +public abstract class List extends AbstractList { @Override public boolean isEmpty() { diff --git a/infer/models/java/src/java/util/Scanner.java b/infer/models/java/src/java/util/Scanner.java index 72d9ddba8..a102308f4 100644 --- a/infer/models/java/src/java/util/Scanner.java +++ b/infer/models/java/src/java/util/Scanner.java @@ -18,7 +18,7 @@ import java.io.IOException; import java.lang.IllegalArgumentException; -public class Scanner extends Object { +public class Scanner { InputStream src; private void init(InputStream source) { diff --git a/infer/models/java/src/java/util/Vector.java b/infer/models/java/src/java/util/Vector.java index 54eb0482c..122089d2f 100644 --- a/infer/models/java/src/java/util/Vector.java +++ b/infer/models/java/src/java/util/Vector.java @@ -11,9 +11,9 @@ package java.util; import com.facebook.infer.builtins.InferUndefined; -public abstract class Vector extends AbstractList { +public abstract class Vector { - protected Object[] elementData; + protected E[] elementData; E elementData(int index) { return (E) elementData[index];