Skip to content

Commit 5ddcb16

Browse files
committed
Java: Add content based model generation test.
1 parent 6365e5e commit 5ddcb16

16 files changed

+82
-5
lines changed

java/ql/src/utils/modelgenerator/CaptureContentSummaryModels.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* @name Capture field based summary models.
3-
* @description Finds applicable field based summary models to be used by other queries.
2+
* @name Capture content based summary models.
3+
* @description Finds applicable content based summary models to be used by other queries.
44
* @kind diagnostic
5-
* @id java/utils/modelgenerator/fieldbased-summary-models
5+
* @id java/utils/modelgenerator/contentbased-summary-models
66
* @tags modelgenerator
77
*/
88

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
unexpectedModel
2+
expectedModel
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.CaptureModels
3+
import TestUtilities.InlineMadTest
4+
5+
module InlineMadTestConfig implements InlineMadTestConfigSig {
6+
string getCapturedModel(Callable c) { result = captureContentFlow(c) }
7+
8+
string getKind() { result = "contentbased-summary" }
9+
}
10+
11+
import InlineMadTest<InlineMadTestConfig>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
public final class Factory {
44

5-
private String value;
5+
public String value;
66

77
private int intValue;
88

99
// summary=p;Factory;false;create;(String,int);;Argument[0];ReturnValue;taint;df-generated
10+
// contentbased-summary=p;Factory;false;create;(String,int);;Argument[0];ReturnValue.Field[p.Factory.value];value;df-generated
1011
public static Factory create(String value, int foo) {
1112
return new Factory(value, foo);
1213
}
1314

1415
// summary=p;Factory;false;create;(String);;Argument[0];ReturnValue;taint;df-generated
16+
// contentbased-summary=p;Factory;false;create;(String);;Argument[0];ReturnValue.Field[p.Factory.value];value;df-generated
1517
public static Factory create(String value) {
1618
return new Factory(value, 0);
1719
}
@@ -22,6 +24,7 @@ private Factory(String value, int intValue) {
2224
}
2325

2426
// summary=p;Factory;false;getValue;();;Argument[this];ReturnValue;taint;df-generated
27+
// contentbased-summary=p;Factory;false;getValue;();;Argument[this].Field[p.Factory.value];ReturnValue;value;df-generated
2528
public String getValue() {
2629
return value;
2730
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public final class FinalClass {
55
private static final String C = "constant";
66

77
// summary=p;FinalClass;false;returnsInput;(String);;Argument[0];ReturnValue;taint;df-generated
8+
// contentbased-summary=p;FinalClass;false;returnsInput;(String);;Argument[0];ReturnValue;value;df-generated
89
public String returnsInput(String input) {
910
return input;
1011
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public final class FluentAPI {
44

55
// summary=p;FluentAPI;false;returnsThis;(String);;Argument[this];ReturnValue;value;df-generated
6+
// contentbased-summary=p;FluentAPI;false;returnsThis;(String);;Argument[this];ReturnValue;value;df-generated
67
public FluentAPI returnsThis(String input) {
78
return this;
89
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ public final class ImmutablePojo {
77
private final long x;
88

99
// summary=p;ImmutablePojo;false;ImmutablePojo;(String,int);;Argument[0];Argument[this];taint;df-generated
10+
// contentbased-summary=p;ImmutablePojo;false;ImmutablePojo;(String,int);;Argument[0];Argument[this].SyntheticField[p.ImmutablePojo.value];value;df-generated
1011
public ImmutablePojo(String value, int x) {
1112
this.value = value;
1213
this.x = x;
1314
}
1415

1516
// summary=p;ImmutablePojo;false;getValue;();;Argument[this];ReturnValue;taint;df-generated
17+
// contentbased-summary=p;ImmutablePojo;false;getValue;();;Argument[this].SyntheticField[p.ImmutablePojo.value];ReturnValue;value;df-generated
1618
public String getValue() {
1719
return value;
1820
}
@@ -24,6 +26,8 @@ public long getX() {
2426

2527
// summary=p;ImmutablePojo;false;or;(String);;Argument[0];ReturnValue;taint;df-generated
2628
// summary=p;ImmutablePojo;false;or;(String);;Argument[this];ReturnValue;taint;df-generated
29+
// contentbased-summary=p;ImmutablePojo;false;or;(String);;Argument[0];ReturnValue;value;df-generated
30+
// contentbased-summary=p;ImmutablePojo;false;or;(String);;Argument[this].SyntheticField[p.ImmutablePojo.value];ReturnValue;value;df-generated
2731
public String or(String defaultValue) {
2832
return value != null ? value : defaultValue;
2933
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public abstract class BasePublic {
1111

1212
public class AImplBasePrivateImpl extends BasePrivate {
1313
// summary=p;Inheritance$AImplBasePrivateImpl;true;id;(String);;Argument[0];ReturnValue;taint;df-generated
14+
// contentbased-summary=p;Inheritance$AImplBasePrivateImpl;true;id;(String);;Argument[0];ReturnValue;value;df-generated
1415
@Override
1516
public String id(String s) {
1617
return s;
@@ -19,6 +20,7 @@ public String id(String s) {
1920

2021
public class AImplBasePublic extends BasePublic {
2122
// summary=p;Inheritance$BasePublic;true;id;(String);;Argument[0];ReturnValue;taint;df-generated
23+
// contentbased-summary=p;Inheritance$BasePublic;true;id;(String);;Argument[0];ReturnValue;value;df-generated
2224
@Override
2325
public String id(String s) {
2426
return s;
@@ -59,6 +61,7 @@ private abstract class E implements IPrivate2 {
5961

6062
public class BImpl extends B {
6163
// summary=p;Inheritance$IPublic1;true;id;(String);;Argument[0];ReturnValue;taint;df-generated
64+
// contentbased-summary=p;Inheritance$IPublic1;true;id;(String);;Argument[0];ReturnValue;value;df-generated
6265
@Override
6366
public String id(String s) {
6467
return s;
@@ -67,6 +70,7 @@ public String id(String s) {
6770

6871
public class CImpl extends C {
6972
// summary=p;Inheritance$C;true;id;(String);;Argument[0];ReturnValue;taint;df-generated
73+
// contentbased-summary=p;Inheritance$C;true;id;(String);;Argument[0];ReturnValue;value;df-generated
7074
@Override
7175
public String id(String s) {
7276
return s;
@@ -75,6 +79,7 @@ public String id(String s) {
7579

7680
public class DImpl extends D {
7781
// summary=p;Inheritance$IPublic2;true;id;(String);;Argument[0];ReturnValue;taint;df-generated
82+
// contentbased-summary=p;Inheritance$IPublic2;true;id;(String);;Argument[0];ReturnValue;value;df-generated
7883
@Override
7984
public String id(String s) {
8085
return s;
@@ -83,6 +88,7 @@ public String id(String s) {
8388

8489
public class EImpl extends E {
8590
// summary=p;Inheritance$EImpl;true;id;(String);;Argument[0];ReturnValue;taint;df-generated
91+
// contentbased-summary=p;Inheritance$EImpl;true;id;(String);;Argument[0];ReturnValue;value;df-generated
8692
@Override
8793
public String id(String s) {
8894
return s;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ public String no(String input) {
1010

1111
public class CaptureMe {
1212
// summary=p;InnerClasses$CaptureMe;true;yesCm;(String);;Argument[0];ReturnValue;taint;df-generated
13+
// contentbased-summary=p;InnerClasses$CaptureMe;true;yesCm;(String);;Argument[0];ReturnValue;value;df-generated
1314
public String yesCm(String input) {
1415
return input;
1516
}
1617
}
1718

1819
// summary=p;InnerClasses;true;yes;(String);;Argument[0];ReturnValue;taint;df-generated
20+
// contentbased-summary=p;InnerClasses;true;yes;(String);;Argument[0];ReturnValue;value;df-generated
1921
public String yes(String input) {
2022
return input;
2123
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,25 @@ public String getValue() {
1919
private StringBuilder sb = new StringBuilder();
2020

2121
// summary=p;InnerHolder;false;setContext;(String);;Argument[0];Argument[this];taint;df-generated
22+
// contentbased-summary=p;InnerHolder;false;setContext;(String);;Argument[0];Argument[this].SyntheticField[p.InnerHolder.context].SyntheticField[p.InnerHolder$Context.value];value;df-generated
2223
public void setContext(String value) {
2324
context = new Context(value);
2425
}
2526

2627
// summary=p;InnerHolder;false;explicitSetContext;(String);;Argument[0];Argument[this];taint;df-generated
28+
// contentbased-summary=p;InnerHolder;false;explicitSetContext;(String);;Argument[0];Argument[this].SyntheticField[p.InnerHolder.context].SyntheticField[p.InnerHolder$Context.value];value;df-generated
2729
public void explicitSetContext(String value) {
2830
this.context = new Context(value);
2931
}
3032

3133
// summary=p;InnerHolder;false;append;(String);;Argument[0];Argument[this];taint;df-generated
34+
// contentbased-summary=p;InnerHolder;false;append;(String);;Argument[0];Argument[this].SyntheticField[p.InnerHolder.sb];taint;df-generated
3235
public void append(String value) {
3336
sb.append(value);
3437
}
3538

3639
// summary=p;InnerHolder;false;getValue;();;Argument[this];ReturnValue;taint;df-generated
40+
// contentbased-summary=p;InnerHolder;false;getValue;();;Argument[this].SyntheticField[p.InnerHolder.context].SyntheticField[p.InnerHolder$Context.value];ReturnValue;value;df-generated
3741
public String getValue() {
3842
return context.getValue();
3943
}

0 commit comments

Comments
 (0)