From 7deda2aef5f947e85697d647ac5a215b603248e9 Mon Sep 17 00:00:00 2001 From: Shumilov Petr Date: Tue, 15 Nov 2022 13:54:46 +0300 Subject: [PATCH] Add basic type API design Signed-off-by: Shumilov Petr --- plugins/ets/stdlib/std/core/Object.ets | 7 ++- plugins/ets/stdlib/std/core/Types.ets | 77 +++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/plugins/ets/stdlib/std/core/Object.ets b/plugins/ets/stdlib/std/core/Object.ets index baba94742..20e7084f0 100644 --- a/plugins/ets/stdlib/std/core/Object.ets +++ b/plugins/ets/stdlib/std/core/Object.ets @@ -22,8 +22,11 @@ export open class Object { // String representation of the object public open toString(): String { - return ""; - // return types.getType(this).toString(); + let sb: StringBuilder = new StringBuilder(); + sb.append(types.getType(this).getName()); + sb.append("@"); + sb.append(hashCode()); // TODO: replace to Int.toHexString(hashCode()) + return sb.toString(); } // Hash code value for the object diff --git a/plugins/ets/stdlib/std/core/Types.ets b/plugins/ets/stdlib/std/core/Types.ets index 2bc6145db..eca108fd3 100644 --- a/plugins/ets/stdlib/std/core/Types.ets +++ b/plugins/ets/stdlib/std/core/Types.ets @@ -15,12 +15,83 @@ package std.core; -class Type { +open class Type { + public open toString() : String { + return ""; + } + + public getName(): String { + return ""; + } + + public static getFromName(className : String) : Type { + return new Type(); + } + + public getSuperClass() : Type { + return new Type(); + } + + public getInterfaces() : Type[] { + return []; + } + + public getNestedTypes() : Type[] { + return []; + } + + public getPackage() : Package { + return new Package(); + } + + public getFields() : Field[] { + return []; + } + + public getMethods() : Method[] { + return []; + } + + public getConstructors() : Constructor[] { + return []; + } + + public native isAssignableFrom(t : Type) : boolean + + public native isInterface() : boolean + + public native isArray() : boolean + + public native isPrimitive() : boolean + + public native isEnum(): boolean + + public getGenericTypeParameters() : Type[] { + return []; + } + +} + +class Field { + +} + +class Package { + +} + +class Constructor { + +} + +class Method { } class Types { - // getType(o: Object): Type {} + public static getType(o: Object): Type { + return new Type(); + } } -export const types = new Types(); +export const types = new Types(); \ No newline at end of file -- Gitee