Skip to content

Commit 3567801

Browse files
Refactored LCEType and LCEValue types to constants
1 parent 93ef584 commit 3567801

File tree

10 files changed

+553
-275
lines changed

10 files changed

+553
-275
lines changed

typescript/src/core/concepts/type.concept.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ export abstract class LCEType extends LCEConcept {
1515
*/
1616
export class LCETypePrimitive extends LCEType {
1717
public static override conceptId = "primitive-type";
18+
public static readonly typeId = "primitive";
1819

19-
/**
20+
/**
2021
* @param name identifier of the primitive type
2122
*/
2223
constructor(public name: string) {
23-
super("primitive");
24+
super(LCETypePrimitive.typeId);
2425
}
2526
}
2627

@@ -29,13 +30,14 @@ export class LCETypePrimitive extends LCEType {
2930
*/
3031
export class LCETypeDeclared extends LCEType {
3132
public static override conceptId = "declared-type";
33+
public static readonly typeId = "declared";
3234

3335
/**
3436
* @param fqn fully qualified name of a class/interface/type alias (only uses global FQN)
3537
* @param typeArguments list of type arguments provided for generics
3638
*/
3739
constructor(public fqn: FQN, public typeArguments: LCEType[]) {
38-
super("declared");
40+
super(LCETypeDeclared.typeId);
3941
}
4042
}
4143

@@ -44,12 +46,13 @@ export class LCETypeDeclared extends LCEType {
4446
*/
4547
export class LCETypeUnion extends LCEType {
4648
public static override conceptId = "union-type";
49+
public static readonly typeId = "union";
4750

4851
/**
4952
* @param types constituents of the union type
5053
*/
5154
constructor(public types: LCEType[]) {
52-
super("union");
55+
super(LCETypeUnion.typeId);
5356
}
5457
}
5558

@@ -58,12 +61,13 @@ export class LCETypeUnion extends LCEType {
5861
*/
5962
export class LCETypeIntersection extends LCEType {
6063
public static override conceptId = "intersection-type";
64+
public static readonly typeId = "intersection";
6165

6266
/**
6367
* @param types constituents of the intersection type
6468
*/
6569
constructor(public types: LCEType[]) {
66-
super("intersection");
70+
super(LCETypeIntersection.typeId);
6771
}
6872
}
6973

@@ -72,12 +76,13 @@ export class LCETypeIntersection extends LCEType {
7276
*/
7377
export class LCETypeObject extends LCEType {
7478
public static override conceptId = "object-type";
79+
public static readonly typeId = "object";
7580

7681
/**
7782
* @param members members of the object type
7883
*/
7984
constructor(public members: LCETypeObjectMember[]) {
80-
super("object");
85+
super(LCETypeObject.typeId);
8186
}
8287
}
8388

@@ -106,6 +111,7 @@ export class LCETypeObjectMember extends LCEConcept {
106111
*/
107112
export class LCETypeFunction extends LCEType {
108113
public static override conceptId = "function-type";
114+
public static readonly typeId = "function";
109115

110116
/**
111117
* @param returnType return type of the function
@@ -116,7 +122,7 @@ export class LCETypeFunction extends LCEType {
116122
public parameters: LCETypeFunctionParameter[],
117123
public async: boolean,
118124
public typeParameters: LCETypeParameterDeclaration[]) {
119-
super("function");
125+
super(LCETypeFunction.typeId);
120126
}
121127
}
122128

@@ -142,12 +148,13 @@ export class LCETypeFunctionParameter extends LCEConcept {
142148
*/
143149
export class LCETypeParameterReference extends LCEType {
144150
public static override conceptId = "type-parameter";
151+
public static readonly typeId = "type-parameter";
145152

146153
/**
147154
* @param name name of the type parameter
148155
*/
149156
constructor(public name: string) {
150-
super("type-parameter");
157+
super(LCETypeParameterReference.typeId);
151158
}
152159
}
153160

@@ -156,12 +163,13 @@ export class LCETypeParameterReference extends LCEType {
156163
*/
157164
export class LCETypeLiteral extends LCEType {
158165
public static override conceptId = "literal-type";
166+
public static readonly typeId = "literal";
159167

160168
/**
161169
* @param value content of the type literal
162170
*/
163171
constructor(public value: string | number | boolean) {
164-
super("literal");
172+
super(LCETypeLiteral.typeId);
165173
}
166174
}
167175

@@ -170,12 +178,13 @@ export class LCETypeLiteral extends LCEType {
170178
*/
171179
export class LCETypeTuple extends LCEType {
172180
public static override conceptId = "tuple-type";
181+
public static readonly typeId = "tuple";
173182

174183
/**
175184
* @param types types of the tuple
176185
*/
177186
constructor(public types: LCEType[]) {
178-
super("tuple");
187+
super(LCETypeTuple.typeId);
179188
}
180189
}
181190

@@ -184,11 +193,12 @@ export class LCETypeTuple extends LCEType {
184193
*/
185194
export class LCETypeNotIdentified extends LCEType {
186195
public static override conceptId = "not-identified-type";
196+
public static readonly typeId = "not-identified";
187197

188198
/**
189199
* @param identifier string representation of type that could not successfully parsed
190200
*/
191201
constructor(public identifier: string) {
192-
super("not-identified");
202+
super(LCETypeNotIdentified.typeId);
193203
}
194204
}

typescript/src/core/concepts/value.concept.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ export abstract class LCEValue extends LCEConcept {
2222
*/
2323
export class LCEValueNull extends LCEValue {
2424
public static override conceptId = "null-value";
25+
public static readonly valueTypeId = "null";
26+
2527

2628
/**
2729
* @param kind indicates whether value is `undefined` or `null`
2830
*/
2931
constructor(public kind: "undefined" | "null") {
30-
super("null", new LCETypePrimitive(kind));
32+
super(LCEValueNull.valueTypeId, new LCETypePrimitive(kind));
3133
}
3234
}
3335

@@ -36,13 +38,14 @@ export class LCEValueNull extends LCEValue {
3638
*/
3739
export class LCEValueLiteral extends LCEValue {
3840
public static override conceptId = "literal-value";
41+
public static readonly valueTypeId = "literal";
3942

4043
/**
4144
* @param value the value of the literal
4245
*/
4346
constructor(public value: string | number | bigint | boolean | RegExp) {
4447
super(
45-
"literal",
48+
LCEValueLiteral.valueTypeId,
4649
typeof value === "object" ? new LCETypeDeclared(new FQN("RegExp"), []) : new LCETypePrimitive(typeof value)
4750
);
4851
}
@@ -53,12 +56,13 @@ export class LCEValueLiteral extends LCEValue {
5356
*/
5457
export class LCEValueDeclared extends LCEValue {
5558
public static override conceptId = "declared-value";
59+
public static readonly valueTypeId = "declared";
5660

5761
/**
5862
* @param fqn fully qualified name of the referenced variable/function/class (only global Fqn is used)
5963
*/
6064
constructor(type: LCEType, public fqn: FQN) {
61-
super("declared", type);
65+
super(LCEValueDeclared.valueTypeId, type);
6266
}
6367
}
6468

@@ -67,13 +71,14 @@ export class LCEValueDeclared extends LCEValue {
6771
*/
6872
export class LCEValueMember extends LCEValue {
6973
public static override conceptId = "member-value";
74+
public static readonly valueTypeId = "member";
7075

7176
/**
7277
* @param parent parent value of which a member is accessed
7378
* @param member member value which is accessed
7479
*/
7580
constructor(type: LCEType, public parent: LCEValue, public member: LCEValue) {
76-
super("member", type);
81+
super(LCEValueMember.valueTypeId, type);
7782
}
7883
}
7984

@@ -82,12 +87,13 @@ export class LCEValueMember extends LCEValue {
8287
*/
8388
export class LCEValueObject extends LCEValue {
8489
public static override conceptId = "object-value";
90+
public static readonly valueTypeId = "object";
8591

8692
/**
8793
* @param members map of the object member's names to their respective values
8894
*/
8995
constructor(type: LCEType, public members: Map<string, LCEValue>) {
90-
super("object", type);
96+
super(LCEValueObject.valueTypeId, type);
9197
}
9298
}
9399

@@ -97,13 +103,14 @@ export class LCEValueObject extends LCEValue {
97103
*/
98104
export class LCEValueObjectProperty extends LCEValue {
99105
public static override conceptId = "object-value-property";
106+
public static readonly valueTypeId = "object-property";
100107

101108
/**
102109
* @param name name of the property
103110
* @param value value of the property
104111
*/
105112
constructor(public name: string, public value: LCEValue) {
106-
super("object-property", value.type);
113+
super(LCEValueObjectProperty.valueTypeId, value.type);
107114
}
108115
}
109116

@@ -112,12 +119,13 @@ export class LCEValueObjectProperty extends LCEValue {
112119
*/
113120
export class LCEValueArray extends LCEValue {
114121
public static override conceptId = "array-value";
122+
public static readonly valueTypeId = "array";
115123

116124
/**
117125
* @param items item values of the array
118126
*/
119127
constructor(type: LCEType, public items: LCEValue[]) {
120-
super("array", type);
128+
super(LCEValueArray.valueTypeId, type);
121129
}
122130
}
123131

@@ -126,6 +134,7 @@ export class LCEValueArray extends LCEValue {
126134
*/
127135
export class LCEValueCall extends LCEValue {
128136
public static override conceptId = "call-value";
137+
public static readonly valueTypeId = "call";
129138

130139
/**
131140
* @param type return type of the call
@@ -134,7 +143,7 @@ export class LCEValueCall extends LCEValue {
134143
* @param typeArgs type arguments specified for call
135144
*/
136145
constructor(type: LCEType, public callee: LCEValue, public args: LCEValue[], public typeArgs: LCEType[]) {
137-
super("call", type);
146+
super(LCEValueCall.valueTypeId, type);
138147
}
139148
}
140149

@@ -143,13 +152,14 @@ export class LCEValueCall extends LCEValue {
143152
*/
144153
export class LCEValueFunction extends LCEValue {
145154
public static override conceptId = "function-value";
155+
public static readonly valueTypeId = "function";
146156

147157
/**
148158
* @param type return type of the function
149159
* @param arrowFunction indicates whether the function is an arrow function
150160
*/
151161
constructor(type: LCEType, public arrowFunction: boolean) {
152-
super("function", type);
162+
super(LCEValueFunction.valueTypeId, type);
153163
}
154164
}
155165

@@ -158,9 +168,10 @@ export class LCEValueFunction extends LCEValue {
158168
*/
159169
export class LCEValueClass extends LCEValue {
160170
public static override conceptId = "class-value";
171+
public static readonly valueTypeId = "class";
161172

162173
constructor() {
163-
super("class", new LCETypeNotIdentified("class expression"));
174+
super(LCEValueClass.valueTypeId, new LCETypeNotIdentified("class expression"));
164175
}
165176
}
166177

@@ -169,12 +180,13 @@ export class LCEValueClass extends LCEValue {
169180
*/
170181
export class LCEValueComplex extends LCEValue {
171182
public static override conceptId = "complex-value";
183+
public static readonly valueTypeId = "complex";
172184

173185
/**
174186
* @param expression string representation of the value's expression
175187
*/
176188
constructor(public expression: string) {
177-
super("complex", new LCETypeNotIdentified("complex"));
189+
super(LCEValueComplex.valueTypeId, new LCETypeNotIdentified("complex"));
178190
}
179191
}
180192

0 commit comments

Comments
 (0)