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)
?.definedType;
else if (identifier == RepresentationTypeIdentifier.TypedResource)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Unspecified)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Resource)
?.definedType;
else if (identifier == RepresentationTypeIdentifier.Enum)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Enum)

View File

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

View File

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

View File

@ -23,7 +23,11 @@ import 'ConstantTemplate.dart';
import 'TemplateType.dart';
class TypeTemplate {
late Guid _classId;
late bool _isWrapper;
bool get isWrapper => _isWrapper;
late Guid _classId;
Guid? _parentId = null;
String? _annotation;
@ -125,24 +129,18 @@ class TypeTemplate {
var instance = Warehouse.createInstance(type);
TemplateDescriber describer;
if (instance is DistributedResource) {
_templateType = TemplateType.Wrapper;
describer = instance.template;
} else if (instance is IResource) {
if (instance is IResource) {
_templateType = TemplateType.Resource;
describer = instance.template;
} else if (instance is IRecord) {
_templateType = TemplateType.Record;
describer = instance.template;
} else if (instance is IEnum) {
_templateType = TemplateType.Enum;
describer = instance.template;
} else
throw new Exception(
"Type must implement IResource, IRecord, IEnum or a subtype of DistributedResource.");
_isWrapper = (instance is DistributedResource);
// if (instance is IRecord)
// _templateType = TemplateType.Record;
// else if (instance is IResource)
@ -150,6 +148,8 @@ class TypeTemplate {
// else
// throw new Exception("Type is neither a resource nor a record.");
TemplateDescriber describer = instance.template;
_definedType = type;
_className = describer.nameSpace;
@ -199,53 +199,56 @@ class TypeTemplate {
}
}
if (describer.functions != null) {
var funcs = describer.functions as List<Func>;
if (_templateType == TemplateType.Resource) {
if (describer.functions != null) {
var funcs = describer.functions as List<Func>;
for (var i = 0; i < funcs.length; i++) {
var fi = funcs[i];
for (var i = 0; i < funcs.length; i++) {
var fi = funcs[i];
List<ArgumentTemplate> args = fi.args
.asMap()
.entries
.map((arg) => ArgumentTemplate(
arg.value.name,
RepresentationType.fromType(arg.value.type) ??
RepresentationType.Dynamic,
arg.value.optional,
arg.key))
.toList();
List<ArgumentTemplate> args = fi.args
.asMap()
.entries
.map((arg) => ArgumentTemplate(
arg.value.name,
RepresentationType.fromType(arg.value.type) ??
RepresentationType.Dynamic,
arg.value.optional,
arg.key))
.toList();
var ft = FunctionTemplate(
this,
i,
fi.name,
false,
fi.isStatic,
args,
RepresentationType.fromType(fi.returnType) ??
RepresentationType.Void,
fi.annotation);
var ft = FunctionTemplate(
this,
i,
fi.name,
false,
fi.isStatic,
args,
RepresentationType.fromType(fi.returnType) ??
RepresentationType.Void,
fi.annotation);
functions.add(ft);
functions.add(ft);
}
}
}
if (describer.events != null) {
var evts = describer.events as List<Evt>;
for (var i = 0; i < evts.length; i++) {
var ei = evts[i];
if (describer.events != null) {
var evts = describer.events as List<Evt>;
for (var i = 0; i < evts.length; i++) {
var ei = evts[i];
var et = new EventTemplate(
this,
i,
ei.name,
false,
RepresentationType.fromType(ei.type) ?? RepresentationType.Dynamic,
ei.annotation,
ei.listenable);
var et = new EventTemplate(
this,
i,
ei.name,
false,
RepresentationType.fromType(ei.type) ??
RepresentationType.Dynamic,
ei.annotation,
ei.listenable);
events.add(et);
events.add(et);
}
}
}

View File

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