@@ -40,16 +40,6 @@ class ConstantAccess extends Expr, TConstantAccess {
40
40
*/
41
41
predicate hasGlobalScope ( ) { none ( ) }
42
42
43
- // gets the full name
44
- string getFullName ( ) {
45
- exists ( ConstantAccess ca | this .getScopeExpr ( ) = ca |
46
- result = ca .getFullName ( ) + "::" + this .getName ( ) )
47
- or
48
- // TODO if the getScopeExpr is not a constant, try to figure out which constants it could be?
49
- not exists ( ConstantAccess ca | this .getScopeExpr ( ) = ca ) and
50
- result = this .getName ( )
51
- }
52
-
53
43
override string toString ( ) { result = this .getName ( ) }
54
44
55
45
override AstNode getAChild ( string pred ) {
@@ -194,16 +184,34 @@ class ConstantWriteAccess extends ConstantAccess {
194
184
*
195
185
* the constant `Baz` has the fully qualified name `Foo::Bar::Baz`, and
196
186
* `CONST_A` has the fully qualified name `Foo::CONST_A`.
187
+ *
188
+ * Important note: This can return more than one value, because there are
189
+ * situations where there can be multiple possible "fully qualified" names.
190
+ * For example:
191
+ * ```
192
+ * module Mod4
193
+ * include Mod1
194
+ * module Mod3::Mod5 end
195
+ * end
196
+ * ```
197
+ * In the above snippet, `Mod5` has two valid fully qualified names it can be
198
+ * referred to by: `Mod1::Mod3::Mod5`, or `Mod4::Mod3::Mod5`.
199
+ *
200
+ * Another example has to do with the order in which module definitions are
201
+ * executed at runtime. Because of the way that ruby dynamically looks up
202
+ * constants up the namespace chain, the fully qualified name of a nested
203
+ * constant can be ambiguous from just statically looking at the AST.
197
204
*/
198
- string getQualifiedName ( ) {
199
- /* get the qualified name for the parent module, then append w */
200
- exists ( ConstantWriteAccess parent | parent = this .getEnclosingModule ( ) |
201
- result = parent .getQualifiedName ( ) + "::" + this .getFullName ( )
202
- )
203
- or
204
- /* base case - there's no parent module */
205
- not exists ( ConstantWriteAccess parent | parent = this .getEnclosingModule ( ) ) and
206
- result = this .getFullName ( )
205
+ string getAQualifiedName ( ) {
206
+ result = resolveConstantWriteAccess ( this )
207
+ }
208
+
209
+ /**
210
+ * gets a qualified name for this constant. Deprecated in favor of
211
+ * `getAQualifiedName` because this can return more than one value
212
+ */
213
+ deprecated string getQualifiedName ( ) {
214
+ result = this .getAQualifiedName ( )
207
215
}
208
216
}
209
217
0 commit comments