getFunctionCodeUnit method

FutureOr<({String? className, CodeUnit? codeUnit})> getFunctionCodeUnit(
  1. String namespace,
  2. String functionName, {
  3. bool allowClassMethod = false,
})

Implementation

FutureOr<({CodeUnit? codeUnit, String? className})> getFunctionCodeUnit(
    String namespace, String functionName,
    {bool allowClassMethod = false}) {
  var codeNamespace = _languageNamespaces.get(namespace);

  var codeUnit = codeNamespace.getCodeUnitWithFunction(functionName);

  if (codeUnit == null && allowClassMethod) {
    var codeUnitWithMethod =
        codeNamespace.getCodeUnitWithClassMethod(functionName);

    if (codeUnitWithMethod != null) {
      var classWithMethod =
          codeUnitWithMethod.root?.getClassWithMethod(functionName);

      if (classWithMethod != null) {
        return (
          codeUnit: codeUnitWithMethod,
          className: classWithMethod.name,
        );
      }
    }
  }

  return (codeUnit: codeUnit, className: null);
}