2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2025-05-06 12:02:57 +00:00

TemplateType.Wrapper Removed

This commit is contained in:
Esiur Project 2022-09-06 23:27:02 +03:00
parent e864b1914a
commit 8c7a55d93c
5 changed files with 71 additions and 73 deletions

View File

@ -167,7 +167,7 @@ class RepresentationType {
return Warehouse.getTemplateByClassId(guid!, TemplateType.Record) return Warehouse.getTemplateByClassId(guid!, TemplateType.Record)
?.definedType; ?.definedType;
else if (identifier == RepresentationTypeIdentifier.TypedResource) else if (identifier == RepresentationTypeIdentifier.TypedResource)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Unspecified) return Warehouse.getTemplateByClassId(guid!, TemplateType.Resource)
?.definedType; ?.definedType;
else if (identifier == RepresentationTypeIdentifier.Enum) else if (identifier == RepresentationTypeIdentifier.Enum)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Enum) return Warehouse.getTemplateByClassId(guid!, TemplateType.Enum)

View File

@ -147,8 +147,7 @@ class TemplateGenerator {
name = _translateClassName(templates name = _translateClassName(templates
.singleWhere((x) => .singleWhere((x) =>
x.classId == representationType.guid && x.classId == representationType.guid &&
(x.type == TemplateType.Resource || (x.type == TemplateType.Resource))
x.type == TemplateType.Wrapper))
.className); .className);
} else if (representationType.identifier == } else if (representationType.identifier ==
RepresentationTypeIdentifier.TypedRecord) { RepresentationTypeIdentifier.TypedRecord) {
@ -345,8 +344,7 @@ class TemplateGenerator {
var defineCreators = templates.map((tmp) { var defineCreators = templates.map((tmp) {
// creator // creator
var className = _translateClassName(tmp.className); var className = _translateClassName(tmp.className);
if (tmp.type == TemplateType.Resource || if (tmp.type == TemplateType.Resource) {
tmp.type == TemplateType.Wrapper) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.parse('${tmp.classId.toString()}')));\r\n"; return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.parse('${tmp.classId.toString()}')));\r\n";
} else if (tmp.type == TemplateType.Record) { } else if (tmp.type == TemplateType.Record) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.parse('${tmp.classId.toString()}')));\r\n"; return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.parse('${tmp.classId.toString()}')));\r\n";
@ -429,8 +427,7 @@ class TemplateGenerator {
parentName = _translateClassName(templates parentName = _translateClassName(templates
.singleWhere((x) => .singleWhere((x) =>
(x.classId == template.parentId) && (x.classId == template.parentId) &&
(x.type == TemplateType.Resource || (x.type == TemplateType.Resource))
x.type == TemplateType.Wrapper))
.className); .className);
rt.writeln("class ${className} extends ${parentName} {"); rt.writeln("class ${className} extends ${parentName} {");
} else { } else {

View File

@ -1,7 +1,5 @@
enum TemplateType { enum TemplateType {
Unspecified,
Resource, Resource,
Record, Record,
Wrapper,
Enum Enum
} }

View File

@ -23,6 +23,10 @@ import 'ConstantTemplate.dart';
import 'TemplateType.dart'; import 'TemplateType.dart';
class TypeTemplate { class TypeTemplate {
late bool _isWrapper;
bool get isWrapper => _isWrapper;
late Guid _classId; late Guid _classId;
Guid? _parentId = null; Guid? _parentId = null;
@ -125,24 +129,18 @@ class TypeTemplate {
var instance = Warehouse.createInstance(type); var instance = Warehouse.createInstance(type);
TemplateDescriber describer; if (instance is IResource) {
if (instance is DistributedResource) {
_templateType = TemplateType.Wrapper;
describer = instance.template;
} else if (instance is IResource) {
_templateType = TemplateType.Resource; _templateType = TemplateType.Resource;
describer = instance.template;
} else if (instance is IRecord) { } else if (instance is IRecord) {
_templateType = TemplateType.Record; _templateType = TemplateType.Record;
describer = instance.template;
} else if (instance is IEnum) { } else if (instance is IEnum) {
_templateType = TemplateType.Enum; _templateType = TemplateType.Enum;
describer = instance.template;
} else } else
throw new Exception( throw new Exception(
"Type must implement IResource, IRecord, IEnum or a subtype of DistributedResource."); "Type must implement IResource, IRecord, IEnum or a subtype of DistributedResource.");
_isWrapper = (instance is DistributedResource);
// if (instance is IRecord) // if (instance is IRecord)
// _templateType = TemplateType.Record; // _templateType = TemplateType.Record;
// else if (instance is IResource) // else if (instance is IResource)
@ -150,6 +148,8 @@ class TypeTemplate {
// else // else
// throw new Exception("Type is neither a resource nor a record."); // throw new Exception("Type is neither a resource nor a record.");
TemplateDescriber describer = instance.template;
_definedType = type; _definedType = type;
_className = describer.nameSpace; _className = describer.nameSpace;
@ -199,6 +199,7 @@ class TypeTemplate {
} }
} }
if (_templateType == TemplateType.Resource) {
if (describer.functions != null) { if (describer.functions != null) {
var funcs = describer.functions as List<Func>; var funcs = describer.functions as List<Func>;
@ -241,13 +242,15 @@ class TypeTemplate {
i, i,
ei.name, ei.name,
false, false,
RepresentationType.fromType(ei.type) ?? RepresentationType.Dynamic, RepresentationType.fromType(ei.type) ??
RepresentationType.Dynamic,
ei.annotation, ei.annotation,
ei.listenable); ei.listenable);
events.add(et); events.add(et);
} }
} }
}
// append signals // append signals
events.forEach(_members.add); events.forEach(_members.add);

View File

@ -22,7 +22,6 @@ SOFTWARE.
*/ */
import '../Data/IntType.dart'; import '../Data/IntType.dart';
import '../Data/TransmissionType.dart'; import '../Data/TransmissionType.dart';
@ -66,10 +65,8 @@ class Warehouse {
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _initTemplates() { static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _initTemplates() {
var rt = new KeyList<TemplateType, KeyList<Guid, TypeTemplate>>(); var rt = new KeyList<TemplateType, KeyList<Guid, TypeTemplate>>();
rt.add(TemplateType.Unspecified, new KeyList<Guid, TypeTemplate>());
rt.add(TemplateType.Resource, new KeyList<Guid, TypeTemplate>()); rt.add(TemplateType.Resource, new KeyList<Guid, TypeTemplate>());
rt.add(TemplateType.Record, new KeyList<Guid, TypeTemplate>()); rt.add(TemplateType.Record, new KeyList<Guid, TypeTemplate>());
rt.add(TemplateType.Wrapper, new KeyList<Guid, TypeTemplate>());
rt.add(TemplateType.Enum, new KeyList<Guid, TypeTemplate>()); rt.add(TemplateType.Enum, new KeyList<Guid, TypeTemplate>());
return rt; return rt;
@ -561,6 +558,9 @@ class Warehouse {
/// </summary> /// </summary>
/// <param name="template">Resource template.</param> /// <param name="template">Resource template.</param>
static void putTemplate(TypeTemplate template) { static void putTemplate(TypeTemplate template) {
if (_templates[template.type]?.containsKey(template.classId) ?? false)
throw Exception("Template with same class Id already exists.");
_templates[template.type]?[template.classId] = template; _templates[template.type]?[template.classId] = template;
} }
@ -588,18 +588,18 @@ class Warehouse {
/// <param name="classId">Class Id.</param> /// <param name="classId">Class Id.</param>
/// <returns>Resource template.</returns> /// <returns>Resource template.</returns>
static TypeTemplate? getTemplateByClassId(Guid classId, static TypeTemplate? getTemplateByClassId(Guid classId,
[TemplateType templateType = TemplateType.Unspecified]) { [TemplateType? templateType = null]) {
if (templateType == TemplateType.Unspecified) { if (templateType == null) {
// look in resources // look into resources
var template = _templates[TemplateType.Resource]?[classId]; var template = _templates[TemplateType.Resource]?[classId];
if (template != null) return template; if (template != null) return template;
// look in records // look into records
template = _templates[TemplateType.Record]?[classId]; template = _templates[TemplateType.Record]?[classId];
if (template != null) return template; if (template != null) return template;
// look in wrappers // look into enums
template = _templates[TemplateType.Wrapper]?[classId]; template = _templates[TemplateType.Enum]?[classId];
return template; return template;
} else { } else {
return _templates[templateType]?[classId]; return _templates[templateType]?[classId];
@ -612,22 +612,22 @@ class Warehouse {
/// <param name="className">Class name.</param> /// <param name="className">Class name.</param>
/// <returns>Resource template.</returns> /// <returns>Resource template.</returns>
static TypeTemplate? getTemplateByClassName(String className, static TypeTemplate? getTemplateByClassName(String className,
[TemplateType templateType = TemplateType.Unspecified]) { [TemplateType? templateType = null]) {
if (templateType == TemplateType.Unspecified) { if (templateType == null) {
// look in resources // look into resources
var template = _templates[TemplateType.Resource] var template = _templates[TemplateType.Resource]
?.values ?.values
.firstWhere((x) => x.className == className); .firstWhere((x) => x.className == className);
if (template != null) return template; if (template != null) return template;
// look in records // look into records
template = _templates[TemplateType.Record] template = _templates[TemplateType.Record]
?.values ?.values
.firstWhere((x) => x.className == className); .firstWhere((x) => x.className == className);
if (template != null) return template; if (template != null) return template;
// look in wrappers // look into wrappers
template = _templates[TemplateType.Wrapper] template = _templates[TemplateType.Enum]
?.values ?.values
.firstWhere((x) => x.className == className); .firstWhere((x) => x.className == className);
return template; return template;