11package liquidjava .processor .refinement_checker .general_checkers ;
22
3+ import java .util .ArrayList ;
34import java .util .HashMap ;
45import java .util .List ;
56import java .util .Map ;
@@ -60,12 +61,13 @@ public void getConstructorRefinements(CtConstructor<?> c) throws LJError {
6061 public void getConstructorInvocationRefinements (CtConstructorCall <?> ctConstructorCall ) throws LJError {
6162 CtExecutableReference <?> exe = ctConstructorCall .getExecutable ();
6263 if (exe != null ) {
64+ List <CtTypeReference <?>> paramTypes = exe .getParameters ();
6365 RefinedFunction f = rtc .getContext ().getFunction (exe .getSimpleName (),
64- exe .getDeclaringType ().getQualifiedName (), ctConstructorCall . getArguments (). size () );
66+ exe .getDeclaringType ().getQualifiedName (), paramTypes );
6567 if (f != null ) {
6668 Map <String , String > map = checkInvocationRefinements (ctConstructorCall ,
6769 ctConstructorCall .getArguments (), ctConstructorCall .getTarget (), f .getName (),
68- f .getTargetClass ());
70+ f .getTargetClass (), paramTypes );
6971 AuxStateHandler .constructorStateMetadata (Keys .REFINEMENT , f , map , ctConstructorCall );
7072 }
7173 }
@@ -220,22 +222,15 @@ public <R> void getInvocationRefinements(CtInvocation<R> invocation) throws LJEr
220222
221223 } else if (method .getParent () instanceof CtClass ) {
222224 String ctype = ((CtClass <?>) method .getParent ()).getQualifiedName ();
223- int argSize = invocation .getArguments ().size ();
224- RefinedFunction f = rtc .getContext ().getFunction (method .getSimpleName (), ctype , argSize );
225+ List < CtTypeReference <?>> paramTypes = invocation .getExecutable ().getParameters ();
226+ RefinedFunction f = rtc .getContext ().getFunction (method .getSimpleName (), ctype , paramTypes );
225227 if (f != null ) { // inside rtc.context
226228 checkInvocationRefinements (invocation , invocation .getArguments (), invocation .getTarget (),
227- method .getSimpleName (), ctype );
229+ method .getSimpleName (), ctype , paramTypes );
228230 }
229231 }
230232 }
231233
232- public RefinedFunction getRefinementFunction (String methodName , String className , int size ) {
233- RefinedFunction f = rtc .getContext ().getFunction (methodName , className , size );
234- if (f == null )
235- f = rtc .getContext ().getFunction (String .format ("%s.%s" , className , methodName ), className , size );
236- return f ;
237- }
238-
239234 private void searchMethodInLibrary (CtExecutableReference <?> ctr , CtInvocation <?> invocation ) throws LJError {
240235 CtTypeReference <?> ctref = ctr .getDeclaringType ();
241236 if (ctref == null ) {
@@ -246,39 +241,47 @@ private void searchMethodInLibrary(CtExecutableReference<?> ctr, CtInvocation<?>
246241 String ctype = (ctref != null ) ? ctref .toString () : null ;
247242
248243 String name = ctr .getSimpleName (); // missing
249- int argSize = invocation . getArguments (). size ();
244+ List < CtTypeReference <?>> paramTypes = ctr . getParameters ();
250245 String qualifiedSignature = null ;
251246 if (ctype != null ) {
252247 qualifiedSignature = String .format ("%s.%s" , ctype , ctr .getSignature ());
253- if (rtc .getContext ().getFunction (qualifiedSignature , ctype , argSize ) != null ) {
248+ RefinedFunction f = rtc .getContext ().getFunction (qualifiedSignature , ctype , paramTypes );
249+ if (f != null ) {
254250 checkInvocationRefinements (invocation , invocation .getArguments (), invocation .getTarget (),
255- qualifiedSignature , ctype );
251+ qualifiedSignature , ctype , paramTypes );
256252 return ;
257253 }
258254 }
259255 String signature = ctr .getSignature ();
260- if (rtc .getContext ().getFunction (signature , ctype , argSize ) != null ) {
261- checkInvocationRefinements (invocation , invocation .getArguments (), invocation .getTarget (), signature , ctype );
256+ RefinedFunction f = rtc .getContext ().getFunction (signature , ctype , paramTypes );
257+ if (f != null ) {
258+ checkInvocationRefinements (invocation , invocation .getArguments (), invocation .getTarget (), signature , ctype ,
259+ paramTypes );
262260 return ;
263261 }
264- if (rtc .getContext ().getFunction (name , ctype , argSize ) != null ) { // inside rtc.context
265- checkInvocationRefinements (invocation , invocation .getArguments (), invocation .getTarget (), name , ctype );
262+ f = rtc .getContext ().getFunction (name , ctype , paramTypes );
263+ if (f != null ) { // inside rtc.context
264+ checkInvocationRefinements (invocation , invocation .getArguments (), invocation .getTarget (), name , ctype ,
265+ paramTypes );
266266 return ;
267267 }
268268 if (qualifiedSignature != null ) {
269269 String completeName = String .format ("%s.%s" , ctype , name );
270- if (rtc .getContext ().getFunction (completeName , ctype , argSize ) != null ) {
270+ f = rtc .getContext ().getFunction (completeName , ctype , paramTypes );
271+ if (f != null ) {
271272 checkInvocationRefinements (invocation , invocation .getArguments (), invocation .getTarget (), completeName ,
272- ctype );
273+ ctype , paramTypes );
273274 }
274275 }
275276 }
276277
277278 private Map <String , String > checkInvocationRefinements (CtElement invocation , List <CtExpression <?>> arguments ,
278- CtExpression <?> target , String methodName , String className ) throws LJError {
279+ CtExpression <?> target , String methodName , String className , List <CtTypeReference <?>> paramTypes )
280+ throws LJError {
279281 // -- Part 1: Check if the invocation is possible
280- int si = arguments .size ();
281- RefinedFunction f = rtc .getContext ().getFunction (methodName , className , si );
282+ RefinedFunction f = null ;
283+ if (paramTypes != null )
284+ f = rtc .getContext ().getFunction (methodName , className , paramTypes );
282285 if (f == null )
283286 return new HashMap <>();
284287 Map <String , String > map = mapInvocation (arguments , f );
@@ -407,8 +410,10 @@ public void loadFunctionInfo(CtExecutable<?> method) {
407410 className = ((CtInterface <?>) method .getParent ()).getQualifiedName ();
408411 }
409412 if (className != null ) {
410- RefinedFunction fi = getRefinementFunction (method .getSimpleName (), className ,
411- method .getParameters ().size ());
413+ List <CtTypeReference <?>> paramTypes = new ArrayList <>();
414+ for (CtParameter <?> p : method .getParameters ())
415+ paramTypes .add (p .getType ());
416+ RefinedFunction fi = rtc .getContext ().getFunction (method .getSimpleName (), className , paramTypes );
412417 if (fi != null ) {
413418 List <Variable > lv = fi .getArguments ();
414419 for (Variable v : lv )
0 commit comments