getObjectThatExtend function

Object getObjectThatExtend(
  1. ClassMirror classMirror
)

Gets the instance of the class that extends the classMirror from the classes annotated with @reflectable, for example:

If we have next Abstract class:

abstract class SomeService {
  String someMethod();
}

The Extension level of the next service is 1

class SomeServiceImpl implements SomeService {
  String someMethod() => 'someMethod';
}

And the Extension level of the next service is 2

class SomeServiceImpl2 extends SomeServiceImpl {
  String someMethod() => super.someMethod() + '2';
}

So that, this method will return an instance of SomeServiceImpl2

Implementation

Object getObjectThatExtend(ClassMirror classMirror) {
  ClassMirror? result;
  int counter = 0, counter2 = 0;
  for (Type type in classMirrors.keys) {
    counter = _getExtensionLevel(classMirror, type, counter);
    if (counter > 0 && counter2 < counter) {
      result = reflectType(type);
      counter2 = counter;
      counter = 0;
    }
  }

  return result?.constructors?['']?.$call?.call();
}