Skip to content

Commit 10fa912

Browse files
authored
Merge pull request #4631 from antlechner/antonia/json-value-retriever
[TG-7706] Add new JSON value assignment feature for static fields
2 parents 7734b53 + c9546e5 commit 10fa912

File tree

175 files changed

+3513
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+3513
-66
lines changed
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Bar {
2+
private static int c = Util.setTo(10);
3+
private int x;
4+
5+
public Bar(int x) {
6+
this.x = Util.setTo(x);
7+
}
8+
9+
public int get() {
10+
return x + c;
11+
}
12+
}
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public enum Color {
2+
RED(false),
3+
BLUE(false),
4+
GREEN(false),
5+
WHITE(true),
6+
GREY(true),
7+
BLACK(true);
8+
9+
private boolean grayscale;
10+
11+
Color(boolean grayscale) {
12+
this.grayscale = grayscale;
13+
}
14+
15+
public boolean isGrayscale() {
16+
return grayscale;
17+
}
18+
19+
public static Color enumField = Color.WHITE;
20+
public static void testEnumInOwnTypePass() {
21+
assert enumField == Color.WHITE && enumField.name().equals("WHITE") &&
22+
enumField.ordinal() == 3 && enumField.isGrayscale();
23+
}
24+
public static void testEnumInOwnTypeFail() {
25+
assert enumField != Color.WHITE || !enumField.name().equals("WHITE") ||
26+
enumField.ordinal() != 3 || !enumField.isGrayscale();
27+
}
28+
29+
}
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Foo {
2+
private int i;
3+
private Bar b;
4+
5+
public Foo(int i, int x)
6+
{
7+
this.i = Util.setTo(i);
8+
this.b = new Bar(x);
9+
}
10+
11+
public int get() {
12+
return i + b.get();
13+
}
14+
}
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class GenericImplementation<T> implements GenericInterface<T> {
2+
3+
T[] elements;
4+
5+
public GenericImplementation(T[] array) {
6+
elements = array;
7+
}
8+
9+
public int size() {
10+
return elements.length;
11+
}
12+
13+
public T first() {
14+
return elements[0];
15+
}
16+
17+
public int num() {
18+
return 5;
19+
}
20+
}
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class GenericImplementationLess implements GenericInterface<Foo> {
2+
3+
Foo[] elements;
4+
5+
public GenericImplementationLess(Foo[] array) {
6+
elements = array;
7+
}
8+
9+
public int size() {
10+
return elements.length;
11+
}
12+
13+
public Foo first() {
14+
return elements[0];
15+
}
16+
17+
public int num() {
18+
return first().get();
19+
}
20+
21+
}
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class GenericImplementationMore<T, U> implements GenericInterface<T> {
2+
3+
T[] elementsT;
4+
U[] elementsU;
5+
6+
public GenericImplementationMore(T[] arrayT, U[] arrayU) {
7+
elementsT = arrayT;
8+
elementsU = arrayU;
9+
}
10+
11+
public int size() {
12+
return elementsT.length + elementsU.length;
13+
}
14+
15+
public T first() {
16+
return elementsT[0];
17+
}
18+
19+
public int num() {
20+
if (elementsU[0] instanceof Bar) {
21+
return ((Bar) elementsU[0]).get();
22+
}
23+
return elementsU.length;
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class GenericImplementationSimpleMore<T, U> implements GenericInterface<T> {
2+
T t;
3+
U u;
4+
5+
public GenericImplementationSimpleMore(T t, U u) {
6+
this.t = t;
7+
this.u = u;
8+
}
9+
10+
public int size() {
11+
return 2;
12+
}
13+
public T first() {
14+
return t;
15+
}
16+
public int num() {
17+
if (u instanceof Bar) {
18+
return ((Bar) u).get();
19+
}
20+
return 1;
21+
}
22+
}
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public interface GenericInterface<T> {
2+
3+
int size();
4+
5+
T first();
6+
7+
int num();
8+
}
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class GenericMultiDim<K, V> {
2+
3+
public K key;
4+
public V value;
5+
6+
public GenericMultiDim(K k, V v) {
7+
key = k;
8+
value = v;
9+
}
10+
11+
}
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class GenericType<T> {
2+
public T field;
3+
4+
public GenericType(T f) {
5+
field = f;
6+
}
7+
8+
}
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public abstract class MyAbstractClass {
2+
3+
abstract public int num();
4+
5+
public int concreteNum() {
6+
return 11;
7+
}
8+
}
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class MyAbstractImplementationA extends MyAbstractClass {
2+
public int num() {
3+
return concreteNum();
4+
}
5+
}
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class MyAbstractImplementationB extends MyAbstractClass {
2+
public int num() {
3+
return 2 * concreteNum();
4+
}
5+
}
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class MyClassWithInheritedFields extends MyParent {
2+
int childField = Util.setTo(4);
3+
4+
public static int sum(MyClassWithInheritedFields myTemp) {
5+
int sum = myTemp.childField + myTemp.parentField;
6+
if (sum == 10)
7+
return sum;
8+
return sum;
9+
}
10+
}
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class MyConcreteClass {
2+
3+
public static int numField = Util.setTo(10);
4+
5+
public int num() {
6+
return numField;
7+
}
8+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class MyImplementationA implements MyInterface {
2+
int field = Util.setTo(11);
3+
public int num() {
4+
return field;
5+
}
6+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class MyImplementationB implements MyInterface {
2+
int field = Util.setTo(22);
3+
public int num() {
4+
return field;
5+
}
6+
}
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public interface MyInterface {
2+
3+
int num();
4+
5+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class MyInterfaceContainerA {
2+
MyImplementationA field = new MyImplementationA();
3+
public MyInterface getField() {
4+
return field;
5+
}
6+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class MyInterfaceContainerB {
2+
MyInterface field = new MyImplementationB();
3+
public MyInterface getField() {
4+
return field;
5+
}
6+
}
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public class MyParent {
2+
int parentField = Util.setTo(3);
3+
String parentString = "parent";
4+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class MySubclassA extends MyConcreteClass {
2+
@Override
3+
public int num() {
4+
return 2 * super.num();
5+
}
6+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class MySubclassB extends MyConcreteClass {
2+
@Override
3+
public int num() {
4+
return 3 * super.num();
5+
}
6+
}
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public class OtherClass {
2+
3+
public static Foo otherField = new Foo(12, 24);
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This directory contains tests for the --static-values feature: reading initial
2+
values of static fields from a JSON file.
3+
Most of the tests are in StaticValues.java, some more tests are included in
4+
Color.java, and all other classes are used to create instances of various kinds
5+
of objects to use in the tests.
6+
The initial static field values are read from the file clinit-state.json.
7+
The script generate-json.sh (which calls org.cprover.JsonGenerator in the Maven
8+
project) can be used to generate output similar to the contents of
9+
clinit-state.json (with slightly less pretty-printing/newlines, which are not
10+
supported in the custom writers and were manually added to clinit-state.json).
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class StaticParent {
2+
protected static int inheritedStatic = Util.setTo(10);
3+
}
Binary file not shown.

0 commit comments

Comments
 (0)