Skip to content

Commit 0645f62

Browse files
committed
Use monotonicAggregates to avoid non-monotonic recursions
1 parent 66e6f4d commit 0645f62

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

java/ql/src/utils/stub-generator/Stubs.qll

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract private class GeneratedType extends ClassOrInterface {
3636
}
3737

3838
private string stubAnnotations() {
39-
result = concat("@" + stubAnnotation(this.(AnnotationType).getAnAnnotation()) + "\n")
39+
result = concat(stubAnnotation(this.(AnnotationType).getAnAnnotation()) + "\n")
4040
}
4141

4242
/** Gets the entire Java stub code for this type. */
@@ -398,20 +398,22 @@ private string stubMember(Member m) {
398398
)
399399
}
400400

401+
language[monotonicAggregates]
401402
private string stubAnnotation(Annotation a) {
402403
if exists(a.getAValue())
403404
then
404405
result =
405-
a.getType().getName() + "(" +
406+
"@" + a.getType().getName() + "(" +
406407
concat(string name, Expr value |
407408
value = a.getValue(name)
408409
|
409410
name + "=" + stubAnnotationValue(value), ","
410411
) + ")"
411-
else result = a.getType().getName()
412+
else result = "@" + a.getType().getName()
412413
}
413414

414-
private string stubAnnotationSimpleValue(Expr value) {
415+
language[monotonicAggregates]
416+
private string stubAnnotationValue(Expr value) {
415417
result = value.(FieldAccess).getField().getQualifiedName()
416418
or
417419
(
@@ -422,15 +424,9 @@ private string stubAnnotationSimpleValue(Expr value) {
422424
then result = "\"\""
423425
else result = stubDefaultValue(value.getType())
424426
or
425-
// We can't use stubAnnotation here because it causes a non-monotonic recursion.
426-
// Handling the most basic case of a nested annotation for now.
427-
result = "@" + value.(Annotation).getType().getName()
427+
result = stubAnnotation(value)
428428
or
429429
result = value.(TypeLiteral).getReferencedType().getName() + ".class"
430-
}
431-
432-
private string stubAnnotationValue(Expr value) {
433-
result = stubAnnotationSimpleValue(value)
434430
or
435431
value instanceof ArrayInit and
436432
result =
@@ -439,7 +435,7 @@ private string stubAnnotationValue(Expr value) {
439435
i >= 0 and
440436
arrayElement = value.(ArrayInit).getInit(i)
441437
|
442-
stubAnnotationSimpleValue(arrayElement), "," order by i
438+
stubAnnotationValue(arrayElement), "," order by i
443439
) + "}"
444440
}
445441

0 commit comments

Comments
 (0)