@@ -12,40 +12,39 @@ public class GhostFunction {
1212 private String name ;
1313 private List <CtTypeReference <?>> param_types ;
1414 private CtTypeReference <?> return_type ;
15+ private String prefix ;
1516
16- private String klassName ;
17-
18- public GhostFunction ( GhostDTO f , Factory factory , String path , String klass ) {
19- name = f . getName ( );
20- return_type = Utils . getType ( f . getReturn_type (). equals ( klass ) ? path : f . getReturn_type (), factory );
21- param_types = new ArrayList <>() ;
17+ public GhostFunction ( GhostDTO f , Factory factory , String prefix ) {
18+ String klass = this . getParentClassName ( prefix );
19+ this . name = f . getName ();
20+ this . return_type = Utils . getType ( f . getReturn_type (). equals ( klass ) ? prefix : f . getReturn_type (), factory );
21+ this . param_types = new ArrayList <>( );
22+ this . prefix = prefix ;
2223 for (String t : f .getParam_types ()) {
23- param_types .add (Utils .getType (t .equals (klass ) ? path : t , factory ));
24+ this . param_types .add (Utils .getType (t .equals (klass ) ? prefix : t , factory ));
2425 }
2526 }
2627
2728 public GhostFunction (String name , List <String > param_types , CtTypeReference <?> return_type , Factory factory ,
28- String path , String klass ) {
29+ String prefix ) {
30+ String klass = this .getParentClassName (prefix );
31+ String type = return_type .toString ().equals (klass ) ? prefix : return_type .toString ();
2932 this .name = name ;
30- this .return_type = Utils .getType (return_type . toString (). equals ( klass ) ? path : return_type . toString () , factory );
33+ this .return_type = Utils .getType (type , factory );
3134 this .param_types = new ArrayList <>();
35+ this .prefix = prefix ;
3236 for (int i = 0 ; i < param_types .size (); i ++) {
3337 String mType = param_types .get (i ).toString ();
34- this .param_types .add (Utils .getType (mType .equals (klass ) ? path : mType , factory ));
38+ this .param_types .add (Utils .getType (mType .equals (klass ) ? prefix : mType , factory ));
3539 }
36- this .klassName = klass ;
3740 }
3841
39- protected GhostFunction (String name , List <CtTypeReference <?>> list , CtTypeReference <?> return_type , String klass ) {
42+ protected GhostFunction (String name , List <CtTypeReference <?>> list , CtTypeReference <?> return_type , String prefix ) {
4043 this .name = name ;
4144 this .return_type = return_type ;
4245 this .param_types = new ArrayList <>();
4346 this .param_types = list ;
44- this .klassName = klass ;
45- }
46-
47- public String getName () {
48- return name ;
47+ this .prefix = prefix ;
4948 }
5049
5150 public CtTypeReference <?> getReturnType () {
@@ -67,7 +66,30 @@ public String toString() {
6766 return sb .toString ();
6867 }
6968
69+ public String getName () {
70+ return name ;
71+ }
72+
73+ public String getPrefix () {
74+ return prefix ;
75+ }
76+
77+ public String getQualifiedName () {
78+ return Utils .qualifyName (prefix , name );
79+ }
80+
7081 public String getParentClassName () {
71- return klassName ;
82+ return getParentClassName (prefix );
83+ }
84+
85+ private String getParentClassName (String pref ) {
86+ return Utils .getSimpleName (pref );
87+ }
88+
89+ // Match by fully qualified name, exact simple name or by comparing the simple name of the provided identifier
90+ // This allows references written in a different class (different prefix) to still match
91+ public boolean matches (String name ) {
92+ return this .getQualifiedName ().equals (name ) || this .name .equals (name )
93+ || this .name .equals (Utils .getSimpleName (name ));
7294 }
7395}
0 commit comments