1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.*;
// See issue 241: https://github.com/typetools/checker-framework/issues/241
// Cover all 8 combinations of:
// -(Non)static class
// -(Non)static field
// -(Non)static method
// Also test:
// -(Non)static field initialization
public class JavaExprContext {
// Classes to perform tests on
// The methods return booleans instead of void simply so they can
// be tested as field initializers.
public static class staticGraphClass {
private Map<String, Integer> adjList = new HashMap<>();
public boolean addEdge(@KeyFor("adjList") String source) {
return true;
}
public static boolean addEdge2(
@KeyFor("#2.adjList") String source, staticGraphClass theGraph) {
return true;
}
public boolean addEdge3(@KeyFor("this.adjList") String source) {
return true;
}
}
public class nonstaticGraphClass {
private Map<String, Integer> adjList = new HashMap<>();
public boolean addEdge(@KeyFor("adjList") String source) {
return true;
}
public boolean addEdge2(@KeyFor("this.adjList") String source) {
return true;
}
}
// Non-static field initialization
staticGraphClass graphField1 = new staticGraphClass();
nonstaticGraphClass graphField2 = new nonstaticGraphClass();
@SuppressWarnings("assignment.type.incompatible")
@KeyFor("graphField1.adjList") String key1 = "";
@SuppressWarnings("assignment.type.incompatible")
@KeyFor("graphField2.adjList") String key2 = "";
boolean b1 = staticGraphClass.addEdge2(key1, graphField1);
boolean b2 = graphField1.addEdge(key1);
boolean b3 = graphField1.addEdge2(key1, graphField1);
boolean b4 = graphField1.addEdge3(key1);
boolean b5 = graphField2.addEdge(key2);
boolean b6 = graphField2.addEdge2(key2);
// Classes that perform tests
public class nonstaticTestClass {
staticGraphClass graphField1 = new staticGraphClass();
nonstaticGraphClass graphField2 = new nonstaticGraphClass();
public void buildGraph1(@KeyFor("graphField1.adjList") String hero) {
staticGraphClass.addEdge2(hero, graphField1);
graphField1.addEdge(hero);
graphField1.addEdge2(
hero,
graphField1); // Calling a static method from an instance object. Ensuring this
// doesn't confuse the FlowExpression parsing.
graphField1.addEdge3(hero);
}
public void buildGraph2(@KeyFor("graphField2.adjList") String hero) {
graphField2.addEdge(hero);
graphField2.addEdge2(hero);
}
public void buildGraph3(staticGraphClass myGraph, @KeyFor("#1.adjList") String hero) {
staticGraphClass.addEdge2(hero, myGraph);
myGraph.addEdge(hero);
myGraph.addEdge2(
hero,
myGraph); // Calling a static method from an instance object. Ensuring this
// doesn't confuse the FlowExpression parsing.
myGraph.addEdge3(hero);
}
public void buildGraph4(nonstaticGraphClass myGraph, @KeyFor("#1.adjList") String hero) {
myGraph.addEdge(hero);
myGraph.addEdge2(hero);
}
}
public static class staticTestClass {
staticGraphClass graphField1 = new staticGraphClass();
static staticGraphClass graphField2 = new staticGraphClass();
public void buildGraph1(@KeyFor("graphField1.adjList") String hero) {
staticGraphClass.addEdge2(hero, graphField1);
graphField1.addEdge(hero);
graphField1.addEdge2(
hero,
graphField1); // Calling a static method from an instance object. Ensuring this
// doesn't confuse the FlowExpression parsing.
graphField1.addEdge3(hero);
}
public void buildGraph3(@KeyFor("graphField2.adjList") String hero) {
staticGraphClass.addEdge2(hero, graphField2);
graphField2.addEdge(hero);
graphField2.addEdge2(
hero,
graphField2); // Calling a static method from an instance object. Ensuring this
// doesn't confuse the FlowExpression parsing.
graphField2.addEdge3(hero);
}
public void buildGraph5(staticGraphClass myGraph, @KeyFor("#1.adjList") String hero) {
staticGraphClass.addEdge2(hero, myGraph);
myGraph.addEdge(hero);
myGraph.addEdge2(
hero,
myGraph); // Calling a static method from an instance object. Ensuring this
// doesn't confuse the FlowExpression parsing.
myGraph.addEdge3(hero);
}
public void buildGraph6(nonstaticGraphClass myGraph, @KeyFor("#1.adjList") String hero) {
myGraph.addEdge(hero);
myGraph.addEdge2(hero);
}
public static void buildGraph7(@KeyFor("graphField2.adjList") String hero) {
staticGraphClass.addEdge2(hero, graphField2);
graphField2.addEdge(hero);
graphField2.addEdge2(
hero,
graphField2); // Calling a static method from an instance object. Ensuring this
// doesn't confuse the FlowExpression parsing.
graphField2.addEdge3(hero);
}
public static void buildGraph9(
staticGraphClass myGraph, @KeyFor("#1.adjList") String hero) {
staticGraphClass.addEdge2(hero, myGraph);
myGraph.addEdge(hero);
myGraph.addEdge2(
hero,
myGraph); // Calling a static method from an instance object. Ensuring this
// doesn't confuse the FlowExpression parsing.
myGraph.addEdge3(hero);
}
public static void buildGraph10(
nonstaticGraphClass myGraph, @KeyFor("#1.adjList") String hero) {
myGraph.addEdge(hero);
myGraph.addEdge2(hero);
}
}
}
|