@@ -40,15 +40,23 @@ class MethodBase extends Callable, BodyStmt, Scope, TMethodBase {
4040 * Holds if this method is public.
4141 * Methods are public by default.
4242 */
43- predicate isPublic ( ) {
44- forall ( VisibilityModifier m | m = this .getVisibilityModifier ( ) | m .getVisibility ( ) = "public" )
45- }
43+ predicate isPublic ( ) { this .getVisibility ( ) = "public" }
4644
4745 /** Holds if this method is private. */
48- predicate isPrivate ( ) { this .getVisibilityModifier ( ) . getVisibility ( ) = "private" }
46+ predicate isPrivate ( ) { this .getVisibility ( ) = "private" }
4947
5048 /** 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+ }
5260
5361 /**
5462 * Gets the visibility modifier that defines the visibility of this method, if
@@ -151,21 +159,26 @@ class Method extends MethodBase, TMethod {
151159 * end
152160 * ```
153161 */
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 ( ) }
162163
163164 final override Parameter getParameter ( int n ) {
164165 toGenerated ( result ) = g .getParameters ( ) .getChild ( n )
165166 }
166167
167168 final override string toString ( ) { result = this .getName ( ) }
168169
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+
169182 override VisibilityModifier getVisibilityModifier ( ) {
170183 result .getEnclosingModule ( ) = this .getEnclosingModule ( ) and
171184 (
0 commit comments