resolve static method

void resolve(
  1. Environment environment,
  2. InstanceProvider provider,
  3. TypeDescriptor type,
  4. Set<Type> types,
)

Implementation

static void resolve(Environment environment, InstanceProvider provider, TypeDescriptor type, Set<Type> types) {
  // make sure that i inherit superclass methods!

  List<MethodCall> methodList = [];

  // local methods

  Iterable<T> iterate<T>(List<T> list, {bool reverse = false}) {
    return reverse ? list.reversed : list;
  }

  void addMethod(Type type, MethodCall method, int lifecycle, bool reverse) {
    var list = allMethods.putIfAbsent(type, () => [for (int i = 0; i < 4; i++) []])[lifecycle];

    if ( reverse )
      list.insert(0, method);
    else
      list.add(method);

    methodList.add(method);
  }

  List<List<MethodCall>> inheritMethods(TypeDescriptor t) {
    var result = allMethods[t.type];

    if ( result != null )
      return result; // done

    result = allMethods[t.type] = [[], [], [], []];

    // super class

    if ( t.superClass != null ) {
      // recursion

      var inherited = inheritMethods(t.superClass!);

      for (int lifecycle = 0; lifecycle < 4; lifecycle++) {
        var reverse = lifecycle == 3;

        for (var method in iterate(inherited[lifecycle], reverse: reverse)) {
          addMethod(t.type, method, lifecycle, reverse);
        }
      }
    } // if

    // add own methods

    for (int lifecycle = 0; lifecycle < 4; lifecycle++) {
      var reverse = lifecycle == 3;

      for (MethodCall method in methods[t.type]?[lifecycle] ?? []) {
        addMethod(t.type, method, lifecycle, reverse); // methodList.add(method); //  was
      }
    }

    // done

    return result;
  } // inheritMethods

  // make sure, methods are inherited

  inheritMethods(type);

  // resolve matching methods

  for ( var method in methodList )
    method.resolve(environment, types);

  // store in provider

  provider.lifecycleMethods = allMethods[type.type]!;

  //for ( int i = 0; i < 4; i++)
  //  if (provider.lifecycleMethods[i]!.isEmpty)
   //   provider.lifecycleMethods[i] = null;
}