11package com .prunoideae .probejs .formatter ;
22
33import com .prunoideae .probejs .formatter .formatter .FormatterType ;
4- import com .prunoideae .probejs .formatter . formatter . IFormatter ;
4+ import com .prunoideae .probejs .info . ClassInfo ;
55import com .prunoideae .probejs .info .MethodInfo ;
66import com .prunoideae .probejs .info .type .ITypeInfo ;
77import com .prunoideae .probejs .info .type .TypeInfoClass ;
88import com .prunoideae .probejs .info .type .TypeInfoParameterized ;
99import com .prunoideae .probejs .info .type .TypeInfoVariable ;
1010import dev .latvian .mods .kubejs .item .ingredient .IngredientJS ;
11- import dev .latvian .mods .kubejs .util .BuilderBase ;
1211
1312import java .lang .reflect .Method ;
1413import java .lang .reflect .Modifier ;
15- import java .util .ArrayList ;
16- import java .util .HashSet ;
17- import java .util .List ;
18- import java .util .Set ;
19- import java .util .function .*;
14+ import java .lang .reflect .TypeVariable ;
15+ import java .util .*;
2016
2117public class SpecialTypes {
2218
@@ -30,22 +26,25 @@ private FormatterLambda(MethodInfo info) {
3026 }
3127
3228 public String format (ITypeInfo typeInfo ) {
33- List < ITypeInfo > paramTypes = new ArrayList <>();
29+ Map < String , ITypeInfo > variableMap = new HashMap <>();
3430 if (typeInfo instanceof TypeInfoParameterized parameterized ) {
35- paramTypes .addAll (parameterized .getParamTypes ());
31+ List <ITypeInfo > concreteTypes = new ArrayList <>(parameterized .getParamTypes ());
32+ for (ITypeInfo variable : info .getFrom ().getParameters ()) {
33+ variableMap .put (variable .getTypeName (), concreteTypes .isEmpty () ? new TypeInfoClass (Object .class ) : concreteTypes .remove (0 ));
34+ }
3635 }
3736
3837 List <String > formattedParam = new ArrayList <>();
3938 for (MethodInfo .ParamInfo param : info .getParams ()) {
4039 ITypeInfo resolvedType = param .getType ();
4140 if (resolvedType instanceof TypeInfoVariable ) {
42- resolvedType = paramTypes . isEmpty () ? new TypeInfoClass (Object .class ) : paramTypes . remove ( 0 );
41+ resolvedType = variableMap . getOrDefault ( resolvedType . getTypeName (), new TypeInfoClass (Object .class ));
4342 }
4443 formattedParam .add ("%s: %s" .formatted (param .getName (), new FormatterType (resolvedType ).format (0 , 0 )));
4544 }
4645 ITypeInfo resolvedReturn = info .getReturnType ();
4746 if (resolvedReturn instanceof TypeInfoVariable ) {
48- resolvedReturn = paramTypes . isEmpty () ? new TypeInfoClass (Object .class ) : paramTypes . remove ( 0 );
47+ resolvedReturn = variableMap . getOrDefault ( resolvedReturn . getTypeName (), new TypeInfoClass (Object .class ));
4948 }
5049 return "(%s) => %s" .formatted (String .join (", " , formattedParam ), new FormatterType (resolvedReturn ).format (0 , 0 ));
5150 }
@@ -55,9 +54,10 @@ public static void processFunctionalInterfaces(Set<Class<?>> globalClasses) {
5554 for (Class <?> clazz : globalClasses ) {
5655 if (clazz .isInterface () && clazz .getAnnotation (FunctionalInterface .class ) != null && !skippedSpecials .contains (clazz )) {
5756 //Functional interfaces has one and only one abstract method
58- for (Method method : clazz .getMethods ()) {
59- if (Modifier .isAbstract (method .getModifiers ())) {
60- FormatterLambda formatter = new FormatterLambda (new MethodInfo (method , method .getDeclaringClass ()));
57+ ClassInfo info = ClassInfo .getOrCache (clazz );
58+ for (MethodInfo method : info .getMethodInfo ()) {
59+ if (method .isAbstract ()) {
60+ FormatterLambda formatter = new FormatterLambda (method );
6161 NameResolver .putTypeFormatter (clazz , formatter ::format );
6262 break ;
6363 }
0 commit comments