@@ -24,7 +24,7 @@ predicate isWithinType(Callable c, RefType t) {
2424}
2525
2626/**
27- * Holds if a `Callable ` is within same package as the `RefType `
27+ * Holds if `e ` is within the same package as `t `
2828 */
2929predicate isWithinPackage ( Expr e , RefType t ) {
3030 e .getCompilationUnit ( ) .getPackage ( ) = t .getPackage ( )
@@ -44,49 +44,49 @@ where
4444 annotated .getAnAnnotation ( ) .getType ( ) .hasName ( "VisibleForTesting" ) and
4545 (
4646 // 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+ )
5960 )
60- )
6161 or
6262 // 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+ )
7576 )
76- )
7777 or
7878 // 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+ )
8889 )
89- )
9090 ) and
9191 // not in a test where use is appropriate
9292 not e .getEnclosingCallable ( ) instanceof LikelyTestMethod and
0 commit comments