@@ -21,27 +21,43 @@ public AwkStringMixin(@NotNull ASTNode node) {
21
21
private static final Pattern stringThatCanBeFunctionName =
22
22
Pattern .compile ("\" [A-Za-z_][A-Za-z0-9_]*\" " );
23
23
24
- static boolean canBeFunctionName (String s ) {
25
- return stringThatCanBeFunctionName .matcher (s ).matches ();
26
- }
27
-
28
24
@ Override
29
25
public String getName () {
26
+ return getPossibleFunctionName ();
27
+ }
28
+
29
+ @ Nullable
30
+ private String getPossibleFunctionName () {
30
31
String str = getText ();
31
32
return canBeFunctionName (str ) ? unquoteString (str ) : null ;
32
33
}
33
34
35
+ static boolean canBeFunctionName (String s ) {
36
+ return stringThatCanBeFunctionName .matcher (s ).matches ();
37
+ }
38
+
34
39
public PsiElement setName (String newName ) {
35
40
return replaceNameNode (AwkElementFactory .createFunctionCallName (getProject (), newName ));
36
41
}
37
42
38
43
@ Override
39
44
public PsiReference getReference () {
40
- return getName () != null && isRhsOfAssignment ()
45
+ return getPossibleFunctionName () != null && canBeFunctionReference ()
41
46
? new AwkReferenceFunction (this , TextRange .from (1 , getTextLength () - 2 ))
42
47
: null ;
43
48
}
44
49
50
+ private boolean canBeFunctionReference () {
51
+ return isRhsOfAssignment () || isUserFunctionArgument ();
52
+ }
53
+
54
+ /** `f("fname")` but not `substr("fname")` (built-in) */
55
+ private boolean isUserFunctionArgument () {
56
+ AwkGawkFuncCallList callList = AwkUtil .findParent (this , AwkGawkFuncCallList .class );
57
+ return callList != null && callList .getParent () instanceof AwkFunctionCallUser ;
58
+ }
59
+
60
+ /** `a = "fname"` */
45
61
private boolean isRhsOfAssignment () {
46
62
return AwkUtil .isType (AwkUtil .getPrevNotWhitespace (getParent ()), AwkTypes .ASSIGN );
47
63
}
0 commit comments