@@ -24,7 +24,7 @@ predicate isWithinType(Callable c, RefType t) {
24
24
}
25
25
26
26
/**
27
- * Holds if a `Callable ` is within same package as the `RefType `
27
+ * Holds if `e ` is within the same package as `t `
28
28
*/
29
29
predicate isWithinPackage ( Expr e , RefType t ) {
30
30
e .getCompilationUnit ( ) .getPackage ( ) = t .getPackage ( )
@@ -44,49 +44,49 @@ where
44
44
annotated .getAnAnnotation ( ) .getType ( ) .hasName ( "VisibleForTesting" ) and
45
45
(
46
46
// field access
47
- exists ( FieldAccess v |
48
- v = e and
49
- v .getField ( ) = annotated and
50
- // depending on the visibility of the field, using the annotation to abuse the visibility may/may not be occurring
51
- (
52
- // if its package protected report when its used outside its class bc it should have been private (class only permitted)
53
- v .getField ( ) .isPackageProtected ( ) and
54
- not isWithinType ( v .getEnclosingCallable ( ) , v .getField ( ) .getDeclaringType ( ) )
55
- or
56
- // if public or protected report when its used outside its package because package protected should have been enough (package only permitted)
57
- ( v .getField ( ) .isPublic ( ) or v .getField ( ) .isProtected ( ) ) and
58
- not isWithinPackage ( v , v .getField ( ) .getDeclaringType ( ) )
47
+ e =
48
+ any ( FieldAccess v |
49
+ v .getField ( ) = annotated and
50
+ // depending on the visibility of the field, using the annotation to abuse the visibility may/may not be occurring
51
+ (
52
+ // if its package protected report when its used outside its class because it should have been private (class only permitted)
53
+ v .getField ( ) .isPackageProtected ( ) and
54
+ not isWithinType ( v .getEnclosingCallable ( ) , v .getField ( ) .getDeclaringType ( ) )
55
+ or
56
+ // if public or protected report when its used outside its package because package protected should have been enough (package only permitted)
57
+ ( v .getField ( ) .isPublic ( ) or v .getField ( ) .isProtected ( ) ) and
58
+ not isWithinPackage ( v , v .getField ( ) .getDeclaringType ( ) )
59
+ )
59
60
)
60
- )
61
61
or
62
62
// method access
63
- exists ( MethodCall c |
64
- c = e and
65
- c .getMethod ( ) = annotated and
66
- // depending on the visibility of the method, using the annotation to abuse the visibility may/may not be occurring
67
- (
68
- // if its package protected report when its used outside its class bc it should have been private (class only permitted)
69
- c .getMethod ( ) .isPackageProtected ( ) and
70
- not isWithinType ( c .getEnclosingCallable ( ) , c .getMethod ( ) .getDeclaringType ( ) )
71
- or
72
- // if public or protected report when its used outside its package because package protected should have been enough (package only permitted)
73
- ( c .getMethod ( ) .isPublic ( ) or c .getMethod ( ) .isProtected ( ) ) and
74
- not isWithinPackage ( c , c .getMethod ( ) .getDeclaringType ( ) )
63
+ e =
64
+ any ( MethodCall c |
65
+ c .getMethod ( ) = annotated and
66
+ // depending on the visibility of the method, using the annotation to abuse the visibility may/may not be occurring
67
+ (
68
+ // if its package protected report when its used outside its class because it should have been private (class only permitted)
69
+ c .getMethod ( ) .isPackageProtected ( ) and
70
+ not isWithinType ( c .getEnclosingCallable ( ) , c .getMethod ( ) .getDeclaringType ( ) )
71
+ or
72
+ // if public or protected report when its used outside its package because package protected should have been enough (package only permitted)
73
+ ( c .getMethod ( ) .isPublic ( ) or c .getMethod ( ) .isProtected ( ) ) and
74
+ not isWithinPackage ( c , c .getMethod ( ) .getDeclaringType ( ) )
75
+ )
75
76
)
76
- )
77
77
or
78
78
// Class instantiation - report if used outside appropriate scope
79
- exists ( ClassInstanceExpr c |
80
- c = e and
81
- c .getConstructedType ( ) = annotated and
82
- (
83
- c .getConstructedType ( ) .isPublic ( ) and not isWithinPackage ( c , c .getConstructedType ( ) )
84
- or
85
- c .getConstructedType ( ) .hasNoModifier ( ) and
86
- c .getConstructedType ( ) instanceof NestedClass and
87
- not isWithinType ( c .getEnclosingCallable ( ) , c .getConstructedType ( ) )
79
+ e =
80
+ any ( ClassInstanceExpr c |
81
+ c .getConstructedType ( ) = annotated and
82
+ (
83
+ c .getConstructedType ( ) .isPublic ( ) and not isWithinPackage ( c , c .getConstructedType ( ) )
84
+ or
85
+ c .getConstructedType ( ) .hasNoModifier ( ) and
86
+ c .getConstructedType ( ) instanceof NestedClass and
87
+ not isWithinType ( c .getEnclosingCallable ( ) , c .getConstructedType ( ) )
88
+ )
88
89
)
89
- )
90
90
) and
91
91
// not in a test where use is appropriate
92
92
not e .getEnclosingCallable ( ) instanceof LikelyTestMethod and
0 commit comments