memberGet method

  1. @override
dynamic memberGet(
  1. String id, {
  2. String? from,
  3. bool isRecursive = false,
  4. bool ignoreUndefined = true,
})
override

Get the value of a static member from this HTClass via memberGet operator '.' for symbol searching, use the same name method on HTClassNamespace instead.

Implementation

@override
dynamic memberGet(String id,
    {String? from, bool isRecursive = false, bool ignoreUndefined = true}) {
  final getter = '${InternalIdentifier.getter}$id';
  final constructor = this.id != id
      ? '${InternalIdentifier.namedConstructorPrefix}$id'
      : InternalIdentifier.defaultConstructor;

  // if (isExternal && !internal) {
  //   final value =
  //       externalClass!.memberGet(id != id ? '$id.$id' : id);
  //   return value;
  // } else {
  if (namespace.symbols.containsKey(id)) {
    final decl = namespace.symbols[id];
    if (decl == null) return null;
    if (decl is HTDeclaration) {
      if (decl.isPrivate &&
          from != null &&
          !from.startsWith(namespace.fullName)) {
        throw HTError.privateMember(id);
      }
      decl.resolve();
      return decl.value;
    } else {
      if (interpreter.lexicon.isPrivate(id) &&
          from != null &&
          !from.startsWith(namespace.fullName)) {
        throw HTError.privateMember(id);
      }
      return decl;
    }
  } else if (namespace.symbols.containsKey(getter)) {
    final decl = namespace.symbols[getter];
    if (decl == null) return null;
    if (decl is! HTFunction) return null;
    if (decl.isPrivate &&
        from != null &&
        !from.startsWith(namespace.fullName)) {
      throw HTError.privateMember(id);
    }
    final func = decl;
    decl.resolve();
    return func.call();
  } else if (namespace.symbols.containsKey(constructor)) {
    final raw = namespace.symbols[constructor];
    if (raw == null) return null;
    if (raw is! HTDeclaration) return null;
    final decl = raw.value;
    if (decl is! HTFunction) return null;
    if (decl.isPrivate &&
        from != null &&
        !from.startsWith(namespace.fullName)) {
      throw HTError.privateMember(id);
    }
    decl.resolve();
    return decl;
  }
  // }

  if (!ignoreUndefined) {
    throw HTError.undefined(id,
        filename: interpreter.currentFile,
        line: interpreter.currentLine,
        column: interpreter.currentColumn);
  }
}