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:
parent
e864b1914a
commit
8c7a55d93c
@ -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)
|
||||||
|
@ -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 {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
enum TemplateType {
|
enum TemplateType {
|
||||||
Unspecified,
|
|
||||||
Resource,
|
Resource,
|
||||||
Record,
|
Record,
|
||||||
Wrapper,
|
|
||||||
Enum
|
Enum
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,11 @@ import 'ConstantTemplate.dart';
|
|||||||
import 'TemplateType.dart';
|
import 'TemplateType.dart';
|
||||||
|
|
||||||
class TypeTemplate {
|
class TypeTemplate {
|
||||||
late Guid _classId;
|
late bool _isWrapper;
|
||||||
|
|
||||||
|
bool get isWrapper => _isWrapper;
|
||||||
|
|
||||||
|
late Guid _classId;
|
||||||
Guid? _parentId = null;
|
Guid? _parentId = null;
|
||||||
|
|
||||||
String? _annotation;
|
String? _annotation;
|
||||||
@ -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,53 +199,56 @@ class TypeTemplate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (describer.functions != null) {
|
if (_templateType == TemplateType.Resource) {
|
||||||
var funcs = describer.functions as List<Func>;
|
if (describer.functions != null) {
|
||||||
|
var funcs = describer.functions as List<Func>;
|
||||||
|
|
||||||
for (var i = 0; i < funcs.length; i++) {
|
for (var i = 0; i < funcs.length; i++) {
|
||||||
var fi = funcs[i];
|
var fi = funcs[i];
|
||||||
|
|
||||||
List<ArgumentTemplate> args = fi.args
|
List<ArgumentTemplate> args = fi.args
|
||||||
.asMap()
|
.asMap()
|
||||||
.entries
|
.entries
|
||||||
.map((arg) => ArgumentTemplate(
|
.map((arg) => ArgumentTemplate(
|
||||||
arg.value.name,
|
arg.value.name,
|
||||||
RepresentationType.fromType(arg.value.type) ??
|
RepresentationType.fromType(arg.value.type) ??
|
||||||
RepresentationType.Dynamic,
|
RepresentationType.Dynamic,
|
||||||
arg.value.optional,
|
arg.value.optional,
|
||||||
arg.key))
|
arg.key))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
var ft = FunctionTemplate(
|
var ft = FunctionTemplate(
|
||||||
this,
|
this,
|
||||||
i,
|
i,
|
||||||
fi.name,
|
fi.name,
|
||||||
false,
|
false,
|
||||||
fi.isStatic,
|
fi.isStatic,
|
||||||
args,
|
args,
|
||||||
RepresentationType.fromType(fi.returnType) ??
|
RepresentationType.fromType(fi.returnType) ??
|
||||||
RepresentationType.Void,
|
RepresentationType.Void,
|
||||||
fi.annotation);
|
fi.annotation);
|
||||||
|
|
||||||
functions.add(ft);
|
functions.add(ft);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (describer.events != null) {
|
if (describer.events != null) {
|
||||||
var evts = describer.events as List<Evt>;
|
var evts = describer.events as List<Evt>;
|
||||||
for (var i = 0; i < evts.length; i++) {
|
for (var i = 0; i < evts.length; i++) {
|
||||||
var ei = evts[i];
|
var ei = evts[i];
|
||||||
|
|
||||||
var et = new EventTemplate(
|
var et = new EventTemplate(
|
||||||
this,
|
this,
|
||||||
i,
|
i,
|
||||||
ei.name,
|
ei.name,
|
||||||
false,
|
false,
|
||||||
RepresentationType.fromType(ei.type) ?? RepresentationType.Dynamic,
|
RepresentationType.fromType(ei.type) ??
|
||||||
ei.annotation,
|
RepresentationType.Dynamic,
|
||||||
ei.listenable);
|
ei.annotation,
|
||||||
|
ei.listenable);
|
||||||
|
|
||||||
events.add(et);
|
events.add(et);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user