-
Notifications
You must be signed in to change notification settings - Fork 551
Expand file tree
/
Copy pathCdmArgumentDefinition.ts
More file actions
179 lines (157 loc) · 4.95 KB
/
CdmArgumentDefinition.ts
File metadata and controls
179 lines (157 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { isString } from 'util';
import {
ArgumentValue,
CdmCorpusContext,
CdmObject,
CdmObjectBase,
cdmObjectSimple,
cdmObjectType,
CdmParameterDefinition,
cdmLogCode,
Logger,
resolveOptions,
VisitCallback,
StringUtils
} from '../internal';
export class CdmArgumentDefinition extends cdmObjectSimple {
private TAG: string = CdmArgumentDefinition.name;
public explanation: string;
public name: string;
public value: ArgumentValue;
/**
* @internal
*/
public unresolvedValue: ArgumentValue;
/**
* @internal
*/
public resolvedParameter: CdmParameterDefinition;
public static get objectType(): cdmObjectType {
return cdmObjectType.argumentDef;
}
constructor(ctx: CdmCorpusContext, name: string) {
super(ctx);
// let bodyCode = () =>
{
this.objectType = cdmObjectType.argumentDef;
this.name = name;
}
// return p.measure(bodyCode);
}
public getObjectType(): cdmObjectType {
// let bodyCode = () =>
{
return cdmObjectType.argumentDef;
}
// return p.measure(bodyCode);
}
public copy(resOpt?: resolveOptions, host?: CdmObject): CdmArgumentDefinition {
// let bodyCode = () =>
{
if (!resOpt) {
resOpt = new resolveOptions(this, this.ctx.corpus.defaultResolutionDirectives);
}
let copy: CdmArgumentDefinition;
if (!host) {
copy = new CdmArgumentDefinition(this.ctx, this.name);
} else {
copy = host as CdmArgumentDefinition;
copy.ctx = this.ctx;
copy.name = this.name;
}
if (this.value) {
if (this.value instanceof CdmObjectBase) {
copy.value = (this.value as CdmObject).copy(resOpt);
} else {
// Value is a string or object
copy.value = this.value;
}
}
copy.resolvedParameter = this.resolvedParameter;
copy.explanation = this.explanation;
return copy;
}
// return p.measure(bodyCode);
}
public validate(): boolean {
// let bodyCode = () =>
{
if (this.value === null || this.value === undefined || this.value === NaN) {
let missingFields: string[] = ['value'];
Logger.error(this.ctx, this.TAG, this.validate.name, this.atCorpusPath, cdmLogCode.ErrValdnIntegrityCheckFailure, missingFields.map((s: string) => `'${s}'`).join(', '), this.atCorpusPath);
return false;
}
return true;
}
// return p.measure(bodyCode);
}
public getExplanation(): string {
// let bodyCode = () =>
{
return this.explanation;
}
// return p.measure(bodyCode);
}
public setExplanation(explanation: string): string {
// let bodyCode = () =>
{
this.explanation = explanation;
return this.explanation;
}
// return p.measure(bodyCode);
}
public getValue(): ArgumentValue {
// let bodyCode = () =>
{
return this.value;
}
// return p.measure(bodyCode);
}
public setValue(value: ArgumentValue): void {
// let bodyCode = () =>
{
this.value = value;
}
// return p.measure(bodyCode);
}
public getName(): string {
// let bodyCode = () =>
{
return this.name;
}
// return p.measure(bodyCode);
}
/**
* @internal
*/
public getParameterDef(): CdmParameterDefinition {
// let bodyCode = () =>
{
return this.resolvedParameter;
}
// return p.measure(bodyCode);
}
public visit(pathFrom: string, preChildren: VisitCallback, postChildren: VisitCallback): boolean {
// let bodyCode = () =>
{
const path: string = pathFrom; // name of arg is forced down from trait ref. you get what you get and you don't throw a fit.
if (preChildren && preChildren(this, path)) {
return false;
}
if (this.value !== undefined) {
if (typeof (this.value) === 'object' && 'visit' in this.value && typeof (this.value.visit) === 'function') {
if (this.value.visit(`${path}/value/`, preChildren, postChildren)) {
return true;
}
}
}
if (postChildren && postChildren(this, path)) {
return true;
}
return false;
}
// return p.measure(bodyCode);
}
}