@@ -40,15 +40,23 @@ class MethodBase extends Callable, BodyStmt, Scope, TMethodBase {
40
40
* Holds if this method is public.
41
41
* Methods are public by default.
42
42
*/
43
- predicate isPublic ( ) {
44
- forall ( VisibilityModifier m | m = this .getVisibilityModifier ( ) | m .getVisibility ( ) = "public" )
45
- }
43
+ predicate isPublic ( ) { this .getVisibility ( ) = "public" }
46
44
47
45
/** Holds if this method is private. */
48
- predicate isPrivate ( ) { this .getVisibilityModifier ( ) . getVisibility ( ) = "private" }
46
+ predicate isPrivate ( ) { this .getVisibility ( ) = "private" }
49
47
50
48
/** Holds if this method is protected. */
51
- predicate isProtected ( ) { this .getVisibilityModifier ( ) .getVisibility ( ) = "protected" }
49
+ predicate isProtected ( ) { this .getVisibility ( ) = "protected" }
50
+
51
+ /**
52
+ * Gets a string describing the visibility of this method.
53
+ * This is either 'public', 'private' or 'protected'.
54
+ */
55
+ string getVisibility ( ) {
56
+ result = this .getVisibilityModifier ( ) .getVisibility ( )
57
+ or
58
+ not exists ( this .getVisibilityModifier ( ) ) and result = "public"
59
+ }
52
60
53
61
/**
54
62
* Gets the visibility modifier that defines the visibility of this method, if
@@ -151,21 +159,26 @@ class Method extends MethodBase, TMethod {
151
159
* end
152
160
* ```
153
161
*/
154
- override predicate isPrivate ( ) {
155
- this .getVisibilityModifier ( ) .getVisibility ( ) = "private"
156
- or
157
- // Top-level methods are private members of the Object class
158
- this .getEnclosingModule ( ) instanceof Toplevel
159
- }
160
-
161
- override predicate isPublic ( ) { super .isPublic ( ) and not this .isPrivate ( ) }
162
+ override predicate isPrivate ( ) { super .isPrivate ( ) }
162
163
163
164
final override Parameter getParameter ( int n ) {
164
165
toGenerated ( result ) = g .getParameters ( ) .getChild ( n )
165
166
}
166
167
167
168
final override string toString ( ) { result = this .getName ( ) }
168
169
170
+ override string getVisibility ( ) {
171
+ result = this .getVisibilityModifier ( ) .getVisibility ( )
172
+ or
173
+ this .getEnclosingModule ( ) instanceof Toplevel and
174
+ not exists ( this .getVisibilityModifier ( ) ) and
175
+ result = "private"
176
+ or
177
+ not this .getEnclosingModule ( ) instanceof Toplevel and
178
+ not exists ( this .getVisibilityModifier ( ) ) and
179
+ result = "public"
180
+ }
181
+
169
182
override VisibilityModifier getVisibilityModifier ( ) {
170
183
result .getEnclosingModule ( ) = this .getEnclosingModule ( ) and
171
184
(
0 commit comments