Skip to content

Commit 7cb8a6c

Browse files
committed
Java: Inline models as data expected output as comments in the java files and add a test.
1 parent 6815bca commit 7cb8a6c

14 files changed

+441
-395
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
unexpectedSummary
2+
expectedSummary
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java
2+
import utils.modelgenerator.internal.CaptureSummaryFlowQuery
3+
import TestUtilities.InlineMadTest
4+
5+
module InlineMadTestConfig implements InlineMadTestConfigSig {
6+
string getComment() { result = any(Javadoc doc).getChild(0).toString() }
7+
8+
string getCapturedSummary() { result = captureFlow(_) }
9+
}
10+
11+
import InlineMadTest<InlineMadTestConfig>

java/ql/test/utils/modelgenerator/dataflow/p/Factory.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22

33
public final class Factory {
44

5-
private String value;
6-
7-
private int intValue;
8-
9-
public static Factory create(String value, int foo) {
10-
return new Factory(value, foo);
11-
}
12-
13-
public static Factory create(String value) {
14-
return new Factory(value, 0);
15-
}
16-
17-
private Factory(String value, int intValue) {
18-
this.value = value;
19-
this.intValue = intValue;
20-
}
21-
22-
public String getValue() {
23-
return value;
24-
}
25-
26-
public int getIntValue() {
27-
return intValue;
28-
}
29-
30-
}
5+
private String value;
6+
7+
private int intValue;
8+
9+
// MaD=p;Factory;false;create;(String,int);;Argument[0];ReturnValue;taint;df-generated
10+
public static Factory create(String value, int foo) {
11+
return new Factory(value, foo);
12+
}
13+
14+
// MaD=p;Factory;false;create;(String);;Argument[0];ReturnValue;taint;df-generated
15+
public static Factory create(String value) {
16+
return new Factory(value, 0);
17+
}
18+
19+
private Factory(String value, int intValue) {
20+
this.value = value;
21+
this.intValue = intValue;
22+
}
23+
24+
// MaD=p;Factory;false;getValue;();;Argument[this];ReturnValue;taint;df-generated
25+
public String getValue() {
26+
return value;
27+
}
28+
29+
public int getIntValue() {
30+
return intValue;
31+
}
32+
}

java/ql/test/utils/modelgenerator/dataflow/p/FinalClass.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
public final class FinalClass {
44

5-
private static final String C = "constant";
5+
private static final String C = "constant";
66

7-
public String returnsInput(String input) {
8-
return input;
9-
}
7+
// MaD=p;FinalClass;false;returnsInput;(String);;Argument[0];ReturnValue;taint;df-generated
8+
public String returnsInput(String input) {
9+
return input;
10+
}
1011

11-
public String returnsConstant() {
12-
return C;
13-
}
14-
15-
}
12+
public String returnsConstant() {
13+
return C;
14+
}
15+
}

java/ql/test/utils/modelgenerator/dataflow/p/FluentAPI.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
public final class FluentAPI {
44

5-
public FluentAPI returnsThis(String input) {
6-
return this;
5+
// MaD=p;FluentAPI;false;returnsThis;(String);;Argument[this];ReturnValue;value;df-generated
6+
public FluentAPI returnsThis(String input) {
7+
return this;
8+
}
9+
10+
public class Inner {
11+
public FluentAPI notThis(String input) {
12+
return FluentAPI.this;
713
}
8-
9-
public class Inner {
10-
public FluentAPI notThis(String input) {
11-
return FluentAPI.this;
12-
}
13-
}
14-
15-
}
14+
}
15+
}

java/ql/test/utils/modelgenerator/dataflow/p/ImmutablePojo.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@
22

33
public final class ImmutablePojo {
44

5-
private final String value;
6-
7-
private final long x;
8-
9-
public ImmutablePojo(String value, int x) {
10-
this.value = value;
11-
this.x = x;
12-
}
13-
14-
public String getValue() {
15-
return value;
16-
}
17-
18-
public long getX() {
19-
return x;
20-
}
21-
22-
public String or(String defaultValue) {
23-
return value != null ? value : defaultValue;
24-
}
25-
26-
}
5+
private final String value;
6+
7+
private final long x;
8+
9+
// MaD=p;ImmutablePojo;false;ImmutablePojo;(String,int);;Argument[0];Argument[this];taint;df-generated
10+
public ImmutablePojo(String value, int x) {
11+
this.value = value;
12+
this.x = x;
13+
}
14+
15+
// MaD=p;ImmutablePojo;false;getValue;();;Argument[this];ReturnValue;taint;df-generated
16+
public String getValue() {
17+
return value;
18+
}
19+
20+
public long getX() {
21+
return x;
22+
}
23+
24+
// MaD=p;ImmutablePojo;false;or;(String);;Argument[0];ReturnValue;taint;df-generated
25+
// MaD=p;ImmutablePojo;false;or;(String);;Argument[this];ReturnValue;taint;df-generated
26+
public String or(String defaultValue) {
27+
return value != null ? value : defaultValue;
28+
}
29+
}
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package p;
22

33
public class InnerClasses {
4-
5-
class IgnoreMe {
6-
public String no(String input) {
7-
return input;
8-
}
9-
}
10-
11-
public class CaptureMe {
12-
public String yesCm(String input) {
13-
return input;
14-
}
4+
5+
class IgnoreMe {
6+
public String no(String input) {
7+
return input;
158
}
9+
}
1610

17-
public String yes(String input) {
18-
return input;
11+
public class CaptureMe {
12+
// MaD=p;InnerClasses$CaptureMe;true;yesCm;(String);;Argument[0];ReturnValue;taint;df-generated
13+
public String yesCm(String input) {
14+
return input;
1915
}
16+
}
2017

18+
// MaD=p;InnerClasses;true;yes;(String);;Argument[0];ReturnValue;taint;df-generated
19+
public String yes(String input) {
20+
return input;
21+
}
2122
}

java/ql/test/utils/modelgenerator/dataflow/p/InnerHolder.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,39 @@
22

33
public final class InnerHolder {
44

5-
private class Context {
6-
private String value;
5+
private class Context {
6+
private String value;
77

8-
Context(String value) {
9-
this.value = value;
10-
}
11-
12-
public String getValue() {
13-
return value;
14-
}
8+
Context(String value) {
9+
this.value = value;
1510
}
1611

17-
private Context context = null;
12+
public String getValue() {
13+
return value;
14+
}
15+
}
1816

19-
private StringBuilder sb = new StringBuilder();
17+
private Context context = null;
2018

21-
public void setContext(String value) {
22-
context = new Context(value);
23-
}
19+
private StringBuilder sb = new StringBuilder();
2420

25-
public void explicitSetContext(String value) {
26-
this.context = new Context(value);
27-
}
21+
// MaD=p;InnerHolder;false;setContext;(String);;Argument[0];Argument[this];taint;df-generated
22+
public void setContext(String value) {
23+
context = new Context(value);
24+
}
2825

29-
public void append(String value) {
30-
sb.append(value);
31-
}
26+
// MaD=p;InnerHolder;false;explicitSetContext;(String);;Argument[0];Argument[this];taint;df-generated
27+
public void explicitSetContext(String value) {
28+
this.context = new Context(value);
29+
}
3230

33-
public String getValue() {
34-
return context.getValue();
35-
}
31+
// MaD=p;InnerHolder;false;append;(String);;Argument[0];Argument[this];taint;df-generated
32+
public void append(String value) {
33+
sb.append(value);
34+
}
3635

37-
}
36+
// MaD=p;InnerHolder;false;getValue;();;Argument[this];ReturnValue;taint;df-generated
37+
public String getValue() {
38+
return context.getValue();
39+
}
40+
}

0 commit comments

Comments
 (0)