11import powershell
2+ private predicate parseCommandName ( Cmd cmd , string namespace , string name ) {
3+ exists ( string qualified | command ( cmd , qualified , _, _, _) |
4+ namespace = qualified .regexpCapture ( "([^\\\\]+)\\\\([^\\\\]+)" , 1 ) and
5+ name = qualified .regexpCapture ( "([^\\\\]+)\\\\([^\\\\]+)" , 2 )
6+ or
7+ // Not a qualified name
8+ not exists ( qualified .indexOf ( "\\" ) ) and
9+ namespace = "" and
10+ name = qualified
11+ )
12+ }
213
314class Cmd extends @command, CmdBase {
4- override string toString ( ) { result = this .getCommandName ( ) }
15+ override string toString ( ) { result = this .getQualifiedCommandName ( ) }
516
617 override SourceLocation getLocation ( ) { command_location ( this , result ) }
718
8- string getCommandName ( ) { command ( this , result , _, _, _) }
19+ /** Gets the name of the command without any qualifiers. */
20+ string getCommandName ( ) { parseCommandName ( this , _, result ) }
21+
22+ /** Holds if the command is qualified. */
23+ predicate isQualified ( ) { parseCommandName ( this , any ( string s | s != "" ) , _) }
24+
25+ /** Gets the namespace qualifier of this command, if any. */
26+ string getNamespaceQualifier ( ) { parseCommandName ( this , result , _) }
27+
28+ /** Gets the (possibly qualified) name of this command. */
29+ string getQualifiedCommandName ( ) { command ( this , result , _, _, _) }
930
1031 int getKind ( ) { command ( this , _, result , _, _) }
1132
@@ -15,8 +36,10 @@ class Cmd extends @command, CmdBase {
1536
1637 CmdElement getElement ( int i ) { command_command_element ( this , i , result ) }
1738
39+ /** Gets the expression that determines the command to invoke. */
1840 Expr getCommand ( ) { result = this .getElement ( 0 ) }
1941
42+ /** Gets the name of this command, if this is statically known. */
2043 StringConstExpr getCmdName ( ) { result = this .getElement ( 0 ) }
2144
2245 /** Gets any argument to this command. */
0 commit comments