diff --git a/packages/concerto-core/api.txt b/packages/concerto-core/api.txt index 5cd60f630e..136c4444fb 100644 --- a/packages/concerto-core/api.txt +++ b/packages/concerto-core/api.txt @@ -32,19 +32,14 @@ class Factory { + Relationship newRelationship(String,String,String) throws TypeNotFoundException + Resource newTransaction(String,String,String,Object,String,boolean) + Resource newEvent(String,String,String,Object,String,boolean) - + boolean hasInstance(object) } class AssetDeclaration extends IdentifiedDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException - + boolean hasInstance(object) } class ClassDeclaration extends Decorated { + void constructor(ModelFile,Object) throws IllegalModelException + ClassDeclaration _resolveSuperType() + boolean isAbstract() - + boolean isEnum() - + boolean isConcept() - + boolean isEvent() + string getName() + string getNamespace() + string getFullyQualifiedName() @@ -62,12 +57,16 @@ class ClassDeclaration extends Decorated { + Property[] getProperties() + Property getNestedProperty(string) throws IllegalModelException + String toString() - + boolean hasInstance(object) + + boolean isAsset() + + boolean isParticipant() + + boolean isTransaction() + + boolean isEvent() + + boolean isConcept() + + boolean isEnum() + + boolean isClassDeclaration() } class ConceptDeclaration extends ClassDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException - + boolean isConcept() - + boolean hasInstance(object) } class Decorator { + void constructor(Object) throws IllegalModelException @@ -80,22 +79,17 @@ class DecoratorFactory { } class EnumDeclaration extends ClassDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException - + boolean isEnum() + String toString() - + boolean hasInstance(object) } class EnumValueDeclaration extends Property { + void constructor(ClassDeclaration,Object) throws IllegalModelException - + boolean hasInstance(object) + + boolean isEnumValue() } class EventDeclaration extends IdentifiedDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException - + boolean isEvent() - + boolean hasInstance(object) } class IdentifiedDeclaration extends ClassDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException - + boolean hasInstance(object) } class IllegalModelException extends BaseFileException { + void constructor(string,ModelFile,Object,number,number,number,number,string) @@ -110,37 +104,36 @@ class ModelFileDownloader { + Promise downloadExternalDependencies(ModelFile[],Object) + Promise runJob(Object,Object) } -class MetaModel { + void createMetaModelManager() - + object validateMetaModel(object) - + object createNameTable(object) - + string resolveName(string,object) - + object resolveTypeNames(object,object) - + object resolveMetaModel(object,object) - + object enumPropertyToMetaModel(object) - + object decoratorArgToMetaModel(object) - + object decoratorToMetaModel(object) - + object decoratorsToMetaModel(object) - + object propertyToMetaModel(object) - + object relationshipToMetaModel(object) - + object enumDeclToMetaModel(object) - + object conceptDeclToMetaModel(object) - + object declToMetaModel(object) - + object modelToMetaModel(object,boolean) - + object modelFileToMetaModel(object,boolean) - + object modelManagerToMetaModel(object,boolean,boolean) - + string decoratorArgFromMetaModel(object) - + string decoratorFromMetaModel(object) - + string decoratorsFromMetaModel(object,string) - + string propertyFromMetaModel(object) - + string declFromMetaModel(object) - + string ctoFromMetaModel(object,boolean) - + object modelManagerFromMetaModel(object,boolean) - + object ctoToMetaModel(string,boolean) - + object ctoToMetaModelAndResolve(string,boolean) -} + + object validateMetaModel() + + object createNameTable() + + string resolveName() + + object resolveTypeNames() + + object resolveMetaModel() + + object enumPropertyToMetaModel() + + object decoratorArgToMetaModel() + + object decoratorToMetaModel() + + object decoratorsToMetaModel() + + object propertyToMetaModel() + + object relationshipToMetaModel() + + object enumDeclToMetaModel() + + object conceptDeclToMetaModel() + + object declToMetaModel() + + object modelToMetaModel() + + object modelFileToMetaModel() + + object modelManagerToMetaModel() + + string decoratorArgFromMetaModel() + + string decoratorFromMetaModel() + + string decoratorsFromMetaModel() + + string propertyFromMetaModel() + + string declFromMetaModel() + + string ctoFromMetaModel() + + object modelManagerFromMetaModel() + + object ctoToMetaModel() + + object ctoToMetaModelAndResolve() class ModelFile { + void constructor(ModelManager,string,string) throws IllegalModelException + + boolean isModelFile() + Boolean isSystemModelFile() + boolean isExternal() + ModelManager getModelManager() @@ -164,11 +157,9 @@ class ModelFile { + string getDefinitions() + string getConcertoVersion() + void isCompatibleVersion() - + boolean hasInstance(object) } class ParticipantDeclaration extends IdentifiedDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException - + boolean hasInstance(object) } class Property extends Decorated { + void constructor(ClassDeclaration,Object) throws IllegalModelException @@ -182,16 +173,14 @@ class Property extends Decorated { + boolean isArray() + boolean isTypeEnum() + boolean isPrimitive() - + boolean hasInstance(object) } class RelationshipDeclaration extends Property { + void constructor(ClassDeclaration,Object) throws IllegalModelException + String toString() - + boolean hasInstance(object) + + boolean isRelationship() } class TransactionDeclaration extends IdentifiedDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException - + boolean hasInstance(object) } class Identifiable extends Typed { + string getTimestamp() @@ -234,6 +223,7 @@ class ModelLoader { } class ModelManager { + void constructor(object) + + boolean isModelManager() + Object accept(Object,Object) + void validateModelFile(string,string) throws IllegalModelException + Object addModelFile(string,string,boolean) throws IllegalModelException @@ -258,7 +248,6 @@ class ModelManager { + DecoratorFactory[] getDecoratorFactories() + void addDecoratorFactory(DecoratorFactory) + boolean derivesFrom(string,string) - + boolean hasInstance(object) } class SecurityException extends BaseException { + void constructor(string) @@ -268,7 +257,6 @@ class Serializer { + void setDefaultOptions(Object) + Object toJSON(Resource,Object,boolean,boolean,boolean,boolean,boolean,number) throws Error + Resource fromJSON(Object,Object,boolean,boolean,number) - + boolean hasInstance(object) } class TypedStack { + void constructor(Object) diff --git a/packages/concerto-core/changelog.txt b/packages/concerto-core/changelog.txt index f14de6c6de..76258da36a 100644 --- a/packages/concerto-core/changelog.txt +++ b/packages/concerto-core/changelog.txt @@ -24,6 +24,9 @@ # Note that the latest public API is documented using JSDocs and is available in api.txt. # +Version 1.2.2 {a7ba5a1d93717527babdda88941e459f} 2021-11-22 +- Remove custom instanceof and add methods to check runtime type + Version 1.2.2 {8149560555027394c95a893c1e442d67} 2021-11-15 - Convert MetaModel to a class for Typescript + Webpack compatability - Update Acorn to latest and refactor the JavaScript parser so we can use static class members diff --git a/packages/concerto-core/lib/factory.js b/packages/concerto-core/lib/factory.js index b025656566..a5b8291ca4 100644 --- a/packages/concerto-core/lib/factory.js +++ b/packages/concerto-core/lib/factory.js @@ -28,9 +28,6 @@ const Relationship = require('./model/relationship'); const Resource = require('./model/resource'); const ValidatedResource = require('./model/validatedresource'); -const TransactionDeclaration = require('./introspect/transactiondeclaration'); -const EventDeclaration = require('./introspect/eventdeclaration'); - const uuid = require('uuid'); const dayjs = require('dayjs'); @@ -60,7 +57,6 @@ class Factory { */ constructor(modelManager) { this.modelManager = modelManager; - this._isFactory = true; } /** @@ -120,7 +116,7 @@ class Factory { let newObj = null; let timestamp = null; - if (classDecl instanceof TransactionDeclaration || classDecl instanceof EventDeclaration) { + if (classDecl.isTransaction() || classDecl.isEvent()) { timestamp = dayjs.utc(); } if(options.disableValidation) { @@ -206,7 +202,7 @@ class Factory { let transaction = this.newResource(ns, type, id, options); const classDeclaration = transaction.getClassDeclaration(); - if (!(classDeclaration instanceof TransactionDeclaration)) { + if (!classDeclaration.isTransaction()) { throw new Error(transaction.getClassDeclaration().getFullyQualifiedName() + ' is not a transaction'); } @@ -236,7 +232,7 @@ class Factory { let event = this.newResource(ns, type, id, options); const classDeclaration = event.getClassDeclaration(); - if (!(classDeclaration instanceof EventDeclaration)) { + if (!classDeclaration.isEvent()) { throw new Error(event.getClassDeclaration().getFullyQualifiedName() + ' is not an event'); } @@ -291,18 +287,6 @@ class Factory { return generateParams; } - - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a Factory - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isFactory); - } } module.exports = Factory; diff --git a/packages/concerto-core/lib/introspect/assetdeclaration.js b/packages/concerto-core/lib/introspect/assetdeclaration.js index 140441e8b3..07ca15f71d 100644 --- a/packages/concerto-core/lib/introspect/assetdeclaration.js +++ b/packages/concerto-core/lib/introspect/assetdeclaration.js @@ -36,18 +36,6 @@ class AssetDeclaration extends IdentifiedDeclaration { */ constructor(modelFile, ast) { super(modelFile, ast); - this._isAssetDeclaration = true; - } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a AssetDeclaration - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isAssetDeclaration); } } diff --git a/packages/concerto-core/lib/introspect/classdeclaration.js b/packages/concerto-core/lib/introspect/classdeclaration.js index 44ed756524..8251a10cd1 100644 --- a/packages/concerto-core/lib/introspect/classdeclaration.js +++ b/packages/concerto-core/lib/introspect/classdeclaration.js @@ -65,6 +65,7 @@ class ClassDeclaration extends Decorated { this.idField = null; this.timestamped = false; this.abstract = false; + this.type = this.ast.type; if (this.ast.abstract) { this.abstract = true; @@ -107,7 +108,6 @@ class ClassDeclaration extends Decorated { } this.fqn = ModelUtil.getFullyQualifiedName(this.modelFile.getNamespace(), this.name); - this._isClassDeclaration = true; if (this.fqn === 'concerto.Transaction' || this.fqn === 'concerto.Event') { this.addTimestampField(); @@ -283,33 +283,6 @@ class ClassDeclaration extends Decorated { return this.abstract; } - /** - * Returns true if this class is an enumeration. - * - * @return {boolean} true if the class is an enumerated type - */ - isEnum() { - return false; - } - - /** - * Returns true if this class is the definition of a concept. - * - * @return {boolean} true if the class is a concept - */ - isConcept() { - return false; - } - - /** - * Returns true if this class is the definition of an event. - * - * @return {boolean} true if the class is an event - */ - isEvent() { - return false; - } - /** * Returns the short name of a class. This name does not include the * namespace from the owning ModelFile. @@ -602,16 +575,67 @@ class ClassDeclaration extends Decorated { } /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 + * Returns true if this class is the definition of an asset. + * + * @return {boolean} true if the class is an asset + */ + isAsset() { + return this.type === 'AssetDeclaration'; + } + + /** + * Returns true if this class is the definition of a participant. + * + * @return {boolean} true if the class is an asset + */ + isParticipant() { + return this.type === 'ParticipantDeclaration'; + } + + /** + * Returns true if this class is the definition of a transaction. + * + * @return {boolean} true if the class is an asset + */ + isTransaction() { + return this.type === 'TransactionDeclaration'; + } + + /** + * Returns true if this class is the definition of an event. * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a Class Declaration + * @return {boolean} true if the class is an asset */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isClassDeclaration); + isEvent() { + return this.type === 'EventDeclaration'; } + /** + * Returns true if this class is the definition of a concept. + * + * @return {boolean} true if the class is an asset + */ + isConcept() { + return this.type === 'ConceptDeclaration'; + } + + /** + * Returns true if this class is the definition of a enum. + * + * @return {boolean} true if the class is an asset + */ + isEnum() { + return this.type === 'EnumDeclaration'; + } + + /** + * Returns true if this class is the definition of a enum. + * + * @return {boolean} true if the class is an asset + */ + isClassDeclaration() { + return true; + } } module.exports = ClassDeclaration; diff --git a/packages/concerto-core/lib/introspect/conceptdeclaration.js b/packages/concerto-core/lib/introspect/conceptdeclaration.js index 931df55c2e..d00c1b444b 100644 --- a/packages/concerto-core/lib/introspect/conceptdeclaration.js +++ b/packages/concerto-core/lib/introspect/conceptdeclaration.js @@ -36,27 +36,6 @@ class ConceptDeclaration extends ClassDeclaration { */ constructor(modelFile, ast) { super(modelFile, ast); - this._isConceptDeclaration = true; - } - - /** - * Returns true if this class is the definition of a concept. - * - * @return {boolean} true if the class is a concept - */ - isConcept() { - return true; - } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a ConceptDeclaration - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isConceptDeclaration); } } diff --git a/packages/concerto-core/lib/introspect/enumdeclaration.js b/packages/concerto-core/lib/introspect/enumdeclaration.js index 614470a1d6..9a3eb045ae 100644 --- a/packages/concerto-core/lib/introspect/enumdeclaration.js +++ b/packages/concerto-core/lib/introspect/enumdeclaration.js @@ -33,16 +33,6 @@ class EnumDeclaration extends ClassDeclaration { */ constructor(modelFile, ast) { super(modelFile, ast); - this._isEnumDeclaration = true; - } - - /** - * Returns true if this class is an enumeration. - * - * @return {boolean} true if the class is an enumerated type - */ - isEnum() { - return true; } /** @@ -52,17 +42,6 @@ class EnumDeclaration extends ClassDeclaration { toString() { return 'EnumDeclaration {id=' + this.getFullyQualifiedName() + '}'; } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a Class Declaration - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isEnumDeclaration); - } } module.exports = EnumDeclaration; diff --git a/packages/concerto-core/lib/introspect/enumvaluedeclaration.js b/packages/concerto-core/lib/introspect/enumvaluedeclaration.js index 432aee90ee..a1a58d36f4 100644 --- a/packages/concerto-core/lib/introspect/enumvaluedeclaration.js +++ b/packages/concerto-core/lib/introspect/enumvaluedeclaration.js @@ -33,7 +33,6 @@ class EnumValueDeclaration extends Property { */ constructor(parent, ast) { super(parent, ast); - this._isEnumValueDeclaration = true; } /** @@ -47,14 +46,12 @@ class EnumValueDeclaration extends Property { } /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 + * Returns true if this class is the definition of a enum value. * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a EnumValueDeclaration + * @return {boolean} true if the class is an enum value */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isEnumValueDeclaration); + isEnumValue() { + return true; } } diff --git a/packages/concerto-core/lib/introspect/eventdeclaration.js b/packages/concerto-core/lib/introspect/eventdeclaration.js index 67db7bc655..6ab9a3ed36 100644 --- a/packages/concerto-core/lib/introspect/eventdeclaration.js +++ b/packages/concerto-core/lib/introspect/eventdeclaration.js @@ -31,7 +31,6 @@ class EventDeclaration extends IdentifiedDeclaration { */ constructor(modelFile, ast) { super(modelFile, ast); - this._isEventDeclaration = true; } /** @@ -43,26 +42,6 @@ class EventDeclaration extends IdentifiedDeclaration { process() { super.process(); } - - /** - * Returns true if this class is the definition of an event - * - * @return {boolean} true if the class is an event - */ - isEvent() { - return true; - } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a EventDeclaration - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isEventDeclaration); - } } module.exports = EventDeclaration; diff --git a/packages/concerto-core/lib/introspect/field.js b/packages/concerto-core/lib/introspect/field.js index 48e7835a72..1a91e6ce8f 100644 --- a/packages/concerto-core/lib/introspect/field.js +++ b/packages/concerto-core/lib/introspect/field.js @@ -37,7 +37,6 @@ class Field extends Property { */ constructor(parent, ast) { super(parent, ast); - this._isField = true; } /** @@ -102,14 +101,12 @@ class Field extends Property { } /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 + * Returns true if this class is the definition of a field. * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a Class Declaration + * @return {boolean} true if the class is a field */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isField); + isField() { + return true; } } diff --git a/packages/concerto-core/lib/introspect/identifieddeclaration.js b/packages/concerto-core/lib/introspect/identifieddeclaration.js index 2b6cebaaa2..27b129a3f5 100644 --- a/packages/concerto-core/lib/introspect/identifieddeclaration.js +++ b/packages/concerto-core/lib/introspect/identifieddeclaration.js @@ -27,27 +27,15 @@ const ClassDeclaration = require('./classdeclaration'); */ class IdentifiedDeclaration extends ClassDeclaration { /** - * Create an AssetDeclaration. + * Create an IdentifiedDeclaration. * @param {ModelFile} modelFile the ModelFile for this class * @param {Object} ast - The AST created by the parser * @throws {IllegalModelException} */ constructor(modelFile, ast) { super(modelFile, ast); - this._isIdentifiedDeclaration = true; this.process(); } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a AssetDeclaration - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isIdentifiedDeclaration); - } } module.exports = IdentifiedDeclaration; diff --git a/packages/concerto-core/lib/introspect/metamodel.js b/packages/concerto-core/lib/introspect/metamodel.js index e2d251ceb5..595e49b540 100644 --- a/packages/concerto-core/lib/introspect/metamodel.js +++ b/packages/concerto-core/lib/introspect/metamodel.js @@ -19,1069 +19,1069 @@ const ModelManager = require('../modelmanager'); const Factory = require('../factory'); const Serializer = require('../serializer'); +const metaModelCto = `/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace concerto.metamodel + /** - * Class to work with the Concerto metamodel + * The metadmodel for Concerto files */ -class MetaModel { - - /** - * The metamodel itself, as a CTO string - */ - static metaModelCto = `/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - namespace concerto.metamodel - - /** - * The metadmodel for Concerto files - */ - concept TypeIdentifier { - o String name - o String namespace optional - } - - abstract concept DecoratorLiteral { - } - - concept DecoratorString extends DecoratorLiteral { - o String value - } - - concept DecoratorNumber extends DecoratorLiteral { - o Double value - } - - concept DecoratorBoolean extends DecoratorLiteral { - o Boolean value - } - - concept DecoratorTypeReference extends DecoratorLiteral { - o TypeIdentifier type - o Boolean isArray default=false - } - - concept Decorator { - o String name - o DecoratorLiteral[] arguments optional - } - - concept Identified { - } - - concept IdentifiedBy extends Identified { - o String name - } - - abstract concept Declaration {} - - concept EnumDeclaration extends Declaration { - o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u - o EnumProperty[] properties - } - - concept EnumProperty { - o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u - o Decorator[] decorators optional - } - - concept ConceptDeclaration extends Declaration { - o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u - o Decorator[] decorators optional - o Boolean isAbstract default=false - o Identified identified optional - o TypeIdentifier superType optional - o Property[] properties - } - - concept AssetDeclaration extends ConceptDeclaration { - } - - concept ParticipantDeclaration extends ConceptDeclaration { - } - - concept TransactionDeclaration extends ConceptDeclaration { - } - - concept EventDeclaration extends ConceptDeclaration { - } - - abstract concept Property { - o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u - o Boolean isArray default=false - o Boolean isOptional default=false - o Decorator[] decorators optional - } - - concept RelationshipProperty extends Property { - o TypeIdentifier type - } - - concept ObjectProperty extends Property { - o String defaultValue optional - o TypeIdentifier type - } - - concept BooleanProperty extends Property { - o Boolean defaultValue optional - } - - concept DateTimeProperty extends Property { - } - - concept StringProperty extends Property { - o String defaultValue optional - o StringRegexValidator validator optional - } - - concept StringRegexValidator { - o String regex - } - - concept DoubleProperty extends Property { - o Double defaultValue optional - o DoubleDomainValidator validator optional - } - - concept DoubleDomainValidator { - o Double lower optional - o Double upper optional - } - - concept IntegerProperty extends Property { - o Integer defaultValue optional - o IntegerDomainValidator validator optional - } - - concept IntegerDomainValidator { - o Integer lower optional - o Integer upper optional - } - - concept LongProperty extends Property { - o Long defaultValue optional - o LongDomainValidator validator optional - } - - concept LongDomainValidator { - o Long lower optional - o Long upper optional - } - - abstract concept Import { - o String namespace - o String uri optional - } - - concept ImportAll extends Import { - } - - concept ImportType extends Import { - o String name - } - - concept Model { - o String namespace - o Import[] imports optional - o Declaration[] declarations optional - } - - concept Models { - o Model[] models - } - `; - - /** - * Create a metamodel manager (for validation against the metamodel) - * @return {*} the metamodel manager - */ - static createMetaModelManager() { - const metaModelManager = new ModelManager(); - metaModelManager.addModelFile(MetaModel.metaModelCto, 'concerto.metamodel'); - return metaModelManager; - } +concept TypeIdentifier { + o String name + o String namespace optional +} - /** - * Validate against the metamodel - * @param {object} input - the metamodel in JSON - * @return {object} the validated metamodel in JSON - */ - static validateMetaModel(input) { - const metaModelManager = MetaModel.createMetaModelManager(); - const factory = new Factory(metaModelManager); - const serializer = new Serializer(factory, metaModelManager); - // First validate the metaModel - const object = serializer.fromJSON(input); - return serializer.toJSON(object); - } +abstract concept DecoratorLiteral { +} - /** - * Create a name resolution table - * @param {*} modelManager - the model manager - * @param {object} metaModel - the metamodel (JSON) - * @return {object} mapping from a name to its namespace - */ - static createNameTable(modelManager, metaModel) { - const table = { - 'Concept': 'concerto', - 'Asset': 'concerto', - 'Participant': 'concerto', - 'Transaction ': 'concerto', - 'Event': 'concerto', - }; +concept DecoratorString extends DecoratorLiteral { + o String value +} - // First list the imported names in order (overriding as we go along) - const imports = metaModel.imports; - imports.forEach((imp) => { - const namespace = imp.namespace; - const modelFile = modelManager.getModelFile(namespace); - if (imp.$class === 'concerto.metamodel.ImportType') { - if (!modelFile.getLocalType(imp.name)) { - throw new Error(`Declaration ${imp.name} in namespace ${namespace} not found`); - } - table[imp.name] = namespace; - } else { - const decls = modelFile.getAllDeclarations(); - decls.forEach((decl) => { - table[decl.getName()] = namespace; - }); - } - }); +concept DecoratorNumber extends DecoratorLiteral { + o Double value +} - // Then add the names local to this metaModel (overriding as we go along) - if (metaModel.declarations) { - metaModel.declarations.forEach((decl) => { - table[decl.name] = metaModel.namespace; +concept DecoratorBoolean extends DecoratorLiteral { + o Boolean value +} + +concept DecoratorTypeReference extends DecoratorLiteral { + o TypeIdentifier type + o Boolean isArray default=false +} + +concept Decorator { + o String name + o DecoratorLiteral[] arguments optional +} + +concept Identified { +} + +concept IdentifiedBy extends Identified { + o String name +} + +abstract concept Declaration {} + +concept EnumDeclaration extends Declaration { + o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u + o EnumProperty[] properties +} + +concept EnumProperty { + o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u + o Decorator[] decorators optional +} + +concept ConceptDeclaration extends Declaration { + o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u + o Decorator[] decorators optional + o Boolean isAbstract default=false + o Identified identified optional + o TypeIdentifier superType optional + o Property[] properties +} + +concept AssetDeclaration extends ConceptDeclaration { +} + +concept ParticipantDeclaration extends ConceptDeclaration { +} + +concept TransactionDeclaration extends ConceptDeclaration { +} + +concept EventDeclaration extends ConceptDeclaration { +} + +abstract concept Property { + o String name regex=/^(?!null|true|false)(\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4})(?:\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\p{Mn}|\\p{Mc}|\\p{Nd}|\\p{Pc}|\\u200C|\\u200D)*$/u + o Boolean isArray default=false + o Boolean isOptional default=false + o Decorator[] decorators optional +} + +concept RelationshipProperty extends Property { + o TypeIdentifier type +} + +concept ObjectProperty extends Property { + o String defaultValue optional + o TypeIdentifier type +} + +concept BooleanProperty extends Property { + o Boolean defaultValue optional +} + +concept DateTimeProperty extends Property { +} + +concept StringProperty extends Property { + o String defaultValue optional + o StringRegexValidator validator optional +} + +concept StringRegexValidator { + o String regex +} + +concept DoubleProperty extends Property { + o Double defaultValue optional + o DoubleDomainValidator validator optional +} + +concept DoubleDomainValidator { + o Double lower optional + o Double upper optional +} + +concept IntegerProperty extends Property { + o Integer defaultValue optional + o IntegerDomainValidator validator optional +} + +concept IntegerDomainValidator { + o Integer lower optional + o Integer upper optional +} + +concept LongProperty extends Property { + o Long defaultValue optional + o LongDomainValidator validator optional +} + +concept LongDomainValidator { + o Long lower optional + o Long upper optional +} + +abstract concept Import { + o String namespace + o String uri optional +} + +concept ImportAll extends Import { +} + +concept ImportType extends Import { + o String name +} + +concept Model { + o String namespace + o Import[] imports optional + o Declaration[] declarations optional +} + +concept Models { + o Model[] models +} +`; + +/** + * Create a metamodel manager (for validation against the metamodel) + * @return {*} the metamodel manager + */ +function createMetaModelManager() { + const metaModelManager = new ModelManager(); + metaModelManager.addModelFile(metaModelCto, 'concerto.metamodel'); + return metaModelManager; +} + +/** + * Validate against the metamodel + * @param {object} input - the metamodel in JSON + * @return {object} the validated metamodel in JSON + */ +function validateMetaModel(input) { + const metaModelManager = createMetaModelManager(); + const factory = new Factory(metaModelManager); + const serializer = new Serializer(factory, metaModelManager); + // First validate the metaModel + const object = serializer.fromJSON(input); + return serializer.toJSON(object); +} + +/** + * Create a name resolution table + * @param {*} modelManager - the model manager + * @param {object} metaModel - the metamodel (JSON) + * @return {object} mapping from a name to its namespace + */ +function createNameTable(modelManager, metaModel) { + const table = { + 'Concept': 'concerto', + 'Asset': 'concerto', + 'Participant': 'concerto', + 'Transaction ': 'concerto', + 'Event': 'concerto', + }; + + // First list the imported names in order (overriding as we go along) + const imports = metaModel.imports; + imports.forEach((imp) => { + const namespace = imp.namespace; + const modelFile = modelManager.getModelFile(namespace); + if (imp.$class === 'concerto.metamodel.ImportType') { + if (!modelFile.getLocalType(imp.name)) { + throw new Error(`Declaration ${imp.name} in namespace ${namespace} not found`); + } + table[imp.name] = namespace; + } else { + const decls = modelFile.getAllDeclarations(); + decls.forEach((decl) => { + table[decl.getName()] = namespace; }); } + }); - return table; + // Then add the names local to this metaModel (overriding as we go along) + if (metaModel.declarations) { + metaModel.declarations.forEach((decl) => { + table[decl.name] = metaModel.namespace; + }); } - /** - * Resolve a name using the name table - * @param {string} name - the name of the type to resolve - * @param {object} table - the name table - * @return {string} the namespace for that name - */ - static resolveName(name, table) { - if (!table[name]) { - throw new Error(`Name ${name} not found`); - } - return table[name]; + return table; +} + +/** + * Resolve a name using the name table + * @param {string} name - the name of the type to resolve + * @param {object} table - the name table + * @return {string} the namespace for that name + */ +function resolveName(name, table) { + if (!table[name]) { + throw new Error(`Name ${name} not found`); } + return table[name]; +} - /** - * Name resolution for metamodel - * @param {object} metaModel - the metamodel (JSON) - * @param {object} table - the name table - * @return {object} the metamodel with fully qualified names - */ - static resolveTypeNames(metaModel, table) { - switch (metaModel.$class) { - case 'concerto.metamodel.Model': { - if (metaModel.declarations) { - metaModel.declarations.forEach((decl) => { - MetaModel.resolveTypeNames(decl, table); - }); - } - } - break; - case 'concerto.metamodel.AssetDeclaration': - case 'concerto.metamodel.ConceptDeclaration': - case 'concerto.metamodel.EventDeclaration': - case 'concerto.metamodel.TransactionDeclaration': - case 'concerto.metamodel.ParticipantDeclaration': { - if (metaModel.superType) { - const name = metaModel.superType.name; - metaModel.superType.namespace = MetaModel.resolveName(name, table); - } - metaModel.properties.forEach((property) => { - MetaModel.resolveTypeNames(property, table); +/** + * Name resolution for metamodel + * @param {object} metaModel - the metamodel (JSON) + * @param {object} table - the name table + * @return {object} the metamodel with fully qualified names + */ +function resolveTypeNames(metaModel, table) { + switch (metaModel.$class) { + case 'concerto.metamodel.Model': { + if (metaModel.declarations) { + metaModel.declarations.forEach((decl) => { + resolveTypeNames(decl, table); }); - if (metaModel.decorators) { - metaModel.decorators.forEach((decorator) => { - MetaModel.resolveTypeNames(decorator, table); - }); - } } - break; - case 'concerto.metamodel.EnumDeclaration': { - if (metaModel.decorators) { - metaModel.decorators.forEach((decorator) => { - MetaModel.resolveTypeNames(decorator, table); - }); - } + } + break; + case 'concerto.metamodel.AssetDeclaration': + case 'concerto.metamodel.ConceptDeclaration': + case 'concerto.metamodel.EventDeclaration': + case 'concerto.metamodel.TransactionDeclaration': + case 'concerto.metamodel.ParticipantDeclaration': { + if (metaModel.superType) { + const name = metaModel.superType.name; + metaModel.superType.namespace = resolveName(name, table); } - break; - case 'concerto.metamodel.EnumProperty': - case 'concerto.metamodel.ObjectProperty': - case 'concerto.metamodel.RelationshipProperty': { - const name = metaModel.type.name; - metaModel.type.namespace = MetaModel.resolveName(name, table); - if (metaModel.decorators) { - metaModel.decorators.forEach((decorator) => { - MetaModel.resolveTypeNames(decorator, table); - }); - } + metaModel.properties.forEach((property) => { + resolveTypeNames(property, table); + }); + if (metaModel.decorators) { + metaModel.decorators.forEach((decorator) => { + resolveTypeNames(decorator, table); + }); } - break; - case 'concerto.metamodel.Decorator': { - if (metaModel.arguments) { - metaModel.arguments.forEach((argument) => { - MetaModel.resolveTypeNames(argument, table); - }); - } + } + break; + case 'concerto.metamodel.EnumDeclaration': { + if (metaModel.decorators) { + metaModel.decorators.forEach((decorator) => { + resolveTypeNames(decorator, table); + }); } - break; - case 'concerto.metamodel.DecoratorTypeReference': { - const name = metaModel.type.name; - metaModel.type.namespace = MetaModel.resolveName(name, table); + } + break; + case 'concerto.metamodel.EnumProperty': + case 'concerto.metamodel.ObjectProperty': + case 'concerto.metamodel.RelationshipProperty': { + const name = metaModel.type.name; + metaModel.type.namespace = resolveName(name, table); + if (metaModel.decorators) { + metaModel.decorators.forEach((decorator) => { + resolveTypeNames(decorator, table); + }); } - break; + } + break; + case 'concerto.metamodel.Decorator': { + if (metaModel.arguments) { + metaModel.arguments.forEach((argument) => { + resolveTypeNames(argument, table); + }); } - return metaModel; } - - /** - * Resolve the namespace for names in the metamodel - * @param {object} modelManager - the ModelManager - * @param {object} metaModel - the MetaModel - * @return {object} the resolved metamodel - */ - static resolveMetaModel(modelManager, metaModel) { - const result = JSON.parse(JSON.stringify(metaModel)); - const nameTable = MetaModel.createNameTable(modelManager, metaModel); - // This adds the fully qualified names to the same object - MetaModel.resolveTypeNames(result, nameTable); - return result; + break; + case 'concerto.metamodel.DecoratorTypeReference': { + const name = metaModel.type.name; + metaModel.type.namespace = resolveName(name, table); + } + break; } + return metaModel; +} - /** - * Create metamodel for an enum property - * @param {object} ast - the AST for the property - * @return {object} the metamodel for this property - */ - static enumPropertyToMetaModel(ast) { - const property = {}; +/** + * Resolve the namespace for names in the metamodel + * @param {object} modelManager - the ModelManager + * @param {object} metaModel - the MetaModel + * @return {object} the resolved metamodel + */ +function resolveMetaModel(modelManager, metaModel) { + const result = JSON.parse(JSON.stringify(metaModel)); + const nameTable = createNameTable(modelManager, metaModel); + // This adds the fully qualified names to the same object + resolveTypeNames(result, nameTable); + return result; +} - property.$class = 'concerto.metamodel.EnumProperty'; +/** + * Create metamodel for an enum property + * @param {object} ast - the AST for the property + * @return {object} the metamodel for this property + */ +function enumPropertyToMetaModel(ast) { + const property = {}; - // Property name - property.name = ast.id.name; + property.$class = 'concerto.metamodel.EnumProperty'; - return property; - } + // Property name + property.name = ast.id.name; - /** - * Create metamodel for a decorator argument - * @param {object} ast - the AST for the decorator argument - * @return {object} the metamodel for this decorator argument - */ - static decoratorArgToMetaModel(ast) { - const decoratorArg = {}; - switch (ast.type) { - case 'String': - decoratorArg.$class = 'concerto.metamodel.DecoratorString'; - decoratorArg.value = ast.value; - break; - case 'Number': - decoratorArg.$class = 'concerto.metamodel.DecoratorNumber'; - decoratorArg.value = ast.value; - break; - case 'Boolean': - decoratorArg.$class = 'concerto.metamodel.DecoratorBoolean'; - decoratorArg.value = ast.value; - break; - default: - decoratorArg.$class = 'concerto.metamodel.DecoratorTypeReference'; - decoratorArg.type = { - $class: 'concerto.metamodel.TypeIdentifier', - name: ast.value.name, - }; - decoratorArg.isArray = ast.value.array; - break; - } + return property; +} - return decoratorArg; +/** + * Create metamodel for a decorator argument + * @param {object} ast - the AST for the decorator argument + * @return {object} the metamodel for this decorator argument + */ +function decoratorArgToMetaModel(ast) { + const decoratorArg = {}; + switch (ast.type) { + case 'String': + decoratorArg.$class = 'concerto.metamodel.DecoratorString'; + decoratorArg.value = ast.value; + break; + case 'Number': + decoratorArg.$class = 'concerto.metamodel.DecoratorNumber'; + decoratorArg.value = ast.value; + break; + case 'Boolean': + decoratorArg.$class = 'concerto.metamodel.DecoratorBoolean'; + decoratorArg.value = ast.value; + break; + default: + decoratorArg.$class = 'concerto.metamodel.DecoratorTypeReference'; + decoratorArg.type = { + $class: 'concerto.metamodel.TypeIdentifier', + name: ast.value.name, + }; + decoratorArg.isArray = ast.value.array; + break; } - /** - * Create metamodel for a decorator - * @param {object} ast - the AST for the decorator - * @return {object} the metamodel for this decorator - */ - static decoratorToMetaModel(ast) { - const decorator = { - $class: 'concerto.metamodel.Decorator', - name: ast.name, - }; - if (ast.arguments && ast.arguments.list) { - if (!ast.arguments.list[0]) { - decorator.arguments = []; - } else { - decorator.arguments = ast.arguments.list.map(MetaModel.decoratorArgToMetaModel); - } + return decoratorArg; +} + +/** + * Create metamodel for a decorator + * @param {object} ast - the AST for the decorator + * @return {object} the metamodel for this decorator + */ +function decoratorToMetaModel(ast) { + const decorator = { + $class: 'concerto.metamodel.Decorator', + name: ast.name, + }; + if (ast.arguments && ast.arguments.list) { + if (!ast.arguments.list[0]) { + decorator.arguments = []; + } else { + decorator.arguments = ast.arguments.list.map(decoratorArgToMetaModel); } - return decorator; } + return decorator; +} + +/** + * Create metamodel for a list of decorators + * @param {object} ast - the AST for the decorators + * @return {object} the metamodel for the decorators + */ +function decoratorsToMetaModel(ast) { + return ast.map(decoratorToMetaModel); +} - /** - * Create metamodel for a list of decorators - * @param {object} ast - the AST for the decorators - * @return {object} the metamodel for the decorators - */ - static decoratorsToMetaModel(ast) { - return ast.map(MetaModel.decoratorToMetaModel); +/** + * Create metamodel for a property + * @param {object} ast - the AST for the property + * @return {object} the metamodel for this property + */ +function propertyToMetaModel(ast) { + const property = {}; + + // Property name + property.name = ast.id.name; + // Is it an array? + if (ast.array) { + property.isArray = true; + } else { + property.isArray = false; } + // Is it an optional? + if (ast.optional) { + property.isOptional = true; + } else { + property.isOptional = false; + } + // XXX Can it be missing? + const type = ast.propertyType.name; - /** - * Create metamodel for a property - * @param {object} ast - the AST for the property - * @return {object} the metamodel for this property - */ - static propertyToMetaModel(ast) { - const property = {}; - - // Property name - property.name = ast.id.name; - // Is it an array? - if (ast.array) { - property.isArray = true; - } else { - property.isArray = false; - } - // Is it an optional? - if (ast.optional) { - property.isOptional = true; - } else { - property.isOptional = false; - } - // XXX Can it be missing? - const type = ast.propertyType.name; + // Handle decorators + if (ast.decorators && ast.decorators.length > 0) { + property.decorators = decoratorsToMetaModel(ast.decorators); + } - // Handle decorators - if (ast.decorators && ast.decorators.length > 0) { - property.decorators = MetaModel.decoratorsToMetaModel(ast.decorators); + switch (type) { + case 'Integer': + property.$class = 'concerto.metamodel.IntegerProperty'; + if (ast.default) { + property.defaultValue = parseInt(ast.default); } - - switch (type) { - case 'Integer': - property.$class = 'concerto.metamodel.IntegerProperty'; - if (ast.default) { - property.defaultValue = parseInt(ast.default); - } - if (ast.range) { - const validator = { - $class: 'concerto.metamodel.IntegerDomainValidator', - }; - if (ast.range.lower) { - validator.lower = parseInt(ast.range.lower); - } - if (ast.range.upper) { - validator.upper = parseInt(ast.range.upper); - } - property.validator = validator; - } - break; - case 'Long': - property.$class = 'concerto.metamodel.LongProperty'; - if (ast.default) { - property.defaultValue = parseInt(ast.default); - } - if (ast.range) { - const validator = { - $class: 'concerto.metamodel.LongDomainValidator', - }; - if (ast.range.lower) { - validator.lower = parseInt(ast.range.lower); - } - if (ast.range.upper) { - validator.upper = parseInt(ast.range.upper); - } - property.validator = validator; + if (ast.range) { + const validator = { + $class: 'concerto.metamodel.IntegerDomainValidator', + }; + if (ast.range.lower) { + validator.lower = parseInt(ast.range.lower); } - break; - case 'Double': - property.$class = 'concerto.metamodel.DoubleProperty'; - if (ast.default) { - property.defaultValue = parseFloat(ast.default); + if (ast.range.upper) { + validator.upper = parseInt(ast.range.upper); } - if (ast.range) { - const validator = { - $class: 'concerto.metamodel.DoubleDomainValidator', - }; - if (ast.range.lower) { - validator.lower = parseFloat(ast.range.lower); - } - if (ast.range.upper) { - validator.upper = parseFloat(ast.range.upper); - } - property.validator = validator; + property.validator = validator; + } + break; + case 'Long': + property.$class = 'concerto.metamodel.LongProperty'; + if (ast.default) { + property.defaultValue = parseInt(ast.default); + } + if (ast.range) { + const validator = { + $class: 'concerto.metamodel.LongDomainValidator', + }; + if (ast.range.lower) { + validator.lower = parseInt(ast.range.lower); } - break; - case 'Boolean': - property.$class = 'concerto.metamodel.BooleanProperty'; - if (ast.default) { - if (ast.default === 'true') { - property.defaultValue = true; - } else { - property.defaultValue = false; - } + if (ast.range.upper) { + validator.upper = parseInt(ast.range.upper); } - break; - case 'DateTime': - property.$class = 'concerto.metamodel.DateTimeProperty'; - break; - case 'String': - property.$class = 'concerto.metamodel.StringProperty'; - if (ast.default) { - property.defaultValue = ast.default; + property.validator = validator; + } + break; + case 'Double': + property.$class = 'concerto.metamodel.DoubleProperty'; + if (ast.default) { + property.defaultValue = parseFloat(ast.default); + } + if (ast.range) { + const validator = { + $class: 'concerto.metamodel.DoubleDomainValidator', + }; + if (ast.range.lower) { + validator.lower = parseFloat(ast.range.lower); } - if (ast.regex) { - const regex = ast.regex.flags ? `/${ast.regex.pattern}/${ast.regex.flags}` : `/${ast.regex.pattern}/}`; - property.validator = { - $class: 'concerto.metamodel.StringRegexValidator', - regex, - }; + if (ast.range.upper) { + validator.upper = parseFloat(ast.range.upper); } - break; - default: - property.$class = 'concerto.metamodel.ObjectProperty'; - if (ast.default) { - property.defaultValue = ast.default; + property.validator = validator; + } + break; + case 'Boolean': + property.$class = 'concerto.metamodel.BooleanProperty'; + if (ast.default) { + if (ast.default === 'true') { + property.defaultValue = true; + } else { + property.defaultValue = false; } - property.type = { - $class: 'concerto.metamodel.TypeIdentifier', - name: type + } + break; + case 'DateTime': + property.$class = 'concerto.metamodel.DateTimeProperty'; + break; + case 'String': + property.$class = 'concerto.metamodel.StringProperty'; + if (ast.default) { + property.defaultValue = ast.default; + } + if (ast.regex) { + const regex = ast.regex.flags ? `/${ast.regex.pattern}/${ast.regex.flags}` : `/${ast.regex.pattern}/}`; + property.validator = { + $class: 'concerto.metamodel.StringRegexValidator', + regex, }; - break; } - - return property; - } - - /** - * Create metamodel for a relationship - * @param {object} ast - the AST for the relationtion - * @return {object} the metamodel for this relationship - */ - static relationshipToMetaModel(ast) { - let relationship = { - $class: 'concerto.metamodel.RelationshipProperty', - type: { - $class: 'concerto.metamodel.TypeIdentifier', - name: ast.propertyType.name - }, + break; + default: + property.$class = 'concerto.metamodel.ObjectProperty'; + if (ast.default) { + property.defaultValue = ast.default; + } + property.type = { + $class: 'concerto.metamodel.TypeIdentifier', + name: type }; + break; + } - // Property name - relationship.name = ast.id.name; - // Is it an array? - if (ast.array) { - relationship.isArray = true; - } else { - relationship.isArray = false; - } - // Is it an optional? - if (ast.optional) { - relationship.isOptional = true; - } else { - relationship.isOptional = false; - } + return property; +} - return relationship; +/** + * Create metamodel for a relationship + * @param {object} ast - the AST for the relationtion + * @return {object} the metamodel for this relationship + */ +function relationshipToMetaModel(ast) { + let relationship = { + $class: 'concerto.metamodel.RelationshipProperty', + type: { + $class: 'concerto.metamodel.TypeIdentifier', + name: ast.propertyType.name + }, + }; + + // Property name + relationship.name = ast.id.name; + // Is it an array? + if (ast.array) { + relationship.isArray = true; + } else { + relationship.isArray = false; + } + // Is it an optional? + if (ast.optional) { + relationship.isOptional = true; + } else { + relationship.isOptional = false; } - /** - * Create metamodel for an enum declaration - * @param {object} ast - the AST for the enum declaration - * @return {object} the metamodel for this enum declaration - */ - static enumDeclToMetaModel(ast) { - let decl = {}; + return relationship; +} - decl.$class = 'concerto.metamodel.EnumDeclaration'; +/** + * Create metamodel for an enum declaration + * @param {object} ast - the AST for the enum declaration + * @return {object} the metamodel for this enum declaration + */ +function enumDeclToMetaModel(ast) { + let decl = {}; - // The enum name - decl.name = ast.id.name; + decl.$class = 'concerto.metamodel.EnumDeclaration'; - // Enum properties - decl.properties = []; - for (let n = 0; n < ast.body.declarations.length; n++) { - let thing = ast.body.declarations[n]; + // The enum name + decl.name = ast.id.name; - decl.properties.push(MetaModel.enumPropertyToMetaModel(thing)); - } + // Enum properties + decl.properties = []; + for (let n = 0; n < ast.body.declarations.length; n++) { + let thing = ast.body.declarations[n]; - return decl; + decl.properties.push(enumPropertyToMetaModel(thing)); } - /** - * Create metamodel for a concept declaration - * @param {object} ast - the AST for the concept declaration - * @return {object} the metamodel for this concept declaration - */ - static conceptDeclToMetaModel(ast) { - let decl = {}; - - if(ast.type === 'AssetDeclaration') { - decl.$class = 'concerto.metamodel.AssetDeclaration'; - } else if (ast.type === 'ConceptDeclaration') { - decl.$class = 'concerto.metamodel.ConceptDeclaration'; - } else if (ast.type === 'EventDeclaration') { - decl.$class = 'concerto.metamodel.EventDeclaration'; - } else if (ast.type === 'ParticipantDeclaration') { - decl.$class = 'concerto.metamodel.ParticipantDeclaration'; - } else if (ast.type === 'TransactionDeclaration') { - decl.$class = 'concerto.metamodel.TransactionDeclaration'; - } + return decl; +} + +/** + * Create metamodel for a concept declaration + * @param {object} ast - the AST for the concept declaration + * @return {object} the metamodel for this concept declaration + */ +function conceptDeclToMetaModel(ast) { + let decl = {}; + + if(ast.type === 'AssetDeclaration') { + decl.$class = 'concerto.metamodel.AssetDeclaration'; + } else if (ast.type === 'ConceptDeclaration') { + decl.$class = 'concerto.metamodel.ConceptDeclaration'; + } else if (ast.type === 'EventDeclaration') { + decl.$class = 'concerto.metamodel.EventDeclaration'; + } else if (ast.type === 'ParticipantDeclaration') { + decl.$class = 'concerto.metamodel.ParticipantDeclaration'; + } else if (ast.type === 'TransactionDeclaration') { + decl.$class = 'concerto.metamodel.TransactionDeclaration'; + } - // The concept name - decl.name = ast.id.name; + // The concept name + decl.name = ast.id.name; - // Is the concept abstract? - if (ast.abstract) { - decl.isAbstract = true; - } else { - decl.isAbstract = false; - } + // Is the concept abstract? + if (ast.abstract) { + decl.isAbstract = true; + } else { + decl.isAbstract = false; + } - // Super type - if (ast.classExtension) { - const cname = ast.classExtension.class.name; - if (cname !== 'Asset' && + // Super type + if (ast.classExtension) { + const cname = ast.classExtension.class.name; + if (cname !== 'Asset' && cname !== 'Concept' && cname !== 'Event' && cname !== 'Participant' && cname !== 'Transaction') { - decl.superType = { - $class: 'concerto.metamodel.TypeIdentifier', - name: ast.classExtension.class.name - }; - } - } - - // Is the concept idenfitied by a property - if (ast.idField) { - if (ast.idField.name === '$identifier') { - decl.identified = { - $class: 'concerto.metamodel.Identified' - }; - } else { - decl.identified = { - $class: 'concerto.metamodel.IdentifiedBy', - name: ast.idField.name - }; - } - } - - // Handle decorators - if (ast.decorators && ast.decorators.length > 0) { - decl.decorators = MetaModel.decoratorsToMetaModel(ast.decorators); - } - - // Concept properties - decl.properties = []; - for (let n = 0; n < ast.body.declarations.length; n++) { - let thing = ast.body.declarations[n]; - // console.log(`THING ${JSON.stringify(thing)}`); - if (thing.type === 'FieldDeclaration') { - decl.properties.push(MetaModel.propertyToMetaModel(thing)); - } else if (thing.type === 'RelationshipDeclaration') { - decl.properties.push(MetaModel.relationshipToMetaModel(thing)); - } + decl.superType = { + $class: 'concerto.metamodel.TypeIdentifier', + name: ast.classExtension.class.name + }; } - - return decl; } - /** - * Create metamodel for a declaration - * @param {object} ast - the AST for the declaration - * @return {object} the metamodel for this declaration - */ - static declToMetaModel(ast) { - if(ast.type === 'EnumDeclaration') { - return MetaModel.enumDeclToMetaModel(ast); + // Is the concept idenfitied by a property + if (ast.idField) { + if (ast.idField.name === '$identifier') { + decl.identified = { + $class: 'concerto.metamodel.Identified' + }; + } else { + decl.identified = { + $class: 'concerto.metamodel.IdentifiedBy', + name: ast.idField.name + }; } - return MetaModel.conceptDeclToMetaModel(ast); } - /** - * Export metamodel from an AST - * @param {object} ast - the AST for the model - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model - */ - static modelToMetaModel(ast, validate = true) { - const metamodel = { - $class: 'concerto.metamodel.Model' - }; - metamodel.namespace = ast.namespace; - - if(ast.imports) { - metamodel.imports = []; - ast.imports.forEach((imp) => { - const split = imp.namespace.split('.'); - const name = split.pop(); - const namespace = split.join('.'); - if (namespace === 'concerto') { - return; - } - const ns = { namespace }; - if (name === '*') { - ns.$class = 'concerto.metamodel.ImportAll'; - } else { - ns.$class = 'concerto.metamodel.ImportType'; - ns.name = name; - } - if(imp.uri) { - ns.uri = imp.uri; - } - metamodel.imports.push(ns); - }); - } + // Handle decorators + if (ast.decorators && ast.decorators.length > 0) { + decl.decorators = decoratorsToMetaModel(ast.decorators); + } - if (ast.body.length > 0) { - metamodel.declarations = []; + // Concept properties + decl.properties = []; + for (let n = 0; n < ast.body.declarations.length; n++) { + let thing = ast.body.declarations[n]; + // console.log(`THING ${JSON.stringify(thing)}`); + if (thing.type === 'FieldDeclaration') { + decl.properties.push(propertyToMetaModel(thing)); + } else if (thing.type === 'RelationshipDeclaration') { + decl.properties.push(relationshipToMetaModel(thing)); } - for(let n=0; n < ast.body.length; n++ ) { - const thing = ast.body[n]; - const decl = MetaModel.declToMetaModel(thing); - metamodel.declarations.push(decl); - } - - // Last, validate the JSON metaModel - const mm = validate ? MetaModel.validateMetaModel(metamodel) : metamodel; - - return mm; } - /** - * Export metamodel from a model file - * @param {object} modelFile - the ModelFile - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model - */ - static modelFileToMetaModel(modelFile, validate) { - return MetaModel.modelToMetaModel(modelFile.ast, validate); + return decl; +} + +/** + * Create metamodel for a declaration + * @param {object} ast - the AST for the declaration + * @return {object} the metamodel for this declaration + */ +function declToMetaModel(ast) { + if(ast.type === 'EnumDeclaration') { + return enumDeclToMetaModel(ast); } + return conceptDeclToMetaModel(ast); +} - /** - * Export metamodel from a model manager - * @param {object} modelManager - the ModelManager - * @param {boolean} [resolve] - whether to resolve names - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model manager - */ - static modelManagerToMetaModel(modelManager, resolve, validate) { - const result = { - $class: 'concerto.metamodel.Models', - models: [], - }; - modelManager.getModelFiles().forEach((modelFile) => { - let metaModel = MetaModel.modelToMetaModel(modelFile.ast, validate); - if (resolve) { - metaModel = MetaModel.resolveMetaModel(modelManager, metaModel); +/** + * Export metamodel from an AST + * @param {object} ast - the AST for the model + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model + */ +function modelToMetaModel(ast, validate = true) { + const metamodel = { + $class: 'concerto.metamodel.Model' + }; + metamodel.namespace = ast.namespace; + + if(ast.imports) { + metamodel.imports = []; + ast.imports.forEach((imp) => { + const split = imp.namespace.split('.'); + const name = split.pop(); + const namespace = split.join('.'); + if (namespace === 'concerto') { + return; + } + const ns = { namespace }; + if (name === '*') { + ns.$class = 'concerto.metamodel.ImportAll'; + } else { + ns.$class = 'concerto.metamodel.ImportType'; + ns.name = name; } - result.models.push(metaModel); + if(imp.uri) { + ns.uri = imp.uri; + } + metamodel.imports.push(ns); }); - return result; } - /** - * Create decorator argument string from a metamodel - * @param {object} mm - the metamodel - * @return {string} the string for the decorator argument - */ - static decoratorArgFromMetaModel(mm) { - let result = ''; - switch (mm.$class) { - case 'concerto.metamodel.DecoratorTypeReference': - result += `${mm.type.name}${mm.isArray ? '[]' : ''}`; - break; - case 'concerto.metamodel.DecoratorString': - result += `"${mm.value}"`; - break; - default: - result += `${mm.value}`; - break; - } - return result; + if (ast.body.length > 0) { + metamodel.declarations = []; + } + for(let n=0; n < ast.body.length; n++ ) { + const thing = ast.body[n]; + const decl = declToMetaModel(thing); + metamodel.declarations.push(decl); } - /** - * Create decorator string from a metamodel - * @param {object} mm - the metamodel - * @return {string} the string for the decorator - */ - static decoratorFromMetaModel(mm) { - let result = ''; - result += `@${mm.name}`; - if (mm.arguments) { - result += '('; - result += mm.arguments.map(MetaModel.decoratorArgFromMetaModel).join(','); - result += ')'; + // Last, validate the JSON metaModel + const mm = validate ? validateMetaModel(metamodel) : metamodel; + + return mm; +} + +/** + * Export metamodel from a model file + * @param {object} modelFile - the ModelFile + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model + */ +function modelFileToMetaModel(modelFile, validate) { + return modelToMetaModel(modelFile.ast, validate); +} + +/** + * Export metamodel from a model manager + * @param {object} modelManager - the ModelManager + * @param {boolean} [resolve] - whether to resolve names + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model manager + */ +function modelManagerToMetaModel(modelManager, resolve, validate) { + const result = { + $class: 'concerto.metamodel.Models', + models: [], + }; + modelManager.getModelFiles().forEach((modelFile) => { + let metaModel = modelToMetaModel(modelFile.ast, validate); + if (resolve) { + metaModel = resolveMetaModel(modelManager, metaModel); } - return result; + result.models.push(metaModel); + }); + return result; +} + +/** + * Create decorator argument string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for the decorator argument + */ +function decoratorArgFromMetaModel(mm) { + let result = ''; + switch (mm.$class) { + case 'concerto.metamodel.DecoratorTypeReference': + result += `${mm.type.name}${mm.isArray ? '[]' : ''}`; + break; + case 'concerto.metamodel.DecoratorString': + result += `"${mm.value}"`; + break; + default: + result += `${mm.value}`; + break; } + return result; +} - /** - * Create decorators string from a metamodel - * @param {object} mm - the metamodel - * @param {string} prefix - indentation - * @return {string} the string for the decorators - */ - static decoratorsFromMetaModel(mm, prefix) { - let result = ''; - result += mm.map(MetaModel.decoratorFromMetaModel).join(`\n${prefix}`); - result += `\n${prefix}`; - return result; +/** + * Create decorator string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for the decorator + */ +function decoratorFromMetaModel(mm) { + let result = ''; + result += `@${mm.name}`; + if (mm.arguments) { + result += '('; + result += mm.arguments.map(decoratorArgFromMetaModel).join(','); + result += ')'; } + return result; +} - /** - * Create a property string from a metamodel - * @param {object} mm - the metamodel - * @return {string} the string for that property - */ - static propertyFromMetaModel(mm) { - let result = ''; - let defaultString = ''; - let validatorString = ''; - - if (mm.decorators) { - result += MetaModel.decoratorsFromMetaModel(mm.decorators, ' '); - } - if (mm.$class === 'concerto.metamodel.RelationshipProperty') { - result += '-->'; - } else { - result += 'o'; - } +/** + * Create decorators string from a metamodel + * @param {object} mm - the metamodel + * @param {string} prefix - indentation + * @return {string} the string for the decorators + */ +function decoratorsFromMetaModel(mm, prefix) { + let result = ''; + result += mm.map(decoratorFromMetaModel).join(`\n${prefix}`); + result += `\n${prefix}`; + return result; +} - switch (mm.$class) { - case 'concerto.metamodel.EnumProperty': - break; - case 'concerto.metamodel.BooleanProperty': - result += ' Boolean'; - if (mm.defaultValue === true || mm.defaultValue === false) { - if (mm.defaultValue) { - defaultString += ' default=true'; - } else { - defaultString += ' default=false'; - } - } - break; - case 'concerto.metamodel.DateTimeProperty': - result += ' DateTime'; - break; - case 'concerto.metamodel.DoubleProperty': - result += ' Double'; - if (mm.defaultValue) { - const doubleString = mm.defaultValue.toFixed(Math.max(1, (mm.defaultValue.toString().split('.')[1] || []).length)); +/** + * Create a property string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for that property + */ +function propertyFromMetaModel(mm) { + let result = ''; + let defaultString = ''; + let validatorString = ''; - defaultString += ` default=${doubleString}`; - } - if (mm.validator) { - const lowerString = mm.validator.lower ? mm.validator.lower : ''; - const upperString = mm.validator.upper ? mm.validator.upper : ''; - validatorString += ` range=[${lowerString},${upperString}]`; - } - break; - case 'concerto.metamodel.IntegerProperty': - result += ' Integer'; - if (mm.defaultValue) { - defaultString += ` default=${mm.defaultValue.toString()}`; - } - if (mm.validator) { - const lowerString = mm.validator.lower ? mm.validator.lower : ''; - const upperString = mm.validator.upper ? mm.validator.upper : ''; - validatorString += ` range=[${lowerString},${upperString}]`; - } - break; - case 'concerto.metamodel.LongProperty': - result += ' Long'; - if (mm.defaultValue) { - defaultString += ` default=${mm.defaultValue.toString()}`; - } - if (mm.validator) { - const lowerString = mm.validator.lower ? mm.validator.lower : ''; - const upperString = mm.validator.upper ? mm.validator.upper : ''; - validatorString += ` range=[${lowerString},${upperString}]`; - } - break; - case 'concerto.metamodel.StringProperty': - result += ' String'; - if (mm.defaultValue) { - defaultString += ` default="${mm.defaultValue}"`; - } - if (mm.validator) { - validatorString += ` regex=${mm.validator.regex}`; - } - break; - case 'concerto.metamodel.ObjectProperty': - result += ` ${mm.type.name}`; + if (mm.decorators) { + result += decoratorsFromMetaModel(mm.decorators, ' '); + } + if (mm.$class === 'concerto.metamodel.RelationshipProperty') { + result += '-->'; + } else { + result += 'o'; + } + + switch (mm.$class) { + case 'concerto.metamodel.EnumProperty': + break; + case 'concerto.metamodel.BooleanProperty': + result += ' Boolean'; + if (mm.defaultValue === true || mm.defaultValue === false) { if (mm.defaultValue) { - defaultString += ` default="${mm.defaultValue}"`; + defaultString += ' default=true'; + } else { + defaultString += ' default=false'; } - break; - case 'concerto.metamodel.RelationshipProperty': - result += ` ${mm.type.name}`; - break; } - if (mm.isArray) { - result += '[]'; + break; + case 'concerto.metamodel.DateTimeProperty': + result += ' DateTime'; + break; + case 'concerto.metamodel.DoubleProperty': + result += ' Double'; + if (mm.defaultValue) { + const doubleString = mm.defaultValue.toFixed(Math.max(1, (mm.defaultValue.toString().split('.')[1] || []).length)); + + defaultString += ` default=${doubleString}`; } - result += ` ${mm.name}`; - if (mm.isOptional) { - result += ' optional'; + if (mm.validator) { + const lowerString = mm.validator.lower ? mm.validator.lower : ''; + const upperString = mm.validator.upper ? mm.validator.upper : ''; + validatorString += ` range=[${lowerString},${upperString}]`; } - result += defaultString; - result += validatorString; - return result; - } - - /** - * Create a declaration string from a metamodel - * @param {object} mm - the metamodel - * @return {string} the string for that declaration - */ - static declFromMetaModel(mm) { - let result = ''; - if (mm.decorators) { - result += MetaModel.decoratorsFromMetaModel(mm.decorators, ''); + break; + case 'concerto.metamodel.IntegerProperty': + result += ' Integer'; + if (mm.defaultValue) { + defaultString += ` default=${mm.defaultValue.toString()}`; } - - if (mm.isAbstract) { - result += 'abstract '; + if (mm.validator) { + const lowerString = mm.validator.lower ? mm.validator.lower : ''; + const upperString = mm.validator.upper ? mm.validator.upper : ''; + validatorString += ` range=[${lowerString},${upperString}]`; } - switch (mm.$class) { - case 'concerto.metamodel.AssetDeclaration': - result += `asset ${mm.name} `; - break; - case 'concerto.metamodel.ConceptDeclaration': - result += `concept ${mm.name} `; - break; - case 'concerto.metamodel.EventDeclaration': - result += `event ${mm.name} `; - break; - case 'concerto.metamodel.ParticipantDeclaration': - result += `participant ${mm.name} `; - break; - case 'concerto.metamodel.TransactionDeclaration': - result += `transaction ${mm.name} `; - break; - case 'concerto.metamodel.EnumDeclaration': - result += `enum ${mm.name} `; - break; + break; + case 'concerto.metamodel.LongProperty': + result += ' Long'; + if (mm.defaultValue) { + defaultString += ` default=${mm.defaultValue.toString()}`; } - if (mm.superType) { - result += `extends ${mm.superType.name} `; + if (mm.validator) { + const lowerString = mm.validator.lower ? mm.validator.lower : ''; + const upperString = mm.validator.upper ? mm.validator.upper : ''; + validatorString += ` range=[${lowerString},${upperString}]`; } - // XXX Needs to be fixed to support `identified` - if (mm.identified) { - if (mm.identified.$class === 'concerto.metamodel.IdentifiedBy') { - result += `identified by ${mm.identified.name} `; - } else { - result += 'identified '; - } + break; + case 'concerto.metamodel.StringProperty': + result += ' String'; + if (mm.defaultValue) { + defaultString += ` default="${mm.defaultValue}"`; } - result += '{'; - mm.properties.forEach((property) => { - result += `\n ${MetaModel.propertyFromMetaModel(property)}`; - }); - result += '\n}'; - return result; - } - - /** - * Create a model string from a metamodel - * @param {object} metaModel - the metamodel - * @param {boolean} [validate] - whether to perform validation - * @return {string} the string for that model - */ - static ctoFromMetaModel(metaModel, validate = true) { - // First, validate the JSON metaModel - const mm = validate ? MetaModel.validateMetaModel(metaModel) : metaModel; - - let result = ''; - result += `namespace ${mm.namespace}`; - if (mm.imports && mm.imports.length > 0) { - result += '\n'; - mm.imports.forEach((imp) => { - let name = '*'; - if (imp.$class === 'concerto.metamodel.ImportType') { - name = imp.name; - } - result += `\nimport ${imp.namespace}.${name}`; - if (imp.uri) { - result += ` from ${imp.uri}`; - } - }); + if (mm.validator) { + validatorString += ` regex=${mm.validator.regex}`; } - if (mm.declarations && mm.declarations.length > 0) { - mm.declarations.forEach((decl) => { - result += `\n\n${MetaModel.declFromMetaModel(decl)}`; - }); + break; + case 'concerto.metamodel.ObjectProperty': + result += ` ${mm.type.name}`; + if (mm.defaultValue) { + defaultString += ` default="${mm.defaultValue}"`; } - return result; + break; + case 'concerto.metamodel.RelationshipProperty': + result += ` ${mm.type.name}`; + break; } + if (mm.isArray) { + result += '[]'; + } + result += ` ${mm.name}`; + if (mm.isOptional) { + result += ' optional'; + } + result += defaultString; + result += validatorString; + return result; +} - /** - * Import metamodel to a model manager - * @param {object} metaModel - the metamodel - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model manager - */ - static modelManagerFromMetaModel(metaModel, validate) { - // First, validate the JSON metaModel - const mm = validate ? MetaModel.validateMetaModel(metaModel) : metaModel; - - const modelManager = new ModelManager(); - - mm.models.forEach((mm) => { - const cto = MetaModel.ctoFromMetaModel(mm, false); // No need to re-validate - modelManager.addModelFile(cto, null, false); - }); - - modelManager.validateModelFiles(); - return modelManager; +/** + * Create a declaration string from a metamodel + * @param {object} mm - the metamodel + * @return {string} the string for that declaration + */ +function declFromMetaModel(mm) { + let result = ''; + if (mm.decorators) { + result += decoratorsFromMetaModel(mm.decorators, ''); } - /** - * Export metamodel from a model string - * @param {string} model - the string for the model - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model - */ - static ctoToMetaModel(model, validate) { - const ast = parser.parse(model); - return MetaModel.modelToMetaModel(ast); + if (mm.isAbstract) { + result += 'abstract '; + } + switch (mm.$class) { + case 'concerto.metamodel.AssetDeclaration': + result += `asset ${mm.name} `; + break; + case 'concerto.metamodel.ConceptDeclaration': + result += `concept ${mm.name} `; + break; + case 'concerto.metamodel.EventDeclaration': + result += `event ${mm.name} `; + break; + case 'concerto.metamodel.ParticipantDeclaration': + result += `participant ${mm.name} `; + break; + case 'concerto.metamodel.TransactionDeclaration': + result += `transaction ${mm.name} `; + break; + case 'concerto.metamodel.EnumDeclaration': + result += `enum ${mm.name} `; + break; + } + if (mm.superType) { + result += `extends ${mm.superType.name} `; } + // XXX Needs to be fixed to support `identified` + if (mm.identified) { + if (mm.identified.$class === 'concerto.metamodel.IdentifiedBy') { + result += `identified by ${mm.identified.name} `; + } else { + result += 'identified '; + } + } + result += '{'; + mm.properties.forEach((property) => { + result += `\n ${propertyFromMetaModel(property)}`; + }); + result += '\n}'; + return result; +} - /** - * Export metamodel from a model string and resolve names - * @param {*} modelManager - the model manager - * @param {string} model - the string for the model - * @param {boolean} [validate] - whether to perform validation - * @return {object} the metamodel for this model - */ - static ctoToMetaModelAndResolve(modelManager, model, validate) { - const ast = parser.parse(model); - const metaModel = MetaModel.modelToMetaModel(ast); - const result = MetaModel.resolveMetaModel(modelManager, metaModel); - return result; +/** + * Create a model string from a metamodel + * @param {object} metaModel - the metamodel + * @param {boolean} [validate] - whether to perform validation + * @return {string} the string for that model + */ +function ctoFromMetaModel(metaModel, validate = true) { + // First, validate the JSON metaModel + const mm = validate ? validateMetaModel(metaModel) : metaModel; + + let result = ''; + result += `namespace ${mm.namespace}`; + if (mm.imports && mm.imports.length > 0) { + result += '\n'; + mm.imports.forEach((imp) => { + let name = '*'; + if (imp.$class === 'concerto.metamodel.ImportType') { + name = imp.name; + } + result += `\nimport ${imp.namespace}.${name}`; + if (imp.uri) { + result += ` from ${imp.uri}`; + } + }); } + if (mm.declarations && mm.declarations.length > 0) { + mm.declarations.forEach((decl) => { + result += `\n\n${declFromMetaModel(decl)}`; + }); + } + return result; +} + +/** + * Import metamodel to a model manager + * @param {object} metaModel - the metamodel + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model manager + */ +function modelManagerFromMetaModel(metaModel, validate) { + // First, validate the JSON metaModel + const mm = validate ? validateMetaModel(metaModel) : metaModel; + + const modelManager = new ModelManager(); + + mm.models.forEach((mm) => { + const cto = ctoFromMetaModel(mm, false); // No need to re-validate + modelManager.addModelFile(cto, null, false); + }); + + modelManager.validateModelFiles(); + return modelManager; +} + +/** + * Export metamodel from a model string + * @param {string} model - the string for the model + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model + */ +function ctoToMetaModel(model, validate) { + const ast = parser.parse(model); + return modelToMetaModel(ast); +} + +/** + * Export metamodel from a model string and resolve names + * @param {*} modelManager - the model manager + * @param {string} model - the string for the model + * @param {boolean} [validate] - whether to perform validation + * @return {object} the metamodel for this model + */ +function ctoToMetaModelAndResolve(modelManager, model, validate) { + const ast = parser.parse(model); + const metaModel = modelToMetaModel(ast); + const result = resolveMetaModel(modelManager, metaModel); + return result; } -module.exports = MetaModel; +module.exports = { + metaModelCto, + modelFileToMetaModel, + modelManagerToMetaModel, + modelManagerFromMetaModel, + resolveMetaModel, + ctoToMetaModel, + ctoToMetaModelAndResolve, + ctoFromMetaModel, +}; \ No newline at end of file diff --git a/packages/concerto-core/lib/introspect/modelfile.js b/packages/concerto-core/lib/introspect/modelfile.js index c698494431..4f69ee7c21 100644 --- a/packages/concerto-core/lib/introspect/modelfile.js +++ b/packages/concerto-core/lib/introspect/modelfile.js @@ -55,7 +55,6 @@ class ModelFile { this.importWildcardNamespaces = []; this.importUriMap = {}; this.fileName = 'UNKNOWN'; - this._isModelFile = true; this.concertoVersion = null; if(!definitions || typeof definitions !== 'string') { @@ -97,6 +96,14 @@ class ModelFile { } } + /** + * Returns true + * @returns {boolean} true + */ + isModelFile() { + return true; + } + /** * Returns true if the ModelFile is a system namespace * @returns {Boolean} true if this is a system model file @@ -405,7 +412,7 @@ class ModelFile { */ getAssetDeclaration(name) { let classDeclaration = this.getLocalType(name); - if(classDeclaration instanceof AssetDeclaration) { + if(classDeclaration && classDeclaration.isAsset()) { return classDeclaration; } @@ -419,7 +426,7 @@ class ModelFile { */ getTransactionDeclaration(name) { let classDeclaration = this.getLocalType(name); - if(classDeclaration instanceof TransactionDeclaration) { + if(classDeclaration && classDeclaration.isTransaction()) { return classDeclaration; } @@ -433,7 +440,7 @@ class ModelFile { */ getEventDeclaration(name) { let classDeclaration = this.getLocalType(name); - if(classDeclaration instanceof EventDeclaration) { + if(classDeclaration && classDeclaration.isEvent()) { return classDeclaration; } @@ -447,7 +454,7 @@ class ModelFile { */ getParticipantDeclaration(name) { let classDeclaration = this.getLocalType(name); - if(classDeclaration instanceof ParticipantDeclaration) { + if(classDeclaration && classDeclaration.isParticipant()) { return classDeclaration; } @@ -648,17 +655,6 @@ class ModelFile { } } } - - /** - * Alternative to instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a ModelFile - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isModelFile); - } } module.exports = ModelFile; diff --git a/packages/concerto-core/lib/introspect/participantdeclaration.js b/packages/concerto-core/lib/introspect/participantdeclaration.js index d9cb4426ed..16928b083d 100644 --- a/packages/concerto-core/lib/introspect/participantdeclaration.js +++ b/packages/concerto-core/lib/introspect/participantdeclaration.js @@ -32,18 +32,6 @@ class ParticipantDeclaration extends IdentifiedDeclaration { */ constructor(modelFile, ast) { super(modelFile, ast); - this._isParticipantDeclaration = true; - } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a ParticipantDeclaration - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isParticipantDeclaration); } } diff --git a/packages/concerto-core/lib/introspect/property.js b/packages/concerto-core/lib/introspect/property.js index 3a87f78ac8..89e0e03ee1 100644 --- a/packages/concerto-core/lib/introspect/property.js +++ b/packages/concerto-core/lib/introspect/property.js @@ -35,7 +35,6 @@ class Property extends Decorated { super(parent.getModelFile(), ast); this.parent = parent; this.process(); - this._isProperty = true; } /** @@ -191,17 +190,6 @@ class Property extends Decorated { isPrimitive() { return ModelUtil.isPrimitiveType(this.getType()); } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a Property - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isProperty); - } } module.exports = Property; diff --git a/packages/concerto-core/lib/introspect/relationshipdeclaration.js b/packages/concerto-core/lib/introspect/relationshipdeclaration.js index d6a287cb41..f2f5addfdf 100644 --- a/packages/concerto-core/lib/introspect/relationshipdeclaration.js +++ b/packages/concerto-core/lib/introspect/relationshipdeclaration.js @@ -35,7 +35,6 @@ class RelationshipDeclaration extends Property { */ constructor(parent, ast) { super(parent, ast); - this._isRelationshipDeclaration = true; } /** @@ -94,14 +93,12 @@ class RelationshipDeclaration extends Property { } /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 + * Returns true if this class is the definition of a relationship. * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a RelationshipDeclaration + * @return {boolean} true if the class is a relationship */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isRelationshipDeclaration); + isRelationship() { + return true; } } diff --git a/packages/concerto-core/lib/introspect/transactiondeclaration.js b/packages/concerto-core/lib/introspect/transactiondeclaration.js index 3ed5d66814..5b4c5613d8 100644 --- a/packages/concerto-core/lib/introspect/transactiondeclaration.js +++ b/packages/concerto-core/lib/introspect/transactiondeclaration.js @@ -32,18 +32,6 @@ class TransactionDeclaration extends IdentifiedDeclaration { */ constructor(modelFile, ast) { super(modelFile, ast); - this._isTransactionDeclaration = true; - } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a TransactionDeclaration - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isTransactionDeclaration); } } diff --git a/packages/concerto-core/lib/model/typed.js b/packages/concerto-core/lib/model/typed.js index bdd900e890..10a2d5aeb1 100644 --- a/packages/concerto-core/lib/model/typed.js +++ b/packages/concerto-core/lib/model/typed.js @@ -14,7 +14,6 @@ 'use strict'; -const Field = require('../introspect/field'); const dayjs = require('dayjs'); const utc = require('dayjs/plugin/utc'); dayjs.extend(utc); @@ -135,7 +134,7 @@ class Typed { for (let n = 0; n < fields.length; n++) { let field = fields[n]; - if (field instanceof Field) { + if (field.isField?.()) { let defaultValue = field.getDefaultValue(); if (defaultValue) { diff --git a/packages/concerto-core/lib/modelmanager.js b/packages/concerto-core/lib/modelmanager.js index 2f82bbb4bf..f560ed84be 100644 --- a/packages/concerto-core/lib/modelmanager.js +++ b/packages/concerto-core/lib/modelmanager.js @@ -56,10 +56,17 @@ class ModelManager { this.factory = new Factory(this); this.serializer = new Serializer(this.factory, this, options); this.decoratorFactories = []; - this._isModelManager = true; this.addRootModel(); } + /** + * Returns true + * @returns {boolean} true + */ + isModelManager() { + return true; + } + /** * Adds root types * @private @@ -613,17 +620,6 @@ abstract concept Event {} } return false; } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a ModelManager - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isModelManager); - } } module.exports = ModelManager; diff --git a/packages/concerto-core/lib/serializer.js b/packages/concerto-core/lib/serializer.js index 1b44ca2b86..75ccac867d 100644 --- a/packages/concerto-core/lib/serializer.js +++ b/packages/concerto-core/lib/serializer.js @@ -14,16 +14,12 @@ 'use strict'; -const EventDeclaration = require('./introspect/eventdeclaration'); -const ConceptDeclaration = require('./introspect/conceptdeclaration'); -const EnumDeclaration = require('./introspect/enumdeclaration'); const DateTimeUtil = require('./datetimeutil'); const Globalize = require('./globalize'); const JSONGenerator = require('./serializer/jsongenerator'); const JSONPopulator = require('./serializer/jsonpopulator'); const Typed = require('./model/typed'); const ResourceValidator = require('./serializer/resourcevalidator'); -const TransactionDeclaration = require('./introspect/transactiondeclaration'); const TypedStack = require('./serializer/typedstack'); const { utcOffset: defaultUtcOffset } = DateTimeUtil.setCurrentTime(); @@ -57,7 +53,6 @@ class Serializer { this.factory = factory; this.modelManager = modelManager; this.defaultOptions = Object.assign({}, baseDefaultOptions, options || {}); - this._isSerializer = true; } /** @@ -162,19 +157,19 @@ class Serializer { // create a new instance, using the identifier field name as the ID. let resource; - if (classDeclaration instanceof TransactionDeclaration) { + if (classDeclaration.isTransaction()) { resource = this.factory.newTransaction(classDeclaration.getNamespace(), classDeclaration.getName(), jsonObject[classDeclaration.getIdentifierFieldName()] ); - } else if (classDeclaration instanceof EventDeclaration) { + } else if (classDeclaration.isEvent()) { resource = this.factory.newEvent(classDeclaration.getNamespace(), classDeclaration.getName(), jsonObject[classDeclaration.getIdentifierFieldName()] ); - } else if (classDeclaration instanceof ConceptDeclaration) { + } else if (classDeclaration.isConcept()) { resource = this.factory.newConcept(classDeclaration.getNamespace(), classDeclaration.getName(), jsonObject[classDeclaration.getIdentifierFieldName()] ); - } else if (classDeclaration instanceof EnumDeclaration) { + } else if (classDeclaration.isEnum()) { throw new Error('Attempting to create an ENUM declaration is not supported.'); } else { resource = this.factory.newResource( classDeclaration.getNamespace(), @@ -199,17 +194,6 @@ class Serializer { return resource; } - - /** - * Alternative instanceof that is reliable across different module instances - * @see https://github.com/hyperledger/composer-concerto/issues/47 - * - * @param {object} object - The object to test against - * @returns {boolean} - True, if the object is an instance of a Serializer - */ - static [Symbol.hasInstance](object){ - return typeof object !== 'undefined' && object !== null && Boolean(object._isSerializer); - } } module.exports = Serializer; diff --git a/packages/concerto-core/lib/serializer/instancegenerator.js b/packages/concerto-core/lib/serializer/instancegenerator.js index 91708c9941..2a59cf79bc 100644 --- a/packages/concerto-core/lib/serializer/instancegenerator.js +++ b/packages/concerto-core/lib/serializer/instancegenerator.js @@ -14,11 +14,7 @@ 'use strict'; -const ClassDeclaration = require('../introspect/classdeclaration'); -const EnumDeclaration = require('../introspect/enumdeclaration'); -const Field = require('../introspect/field'); const ModelUtil = require('../modelutil'); -const RelationshipDeclaration = require('../introspect/relationshipdeclaration'); const Util = require('../util'); const Globalize = require('../globalize'); @@ -40,11 +36,11 @@ class InstanceGenerator { * @private */ visit(thing, parameters) { - if (thing instanceof ClassDeclaration) { + if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); } else { throw new Error('Unrecognised ' + JSON.stringify(thing) ); @@ -151,7 +147,7 @@ class InstanceGenerator { let classDeclaration = parameters.modelManager.getType(type); - if (classDeclaration instanceof EnumDeclaration) { + if (classDeclaration.isEnum()) { let enumValues = classDeclaration.getOwnProperties(); return parameters.valueGenerator.getEnum(enumValues).getName(); } diff --git a/packages/concerto-core/lib/serializer/jsongenerator.js b/packages/concerto-core/lib/serializer/jsongenerator.js index cc1ce3edbb..f260bf4d6a 100644 --- a/packages/concerto-core/lib/serializer/jsongenerator.js +++ b/packages/concerto-core/lib/serializer/jsongenerator.js @@ -14,9 +14,6 @@ 'use strict'; -const ClassDeclaration = require('../introspect/classdeclaration'); -const Field = require('../introspect/field'); -const RelationshipDeclaration = require('../introspect/relationshipdeclaration'); const Resource = require('../model/resource'); const Typed = require('../model/typed'); const ModelUtil = require('../modelutil'); @@ -65,11 +62,11 @@ class JSONGenerator { * @private */ visit(thing, parameters) { - if (thing instanceof ClassDeclaration) { + if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); } else { throw new Error('Unrecognised ' + JSON.stringify(thing)); diff --git a/packages/concerto-core/lib/serializer/jsonpopulator.js b/packages/concerto-core/lib/serializer/jsonpopulator.js index 5db13ed9e2..a8f25976d7 100644 --- a/packages/concerto-core/lib/serializer/jsonpopulator.js +++ b/packages/concerto-core/lib/serializer/jsonpopulator.js @@ -14,9 +14,6 @@ 'use strict'; -const ClassDeclaration = require('../introspect/classdeclaration'); -const Field = require('../introspect/field'); -const RelationshipDeclaration = require('../introspect/relationshipdeclaration'); const Relationship = require('../model/relationship'); const Util = require('../util'); const ModelUtil = require('../modelutil'); @@ -104,11 +101,11 @@ class JSONPopulator { * @private */ visit(thing, parameters) { - if (thing instanceof ClassDeclaration) { + if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); } else { throw new Error('Unrecognised ' + JSON.stringify(thing) ); diff --git a/packages/concerto-core/lib/serializer/objectvalidator.js b/packages/concerto-core/lib/serializer/objectvalidator.js index 17ad35eeb8..473a24fe0b 100644 --- a/packages/concerto-core/lib/serializer/objectvalidator.js +++ b/packages/concerto-core/lib/serializer/objectvalidator.js @@ -14,10 +14,6 @@ 'use strict'; -const ClassDeclaration = require('../introspect/classdeclaration'); -const Field = require('../introspect/field'); -const RelationshipDeclaration = require('../introspect/relationshipdeclaration'); -const EnumDeclaration = require('../introspect/enumdeclaration'); const Util = require('../util'); const ModelUtil = require('../modelutil'); const ValidationException = require('./validationexception'); @@ -72,13 +68,13 @@ class ObjectValidator { * @private */ visit(thing, parameters) { - if (thing instanceof EnumDeclaration) { + if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); } } diff --git a/packages/concerto-core/lib/serializer/resourcevalidator.js b/packages/concerto-core/lib/serializer/resourcevalidator.js index 0a8319da97..d55b98b07e 100644 --- a/packages/concerto-core/lib/serializer/resourcevalidator.js +++ b/packages/concerto-core/lib/serializer/resourcevalidator.js @@ -14,10 +14,6 @@ 'use strict'; -const ClassDeclaration = require('../introspect/classdeclaration'); -const Field = require('../introspect/field'); -const RelationshipDeclaration = require('../introspect/relationshipdeclaration'); -const EnumDeclaration = require('../introspect/enumdeclaration'); const Relationship = require('../model/relationship'); const Resource = require('../model/resource'); const Identifiable = require('../model/identifiable'); @@ -67,13 +63,13 @@ class ResourceValidator { * @private */ visit(thing, parameters) { - if (thing instanceof EnumDeclaration) { + if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); } } diff --git a/packages/concerto-core/package.json b/packages/concerto-core/package.json index a448b667ac..4d907801df 100644 --- a/packages/concerto-core/package.json +++ b/packages/concerto-core/package.json @@ -20,7 +20,8 @@ "test": "node ./scripts/api-changelog.js && nyc mocha --recursive -t 10000", "test:watch": "nyc mocha --watch --recursive -t 10000", "mocha": "mocha --recursive -t 10000", - "nyc": "nyc mocha --recursive -t 10000" + "nyc": "nyc mocha --recursive -t 10000", + "build:types" : "npx -p typescript tsc lib/**/*.js index.js --declaration --allowJs --emitDeclarationOnly --outDir types" }, "repository": { "type": "git", diff --git a/packages/concerto-core/test/introspect/assetdeclaration.js b/packages/concerto-core/test/introspect/assetdeclaration.js index a16a074d81..5b49040018 100644 --- a/packages/concerto-core/test/introspect/assetdeclaration.js +++ b/packages/concerto-core/test/introspect/assetdeclaration.js @@ -154,17 +154,6 @@ describe('AssetDeclaration', () => { let asset = loadAssetDeclaration('test/data/parser/assetdeclaration.resolve.cto'); (asset instanceof AssetDeclaration).should.be.true; }); - - it('should return true for a valid Asset Declaration using a different module instance', () => { - /* eslint-disable require-jsdoc */ - class MyAssetDeclaration { - constructor(){ - this._isAssetDeclaration = true; - } - } - const asset = new MyAssetDeclaration(); - (asset instanceof AssetDeclaration).should.be.true; - }); }); }); diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index befa94de23..2a17da2c5d 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -168,6 +168,95 @@ describe('ClassDeclaration', () => { }); + describe('#isXYZ', () => { + + it('should return true for concepts', () => { + let clz = new ClassDeclaration(modelFile, { + id: { + name: 'suchName' + }, + type: 'ConceptDeclaration', + body: { + declarations: [ + ] + } + }); + clz.isConcept().should.equal(true); + }); + + it('should return true for assets', () => { + let clz = new ClassDeclaration(modelFile, { + id: { + name: 'suchName' + }, + type: 'AssetDeclaration', + body: { + declarations: [ + ] + } + }); + clz.isAsset().should.equal(true); + }); + + it('should return true for events', () => { + let clz = new ClassDeclaration(modelFile, { + id: { + name: 'suchName' + }, + type: 'EventDeclaration', + body: { + declarations: [ + ] + } + }); + clz.isEvent().should.equal(true); + }); + + it('should return true for participants', () => { + let clz = new ClassDeclaration(modelFile, { + id: { + name: 'suchName' + }, + type: 'ParticipantDeclaration', + body: { + declarations: [ + ] + } + }); + clz.isParticipant().should.equal(true); + }); + + it('should return true for enums', () => { + let clz = new ClassDeclaration(modelFile, { + id: { + name: 'suchName' + }, + type: 'EnumDeclaration', + body: { + declarations: [ + ] + } + }); + clz.isEnum().should.equal(true); + }); + + it('should return true for transactions', () => { + let clz = new ClassDeclaration(modelFile, { + id: { + name: 'suchName' + }, + type: 'TransactionDeclaration', + body: { + declarations: [ + ] + } + }); + clz.isTransaction().should.equal(true); + clz.isAsset().should.equal(false); + }); + }); + + describe('#getFullyQualifiedName', () => { it('should return the fully qualified name if function is in a namespace', () => { diff --git a/packages/concerto-core/test/introspect/enumdeclaration.js b/packages/concerto-core/test/introspect/enumdeclaration.js index 34be6a2845..c93aa6b4bc 100644 --- a/packages/concerto-core/test/introspect/enumdeclaration.js +++ b/packages/concerto-core/test/introspect/enumdeclaration.js @@ -15,7 +15,6 @@ 'use strict'; const EnumDeclaration = require('../../lib/introspect/enumdeclaration'); -const EnumValueDeclaration = require('../../lib/introspect/enumvaluedeclaration'); const ModelFile = require('../../lib/introspect/modelfile'); const ModelManager = require('../../lib/modelmanager'); const fs = require('fs'); @@ -67,13 +66,13 @@ describe('EnumDeclaration', () => { }); }); - describe('#hasInstance', () => { + describe('#isEnum and isEnumValue', () => { it('should return true for a valid Enum Declaration', () => { let declaration = loadLastDeclaration('test/data/model/enum.cto', EnumDeclaration); - (declaration instanceof EnumDeclaration).should.be.true; + (declaration.isEnum()).should.be.true; let value = declaration.getProperties(); - (value[0] instanceof EnumValueDeclaration).should.be.true; + (value[0].isEnumValue()).should.be.true; }); }); }); diff --git a/packages/concerto-core/test/modelmanager.js b/packages/concerto-core/test/modelmanager.js index b461a0a26a..d068f0ce61 100644 --- a/packages/concerto-core/test/modelmanager.js +++ b/packages/concerto-core/test/modelmanager.js @@ -59,6 +59,12 @@ describe('ModelManager', () => { sandbox.restore(); }); + describe('#isModelManager', () => { + it('should return true', () => { + modelManager.isModelManager().should.be.true; + }); + }); + describe('#accept', () => { it('should call the visitor', () => { diff --git a/packages/concerto-core/types/index.d.ts b/packages/concerto-core/types/index.d.ts index 3d3c88b02c..f399de55d4 100644 --- a/packages/concerto-core/types/index.d.ts +++ b/packages/concerto-core/types/index.d.ts @@ -1,458 +1,40 @@ -declare module '@accordproject/concerto-core' { - // Exceptions - interface FileLocation { - start: { - line: string; - column: string; - } - end: { - line: string; - column: string; - } - } - - export class BaseException extends Error { - constructor(message: string, component?: string); - } - - export class BaseFileException extends BaseException { - constructor(message: string, fileLocation?: string, fullMessage?: string, fileName?: string, component?: string); - getFileLocation(): string | null; - getShortMessage(): string; - getFileName(): string | null; - } - - export class ParseException extends BaseFileException { - constructor(message: string, fileLocation?: string, fileName?: string, fullMessageOverride?: string, component?: string); - } - - export class SecurityException extends BaseException { - constructor(message: string); - } - - export class IllegalModelException extends BaseFileException { - constructor(message: string, modelFile?: ModelFile, fileLocation?: FileLocation, component?: string); - getModelFile(): ModelFile | null; - } - - export class TypeNotFoundException extends BaseException { - constructor(typeName: string, message?: string, component?: string); - getTypeName(): string; - } - - // Decorated - class Decorated { - constructor(modelFile: ModelFile, ast: string); - getModelFile(): ModelFile; - private accept(visitor: any, parameters: any): any; - private process(): void; - private validate(): void; - getDecorators(): Decorator[]; - getDecorator(name: string): Decorator | null; - } - - export class Decorator { - constructor(parent: ClassDeclaration | Property, ast: any); - private accept(visitor: any, parameters: any): any; - getParent(): ClassDeclaration | Property; - private process(): void; - private validate(): void; - getName(): string; - getArguments(): any[]; - } - - export abstract class DecoratorFactory { - abstract newDecorator(parent: ClassDeclaration | Property, ast: any): Decorator; - } - - // ClassDeclarations - export abstract class ClassDeclaration extends Decorated { - constructor(modelFile: ModelFile, ast: any); - private process(): void; - private addTimestampField(): void; - private addIdentifierField(): void; - _resolveSuperType(): ClassDeclaration | null; - private validate(): void; - isAbstract(): boolean; - isEnum(): boolean; - isConcept(): boolean; - isEvent(): boolean; - getName(): string; - getNamespace(): string; - getFullyQualifiedName(): string; - isIdentified(): boolean; - isSystemIdentified(): boolean; - isExplicitlyIdentified(): boolean; - getIdentifierFieldName(): string | null; - getOwnProperty(name: string): Property | null; - getOwnProperties(): Property[]; - getSuperType(): string | null; - getSuperTypeDeclaration(): ClassDeclaration | null; - getAssignableClassDeclarations(): ClassDeclaration[]; - getAllSuperTypeDeclarations(): ClassDeclaration[]; - getProperty(name: string): Property | null; - getProperties(): Property[]; - getNestedProperty(propertyPath: string): Property; - toString(): string; - static [Symbol.hasInstance](object: any): boolean; - } - - export class IdentifiedDeclaration extends ClassDeclaration { } - - export class AssetDeclaration extends IdentifiedDeclaration { } - - export class ConceptDeclaration extends ClassDeclaration { } - - export class EnumDeclaration extends ClassDeclaration { } - - export class EventDeclaration extends IdentifiedDeclaration { } - - export class ParticipantDeclaration extends IdentifiedDeclaration { } - - export class TransactionDeclaration extends IdentifiedDeclaration { } - - // Properties - export class Property extends Decorated { - constructor(parent: ClassDeclaration, ast: any); - getParent(): ClassDeclaration; - private process(): void; - private validate(classDecl?: ClassDeclaration): void; - getName(): string; - getType(): string; - isOptional(): boolean; - getFullyQualifiedTypeName(): string; - getFullyQualifiedName(): string; - getNamespace(): string; - isArray(): boolean; - isTypeEnum(): boolean; - isPrimitive(): boolean; - static [Symbol.hasInstance](object: any): boolean; - } - - export class Field extends Property { - getValidator(): string | null; - getDefaultValue(): string | null; - toString(): string; - } - - export class EnumValueDeclaration extends Property { } - - export class RelationshipDeclaration extends Property { - toString(): string; - } - - // Typed - export abstract class Typed { - constructor(modelManager: ModelManager, classDeclaration: ClassDeclaration, ns: string, type: string); - private accept(visitor: any, parameters: any): any; - private getModelManager(): ModelManager; - getType(): string; - getFullyQualifiedType(): string; - getNamespace(): string; - private getClassDeclaration(): ClassDeclaration; - setPropertyValue(propName: string, value: string): void; - addArrayValue(propName: string, value: string): void; - private assignFieldDefaults(): void; - instanceOf(fqt: string): boolean; - private toJSON(): any; - [propertyName: string]: any; - } - - // Identifiables - abstract class Identifiable extends Typed { - constructor(modelManager: ModelManager, classDeclaration: ClassDeclaration, ns: string, type: string, id: string, timestamp: string); - getTimestamp(): string; - getIdentifier(): string; - setIdentifier(id: string): void; - getFullyQualifiedIdentifier(): string; - toString(): string; - isRelationship(): boolean; - isResource(): boolean; - toURI(): string; - } - - export class Relationship extends Identifiable { - static fromURI(modelManager: ModelManager, uriAsstring: string, defaultNamespace?: string, defaultType?: string): Relationship; - } - - export class Resource extends Identifiable { - isConcept(): boolean; - isIdentifiable(): boolean; - } - - // Writers - export class Writer { - constructor(); - writeBeforeLine(tabs: number, text: string): void; - writeLine(tabs: number, text: string): void; - getLineCount(): number; - writeIndented(tabs: number, text: string): void; - write(msg: string): void; - getBuffer(): string; - clearBuffer(): void; - } - - // Factory - interface NewResourceOptions { - disableValidation?: boolean; - generate?: string; - includeOptionalFields?: boolean; - } - - interface NewConceptOptions { - disableValidation?: boolean; - generate?: string; - includeOptionalFields?: boolean; - } - - interface NewTransactionOptions { - generate?: string; - includeOptionalFields?: boolean; - } - - interface NewEventOptions { - generate?: string; - includeOptionalFields?: boolean; - } - - export class Factory { - static newId(): string; - constructor(modelManager: ModelManager); - newResource(ns: string, type: string, id: string, options?: NewResourceOptions): Resource; - newConcept(ns: string, type: string, id: string, options?: NewConceptOptions): Resource; - newRelationship(ns: string, type: string, id: string): Relationship; - newTransaction(ns: string, type: string, id?: string, options?: NewTransactionOptions): Resource; - newEvent(ns: string, type: string, id?: string, options?: NewEventOptions): Resource; - private initializeNewObject(newObject: Typed, classDeclaration: ClassDeclaration, clientOptions: any): void; - private parseGenerateOptions(clientOptions: any): any; - static [Symbol.hasInstance](object: any): boolean; - } - - // Globalize - export function Globalize(locale: string): any; - function messageFormatter(message: string): any; - function formatMessage(message: string): any; - - // Introspector - export class Introspector { - constructor(modelManager: ModelManager); - private accept(visitor: any, parameters: any): any; - getClassDeclarations(): ClassDeclaration[]; - getClassDeclaration(fullyQualifiedTypeName: string): ClassDeclaration; - private getModelManager(): ModelManager; - } - - // ModelFile - export class ModelFile { - constructor(modelManager: ModelManager, definitions: string, fileName?: string); - private fromAst(ast: any): void; - isSystemModelFile(): boolean; - isExternal(): boolean; - private getImportURI(namespace: string): string | null; - private getExternalImports(): any; - private accept(visitor: any, parameters: any): any; - getModelManager(): ModelManager; - getImports(): string[]; - private validate(): void; - private resolveType(context: string, type: string, fileLocation: FileLocation): void; - private isLocalType(type: string): boolean; - private isImportedType(type: string): boolean; - private resolveImport(type: string): string; - isDefined(type: string): boolean; - private getType(type: string): string | ClassDeclaration; - private getFullyQualifiedTypeName(type: string): string; - getLocalType(type: string): ClassDeclaration | null; - getAssetDeclaration(name: string): AssetDeclaration | null; - getTransactionDeclaration(name: string): TransactionDeclaration | null; - getEventDeclaration(name: string): EventDeclaration | null; - getParticipantDeclaration(name: string): ParticipantDeclaration | null; - getNamespace(): string; - getName(): string; - getAssetDeclarations(): AssetDeclaration[]; - getTransactionDeclarations(): TransactionDeclaration[]; - getEventDeclarations(): EventDeclaration[]; - getParticipantDeclarations(): ParticipantDeclaration[]; - getConceptDeclarations(): ConceptDeclaration[]; - getEnumDeclarations(): EnumDeclaration[]; - getDeclarations(type: (...params: any[]) => any): ClassDeclaration[]; - getAllDeclarations(): ClassDeclaration[]; - getDefinitions(): string; - getConcertoVersion(): string; - static [Symbol.hasInstance](object: any): boolean; - } - - // ModelManager - interface IncludeModelsOptions { - includeExternalModels: boolean; - includeSystemModels: boolean; - } - - export class ModelManager { - constructor(options?: any); - private addRootModel(): void; - accept(visitor: any, parameters: any): any; - validateModelFile(modelFile: string, fileName?: string): void; - private _throwAlreadyExists(modelFile: ModelFile): void; - addModelFile(modelFile: string, fileName?: string, disableValidation?: boolean): any; - updateModelFile(modelFile: string, fileName?: string, disableValidation?: boolean): any; - deleteModelFile(namespace: string): void; - addModelFiles(modelFiles: (string|ModelFile)[], fileNames?: string[], disableValidation?: boolean): any[]; - validateModelFiles(): void; - updateExternalModels(options?: any, modelFileDownloader?: ModelFileDownloader): Promise; - writeModelsToFileSystem(path: string, options?: IncludeModelsOptions): void; - private getModelFiles(): ModelFile[]; - private getSystemModelFiles(): ModelFile[]; - getModels(options?: IncludeModelsOptions): { name: string; content: string }[]; - private resolveType(context: string, type: string): string; - clearModelFiles(): void; - getModelFile(namespace: string): ModelFile | null; - private getModelFileByFileName(fileName: string): ModelFile | null; - getNamespaces(): string[]; - getType(qualifiedName: string): ClassDeclaration; - getSystemTypes(): ClassDeclaration[]; - getAssetDeclarations(): AssetDeclaration[]; - getTransactionDeclarations(): TransactionDeclaration[]; - getEventDeclarations(): EventDeclaration[]; - getParticipantDeclarations(): ParticipantDeclaration[]; - getEnumDeclarations(): EnumDeclaration[]; - getConceptDeclarations(): ConceptDeclaration[]; - getFactory(): Factory; - getSerializer(): Serializer; - getDecoratorFactories(): DecoratorFactory[]; - addDecoratorFactory(factory: DecoratorFactory): void; - derivesFrom(fqt1: string, fqt2: string): boolean; - static [Symbol.hasInstance](object: any): boolean; - } - - // Serializer - interface SerializerToJSONOptions { - validate?: boolean; - convertResourcesToRelationships?: boolean; - permitResourcesForRelationships?: boolean; - deduplicateResources?: boolean; - convertResourcesToId?: boolean; - utcOffset: number; - } - - interface SerializerFromJSONOptions { - acceptResourcesForRelationships: boolean; - validate: boolean; - utcOffset: number; - } - - export class Serializer { - constructor(factory: Factory, modelManager: ModelManager, options?: any); - setDefaultOptions(newDefaultOptions: any): void; - toJSON(resource: Resource, options?: SerializerToJSONOptions): any; - fromJSON(jsonObject: any, options?: SerializerFromJSONOptions): Resource; - static [Symbol.hasInstance](object: any): boolean; - } - - // ModelUtil - export class ModelUtil { - private static getShortName(fqn: string): string; - private static isWildcardName(fqn: string): boolean; - private static isRecursiveWildcardName(fqn: string): boolean; - private static isMatchingType(type: Typed, fqn: string): boolean; - private static getNamespace(fqn: string): string; - private static isPrimitiveType(typeName: string): boolean; - private static isAssignableTo(modelFile: ModelFile, typeName: string, property: Property): boolean; - private static capitalizeFirstLetter(string: string): string; - private static isEnum(field: Field): boolean; - static getFullyQualifiedName(namespace: string, type: string): string; - } - - // ModelFileLoaders - interface ModelFileLoader { - accepts(url: string): boolean; - load(url: string, options: any): Promise; - } - - class CompositeModelFileLoader implements ModelFileLoader { - constructor(); - addModelFileLoader(modelFileLoader: ModelFileLoader): void; - private getModelFileLoaders(): ModelFileLoader[]; - clearModelFileLoaders(): void; - accepts(url: string): boolean; - load(url: string, options: any): Promise; - } - - export class DefaultModelFileLoader extends CompositeModelFileLoader { - constructor(modelManager: ModelManager); - } - - export class ModelFileDownloader { - constructor(modelFileLoader: ModelFileLoader, concurrency: number); - downloadExternalDependencies(modelFiles: ModelFile[], options?: any): Promise; - runJob(job: any, modelFileLoader: ModelFileLoader): Promise; - } - - // ModelLoader - export class ModelLoader { - private addModel(modelFileLoader: ModelFileLoader, modelManager: ModelManager, ctoFile: string): ModelManager; - static loadModelManager(ctoFiles: string[], options?: any): Promise; - static loadModelManagerFromModelFiles(modelFiles: ModelFile[], fileNames?: string[], options?: any): Promise; - } - - // Logger - export class Logger { - private static dispatch(level, ...args: any[]): void; - private static add(transport: any): void; - private static error(...args: any[]): void; - private static info(...args: any[]): void; - private static log(...args: any[]): void; - private static http(...args: any[]): void; - private static verbose(...args:any[]): void; - private static debug(...args:any[]): void; - private static silly(...args:any[]): void; - level: string; - transports: any[]; - } - - // DateTimeUtil - interface CurrentTime { - currentTime: any, - utcOffset: number - } - - function setCurrentTime(currentTime?: string, utcOffset?: number): CurrentTime; - - // TypedStack - export class TypedStack { - constructor(resource: any); - push(obj: any, expectedType: any): void; - pop(expectedType: obj): any?; - peek(expectedType: obj): any?; - clear(): void; - } - - // Concerto - class Concerto { - constructor(modelManager: ModelManager); - validate(obj: any, options?: any): void; - getModelManager(): ModelManager; - isObject(obj: any): boolean; - getTypeDeclaration(obj: any): ClassDeclaration; - getIdentifier(obj: any): string; - isIdentifiable(obj: any): boolean; - isRelationship(obj: any): boolean; - setIdentifier(obj: any, id: string): any; - getFullyQualifiedIdentifier(obj: any): string; - toURI(obj: any): string; - fromURI(uri: string): any; - getType(obj: any): string; - getNamespace(obj: any): string; - } - - // MetaModel - export class MetaModel { - static metaModelCto: string; - static modelFileToMetaModel(modelFile: ModelFile, validate?: boolean): any; - static ctoToMetaModel(model: string, validate?: boolean): any; - static ctoToMetaModelAndResolve(modelManager: ModelManager, model: string, validate?: boolean) : any; - static ctoFromMetaModel(metaModel: any, validate?: boolean): string; - } - - // version - export const version: any; -} +export var BaseException: typeof import("./lib/baseexception"); +export var BaseFileException: typeof import("./lib/basefileexception"); +export var ParseException: typeof import("./lib/introspect/parseexception"); +export var SecurityException: typeof import("./lib/securityexception"); +export var IllegalModelException: typeof import("./lib/introspect/illegalmodelexception"); +export var TypeNotFoundException: typeof import("./lib/typenotfoundexception"); +export var Decorator: typeof import("./lib/introspect/decorator"); +export var DecoratorFactory: typeof import("./lib/introspect/decoratorfactory"); +export var ClassDeclaration: typeof import("./lib/introspect/classdeclaration"); +export var IdentifiedDeclaration: typeof import("./lib/introspect/identifieddeclaration"); +export var AssetDeclaration: typeof import("./lib/introspect/assetdeclaration"); +export var ConceptDeclaration: typeof import("./lib/introspect/conceptdeclaration"); +export var EnumValueDeclaration: typeof import("./lib/introspect/enumvaluedeclaration"); +export var EventDeclaration: typeof import("./lib/introspect/eventdeclaration"); +export var ParticipantDeclaration: typeof import("./lib/introspect/participantdeclaration"); +export var TransactionDeclaration: typeof import("./lib/introspect/transactiondeclaration"); +export var Property: typeof import("./lib/introspect/property"); +export var Field: typeof import("./lib/introspect/field"); +export var EnumDeclaration: typeof import("./lib/introspect/enumdeclaration"); +export var RelationshipDeclaration: typeof import("./lib/introspect/relationshipdeclaration"); +export var Typed: typeof import("./lib/model/typed"); +export var Identifiable: typeof import("./lib/model/identifiable"); +export var Relationship: typeof import("./lib/model/relationship"); +export var Resource: typeof import("./lib/model/resource"); +export var Writer: typeof import("./lib/writer"); +export var Factory: typeof import("./lib/factory"); +export var Globalize: typeof import("./lib/globalize"); +export var Introspector: typeof import("./lib/introspect/introspector"); +export var ModelFile: typeof import("./lib/introspect/modelfile"); +export var ModelManager: typeof import("./lib/modelmanager"); +export var Serializer: typeof import("./lib/serializer"); +export var ModelUtil: typeof import("./lib/modelutil"); +export var DefaultModelFileLoader: typeof import("./lib/introspect/loaders/defaultmodelfileloader"); +export var ModelLoader: typeof import("./lib/modelloader"); +export var DateTimeUtil: typeof import("./lib/datetimeutil"); +export var Logger: typeof import("./lib/logger"); +export var TypedStack: typeof import("./lib/serializer/typedstack"); +export var Concerto: typeof import("./lib/concerto"); +export var MetaModel: typeof import("./lib/introspect/metamodel"); +export var version: any; diff --git a/packages/concerto-core/types/tsconfig.json b/packages/concerto-core/types/tsconfig.json deleted file mode 100644 index 45f43b41a0..0000000000 --- a/packages/concerto-core/types/tsconfig.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "compilerOptions": { - "removeComments": false, - "preserveConstEnums": true, - "sourceMap": true, - "declaration": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "suppressImplicitAnyIndexErrors": true, - "moduleResolution": "node", - "module": "commonjs", - "target": "es6", - "outDir": "dist", - "baseUrl": ".", - "paths": { - "*": [ - "node_modules/*" - ] - } - }, - "files": [ - "index.d.ts" - ], - "formatCodeOptions": { - "indentSize": 4, - "tabSize": 4 - } -} \ No newline at end of file diff --git a/packages/concerto-tools/lib/codegen/fromcto/csharp/csharpvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/csharp/csharpvisitor.js index 4368a8b40e..bb61fe98a3 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/csharp/csharpvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/csharp/csharpvisitor.js @@ -42,19 +42,19 @@ class CSharpVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationship(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { diff --git a/packages/concerto-tools/lib/codegen/fromcto/golang/golangvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/golang/golangvisitor.js index db389beaa1..2c31628576 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/golang/golangvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/golang/golangvisitor.js @@ -45,25 +45,25 @@ class GoLangVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof AssetDeclaration) { + } else if (thing.isAsset?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof TransactionDeclaration) { + } else if (thing.isTransaction?.()) { // return this.visitTransactionDeclaration(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ConceptDeclaration) { + } else if (thing.isConcept?.()) { //return this.visitConceptDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { // return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: null })); diff --git a/packages/concerto-tools/lib/codegen/fromcto/graphql/graphqlvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/graphql/graphqlvisitor.js index a461a83fdb..646f2d6c7e 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/graphql/graphqlvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/graphql/graphqlvisitor.js @@ -51,17 +51,17 @@ class GraphQLVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationship(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); } else { diff --git a/packages/concerto-tools/lib/codegen/fromcto/java/javavisitor.js b/packages/concerto-tools/lib/codegen/fromcto/java/javavisitor.js index 67cae99087..7873c97bdc 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/java/javavisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/java/javavisitor.js @@ -50,19 +50,19 @@ class JavaVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationship(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: 2 })); diff --git a/packages/concerto-tools/lib/codegen/fromcto/jsonschema/jsonschemavisitor.js b/packages/concerto-tools/lib/codegen/fromcto/jsonschema/jsonschemavisitor.js index 67d2a9e033..69251334b2 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/jsonschema/jsonschemavisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/jsonschema/jsonschemavisitor.js @@ -88,25 +88,25 @@ class JSONSchemaVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof AssetDeclaration) { + } else if (thing.isAsset?.()) { return this.visitAssetDeclaration(thing, parameters); - } else if (thing instanceof TransactionDeclaration) { + } else if (thing.isTransaction?.()) { return this.visitTransactionDeclaration(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ConceptDeclaration) { + } else if (thing.isConcept?.()) { return this.visitConceptDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: null })); diff --git a/packages/concerto-tools/lib/codegen/fromcto/jsonschema/recursionvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/jsonschema/recursionvisitor.js index c884f78c41..b3d1a46bf9 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/jsonschema/recursionvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/jsonschema/recursionvisitor.js @@ -44,14 +44,14 @@ class RecursionDetectionVisitor { */ visit(thing, parameters) { // the order of these matters! - if (thing instanceof EnumDeclaration) { + if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); } - else if (thing instanceof ClassDeclaration) { + else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); } else { throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: null })); diff --git a/packages/concerto-tools/lib/codegen/fromcto/loopback/loopbackvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/loopback/loopbackvisitor.js index a5dd8b20cf..4a201c3e87 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/loopback/loopbackvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/loopback/loopbackvisitor.js @@ -66,27 +66,27 @@ class LoopbackVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof AssetDeclaration) { + } else if (thing.isAsset?.()) { return this.visitAssetDeclaration(thing, parameters); - } else if (thing instanceof ParticipantDeclaration) { + } else if (thing.isParticipant?.()) { return this.visitParticipantDeclaration(thing, parameters); - } else if (thing instanceof ConceptDeclaration) { + } else if (thing.isConcept?.()) { return this.visitConceptDeclaration(thing, parameters); - } else if (thing instanceof TransactionDeclaration) { + } else if (thing.isTransaction?.()) { return this.visitTransactionDeclaration(thing, parameters); - } else if (thing instanceof EventDeclaration) { + } else if (thing.isEvent?.()) { return this.visitEventDeclaration(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationshipDeclaration(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: 1 })); diff --git a/packages/concerto-tools/lib/codegen/fromcto/plantuml/plantumlvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/plantuml/plantumlvisitor.js index 4745efd3e7..10640915f7 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/plantuml/plantumlvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/plantuml/plantumlvisitor.js @@ -45,25 +45,25 @@ class PlantUMLVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof ParticipantDeclaration) { + } else if (thing.isParticipant?.()) { return this.visitParticipantDeclaration(thing, parameters); - } else if (thing instanceof TransactionDeclaration) { + } else if (thing.isTransaction?.()) { return this.visitTransactionDeclaration(thing, parameters); - } else if (thing instanceof AssetDeclaration) { + } else if (thing.isAsset?.()) { return this.visitAssetDeclaration(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationship(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised ' + JSON.stringify(thing) ); diff --git a/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js b/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js index 0d0cadbcc1..fcc8da5b2c 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/typescript/typescriptvisitor.js @@ -43,19 +43,19 @@ class TypescriptVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationship(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { diff --git a/packages/concerto-tools/lib/codegen/fromcto/xmlschema/xmlschemavisitor.js b/packages/concerto-tools/lib/codegen/fromcto/xmlschema/xmlschemavisitor.js index 94401ae6df..0352a9d1ca 100644 --- a/packages/concerto-tools/lib/codegen/fromcto/xmlschema/xmlschemavisitor.js +++ b/packages/concerto-tools/lib/codegen/fromcto/xmlschema/xmlschemavisitor.js @@ -43,19 +43,19 @@ class XmlSchemaVisitor { * @private */ visit(thing, parameters) { - if (thing instanceof ModelManager) { + if (thing.isModelManager?.()) { return this.visitModelManager(thing, parameters); - } else if (thing instanceof ModelFile) { + } else if (thing.isModelFile?.()) { return this.visitModelFile(thing, parameters); - } else if (thing instanceof EnumDeclaration) { + } else if (thing.isEnum?.()) { return this.visitEnumDeclaration(thing, parameters); - } else if (thing instanceof ClassDeclaration) { + } else if (thing.isClassDeclaration?.()) { return this.visitClassDeclaration(thing, parameters); - } else if (thing instanceof Field) { + } else if (thing.isField?.()) { return this.visitField(thing, parameters); - } else if (thing instanceof RelationshipDeclaration) { + } else if (thing.isRelationship?.()) { return this.visitRelationship(thing, parameters); - } else if (thing instanceof EnumValueDeclaration) { + } else if (thing.isEnumValue?.()) { return this.visitEnumValueDeclaration(thing, parameters); } else { throw new Error('Unrecognised ' + JSON.stringify(thing) ); diff --git a/packages/concerto-tools/test/codegen/fromcto/csharp/csharpvisitor.js b/packages/concerto-tools/test/codegen/fromcto/csharp/csharpvisitor.js index c01cd7d5ba..a1d9c3ed20 100644 --- a/packages/concerto-tools/test/codegen/fromcto/csharp/csharpvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/csharp/csharpvisitor.js @@ -47,7 +47,7 @@ describe('CSharpVisitor', function () { it('should return visitModelManager for a ModelManager', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(csharpVisitor, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -58,7 +58,7 @@ describe('CSharpVisitor', function () { it('should return visitModelFile for a ModelFile', () => { let thing = sinon.createStubInstance(ModelFile); - thing._isModelFile = true; + thing.isModelFile.returns(true); let mockSpecialVisit = sinon.stub(csharpVisitor, 'visitModelFile'); mockSpecialVisit.returns('Duck'); @@ -69,7 +69,7 @@ describe('CSharpVisitor', function () { it('should return visitEnumDeclaration for a EnumDeclaration', () => { let thing = sinon.createStubInstance(EnumDeclaration); - thing._isEnumDeclaration = true; + thing.isEnum.returns(true); let mockSpecialVisit = sinon.stub(csharpVisitor, 'visitEnumDeclaration'); mockSpecialVisit.returns('Duck'); @@ -80,7 +80,7 @@ describe('CSharpVisitor', function () { it('should return visitClassDeclaration for a ClassDeclaration', () => { let thing = sinon.createStubInstance(ClassDeclaration); - thing._isClassDeclaration = true; + thing.isClassDeclaration.returns(true); let mockSpecialVisit = sinon.stub(csharpVisitor, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -91,7 +91,7 @@ describe('CSharpVisitor', function () { it('should return visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(csharpVisitor, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -102,7 +102,7 @@ describe('CSharpVisitor', function () { it('should return visitRelationship for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); let mockSpecialVisit = sinon.stub(csharpVisitor, 'visitRelationship'); mockSpecialVisit.returns('Duck'); @@ -113,7 +113,7 @@ describe('CSharpVisitor', function () { it('should return visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(csharpVisitor, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Goose'); @@ -138,7 +138,7 @@ describe('CSharpVisitor', function () { let param = {}; let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.getModelFiles.returns([{ accept: acceptSpy }, @@ -238,7 +238,6 @@ describe('CSharpVisitor', function () { it('should write lines for the imports that are not in own namespace ignoring primitives and write lines for importing system type', () => { let acceptSpy = sinon.spy(); let mockEnum = sinon.createStubInstance(EnumDeclaration); - mockEnum._isEnumDeclaration = true; mockEnum.isEnum.returns(true); mockEnum.accept = acceptSpy; @@ -270,15 +269,15 @@ describe('CSharpVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getProperties.returns([property1, property2, property3]); mockClassDeclaration.accept = acceptSpy; let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getNamespace.returns('org.acme'); mockModelFile.getAllDeclarations.returns([ mockEnum, @@ -345,7 +344,7 @@ describe('CSharpVisitor', function () { let acceptSpy = sinon.spy(); let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy }, @@ -365,7 +364,7 @@ describe('CSharpVisitor', function () { let acceptSpy = sinon.spy(); let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy }, @@ -430,7 +429,7 @@ describe('CSharpVisitor', function () { }; let mockEnumValueDeclaration = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDeclaration._isEnumValueDeclaration = true; + mockEnumValueDeclaration.isEnumValue.returns(true); mockEnumValueDeclaration.getName.returns('Bob'); csharpVisitor.visitEnumValueDeclaration(mockEnumValueDeclaration, param); @@ -447,7 +446,7 @@ describe('CSharpVisitor', function () { }); it('should write a line for field name and type', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('Person'); csharpVisitor.visitRelationship(mockRelationship, param); @@ -457,7 +456,7 @@ describe('CSharpVisitor', function () { it('should write a line for field name and type thats an array', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Bob'); mockField.getType.returns('Person'); mockField.isArray.returns(true); diff --git a/packages/concerto-tools/test/codegen/fromcto/golang/golangvisitor.js b/packages/concerto-tools/test/codegen/fromcto/golang/golangvisitor.js index d43f80276c..75868d824f 100644 --- a/packages/concerto-tools/test/codegen/fromcto/golang/golangvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/golang/golangvisitor.js @@ -49,7 +49,7 @@ describe('GoLangVisitor', function () { }); it('should call visitModelManager for a ModelManager', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(goVisit, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -60,7 +60,7 @@ describe('GoLangVisitor', function () { it('should call visitModelFile for a ModelFile', () => { let thing = sinon.createStubInstance(ModelFile); - thing._isModelFile = true; + thing.isModelFile.returns(true); let mockSpecialVisit = sinon.stub(goVisit, 'visitModelFile'); mockSpecialVisit.returns('Duck'); @@ -71,7 +71,7 @@ describe('GoLangVisitor', function () { it('should call visitClassDeclaration for a AssetDeclaration', () => { let thing = sinon.createStubInstance(AssetDeclaration); - thing._isAssetDeclaration = true; + thing.isAsset.returns(true); let mockSpecialVisit = sinon.stub(goVisit, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -82,14 +82,14 @@ describe('GoLangVisitor', function () { it('should call nothing for a TransactionDeclaration', () => { let thing = sinon.createStubInstance(TransactionDeclaration); - thing._isTransactionDeclaration = true; + thing.isTransaction.returns(true); should.equal(goVisit.visit(thing, param), undefined); }); it('should call visitEnumDeclaration for a EnumDeclaration', () => { let thing = sinon.createStubInstance(EnumDeclaration); - thing._isEnumDeclaration = true; + thing.isEnum.returns(true); let mockSpecialVisit = sinon.stub(goVisit, 'visitEnumDeclaration'); mockSpecialVisit.returns('Duck'); @@ -100,14 +100,14 @@ describe('GoLangVisitor', function () { it('should call nothing for a ConceptDeclaration', () => { let thing = sinon.createStubInstance(ConceptDeclaration); - thing._isConceptDeclaration = true; + thing.isConcept.returns(true); should.equal(goVisit.visit(thing, param), undefined); }); it('should call visitClassDeclaration for a ClassDeclaration', () => { let thing = sinon.createStubInstance(ClassDeclaration); - thing._isClassDeclaration = true; + thing.isClassDeclaration.returns(true); let mockSpecialVisit = sinon.stub(goVisit, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -118,7 +118,7 @@ describe('GoLangVisitor', function () { it('should call visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(goVisit, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -129,14 +129,14 @@ describe('GoLangVisitor', function () { it('should call nothing for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); should.equal(goVisit.visit(thing, param), undefined); }); it('should call visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(goVisit, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Duck'); @@ -163,7 +163,7 @@ describe('GoLangVisitor', function () { let acceptSpy = sinon.spy(); let mockModelManagerDefinition = sinon.createStubInstance(ModelManager); - mockModelManagerDefinition._isModelManager = true; + mockModelManagerDefinition.isModelManager.returns(true); mockModelManagerDefinition.getModelFiles.returns([{ accept: acceptSpy }, @@ -197,7 +197,7 @@ describe('GoLangVisitor', function () { mockContainsDateTimeField.returns(false); let mockModelFileDefinition = sinon.createStubInstance(ModelFile); - mockModelFileDefinition._isModelFile = true; + mockModelFileDefinition.isModelFile.returns(true); mockModelFileDefinition.getNamespace.returns; mockModelFileDefinition.getAllDeclarations.returns([{ accept: acceptSpy @@ -222,7 +222,7 @@ describe('GoLangVisitor', function () { mockContainsDateTimeField.returns(true); let mockModelFileDefinition = sinon.createStubInstance(ModelFile); - mockModelFileDefinition._isModelFile = true; + mockModelFileDefinition.isModelFile.returns(true); mockModelFileDefinition.getNamespace.returns; mockModelFileDefinition.getAllDeclarations.returns([{ accept: acceptSpy @@ -252,7 +252,7 @@ describe('GoLangVisitor', function () { it('should write lines defining type and const and call accept for each property', () => { let acceptSpy = sinon.spy(); let mockEnumDeclaration = sinon.createStubInstance(EnumDeclaration); - mockEnumDeclaration._isEnumDeclaration = true; + mockEnumDeclaration.isEnum.returns(true); mockEnumDeclaration.getName.returns('Bob'); mockEnumDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -282,7 +282,7 @@ describe('GoLangVisitor', function () { it('should write lines defining type call accept for each property', () => { let acceptSpy = sinon.spy(); let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Bob'); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -302,7 +302,7 @@ describe('GoLangVisitor', function () { it('should write lines defining type and call accept for each property embedding the super type as necessary', () => { let acceptSpy = sinon.spy(); let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Bob'); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -332,7 +332,7 @@ describe('GoLangVisitor', function () { it('should write a line defining a field', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(false); mockField.getName.returns('bob'); let mockGoType = sinon.stub(goVisit, 'toGoType'); @@ -345,7 +345,7 @@ describe('GoLangVisitor', function () { it('should write a line defining a field and add [] if an array', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(true); mockField.getName.returns('bob'); let mockGoType = sinon.stub(goVisit, 'toGoType'); @@ -366,9 +366,9 @@ describe('GoLangVisitor', function () { }; }); - it('should write a line using the enum value decleration', () => { + it('should write a line using the enum value declaration', () => { let mockEnumValueDeclaration = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDeclaration._isEnumDeclaration = true; + mockEnumValueDeclaration.isEnumValue.returns(true); mockEnumValueDeclaration.getParent.returns({ getOwnProperties: () => { return [{ @@ -390,7 +390,7 @@ describe('GoLangVisitor', function () { it('should write a line using the enum value decleration adding iota when the first', () => { let mockEnumValueDeclaration = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDeclaration._isEnumValueDeclaration = true; + mockEnumValueDeclaration.isEnumValue.returns(true); mockEnumValueDeclaration.getParent.returns({ getOwnProperties: () => { return [{ @@ -422,7 +422,7 @@ describe('GoLangVisitor', function () { it('should write a line defining a relationship', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(false); mockRelationship.getName.returns('bob'); @@ -433,7 +433,7 @@ describe('GoLangVisitor', function () { it('should write a line defining a relationship and add [] if an array', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(true); mockRelationship.getName.returns('bob'); @@ -446,7 +446,7 @@ describe('GoLangVisitor', function () { describe('containsDateTimeField', () => { it('should return true if the model file contains a data and time field', () => { let mockModelFileDefinition = sinon.createStubInstance(ModelFile); - mockModelFileDefinition._isModelFile = true; + mockModelFileDefinition.isModelFile.returns(true); mockModelFileDefinition.getAllDeclarations.returns([ { getProperties: () => { @@ -464,7 +464,7 @@ describe('GoLangVisitor', function () { it('should return true if the model file contains a data and time field', () => { let mockModelFileDefinition = sinon.createStubInstance(ModelFile); - mockModelFileDefinition._isModelFile = true; + mockModelFileDefinition.isModelFile.returns(true); mockModelFileDefinition.getAllDeclarations.returns([ { getProperties: () => { diff --git a/packages/concerto-tools/test/codegen/fromcto/graphql/graphqlvisitor.js b/packages/concerto-tools/test/codegen/fromcto/graphql/graphqlvisitor.js index 6ce597615c..a5a7edcb6c 100644 --- a/packages/concerto-tools/test/codegen/fromcto/graphql/graphqlvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/graphql/graphqlvisitor.js @@ -70,7 +70,7 @@ describe('GraphQLVisitor', function () { it('should call visitModelManager for a ModelManager', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(graphQLVisitor, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -80,7 +80,7 @@ describe('GraphQLVisitor', function () { it('should call visitModelFile for a ModelFile', () => { let thing = sinon.createStubInstance(ModelFile); - thing._isModelFile = true; + thing.isModelFile.returns(true); let mockSpecialVisit = sinon.stub(graphQLVisitor, 'visitModelFile'); mockSpecialVisit.returns('Duck'); @@ -90,7 +90,7 @@ describe('GraphQLVisitor', function () { it('should return visitClassDeclaration for a ClassDeclaration', () => { let thing = sinon.createStubInstance(ClassDeclaration); - thing._isClassDeclaration = true; + thing.isClassDeclaration.returns(true); let mockSpecialVisit = sinon.stub(graphQLVisitor, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -101,7 +101,7 @@ describe('GraphQLVisitor', function () { it('should return visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(graphQLVisitor, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -112,7 +112,7 @@ describe('GraphQLVisitor', function () { it('should return visitRelationship for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); let mockSpecialVisit = sinon.stub(graphQLVisitor, 'visitRelationship'); mockSpecialVisit.returns('Duck'); @@ -123,7 +123,7 @@ describe('GraphQLVisitor', function () { it('should return visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(graphQLVisitor, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Duck'); @@ -150,7 +150,7 @@ describe('GraphQLVisitor', function () { let acceptSpy = sinon.spy(); let mockModelManagerDefinition = sinon.createStubInstance(ModelManager); - mockModelManagerDefinition._isModelManager = true; + mockModelManagerDefinition.isModelManager.returns(true); mockModelManagerDefinition.getModelFiles.returns([{ accept: acceptSpy }, @@ -178,7 +178,7 @@ describe('GraphQLVisitor', function () { it('should visit all declaration in a model file', () => { let acceptSpy = sinon.spy(); let mockModelFileDefinition = sinon.createStubInstance(ModelFile); - mockModelFileDefinition._isModelFile = true; + mockModelFileDefinition.isModelFile.returns(true); mockModelFileDefinition.getNamespace.returns; mockModelFileDefinition.getAllDeclarations.returns([{ accept: acceptSpy @@ -201,7 +201,7 @@ describe('GraphQLVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getProperties.returns([{ @@ -228,7 +228,7 @@ describe('GraphQLVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Size'); mockClassDeclaration.isEnum.returns(true); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Size'); @@ -256,7 +256,7 @@ describe('GraphQLVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getProperties.returns([{ @@ -284,7 +284,7 @@ describe('GraphQLVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getType.returns('string'); mockField.getName.returns('Bob'); @@ -298,7 +298,7 @@ describe('GraphQLVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getType.returns('org.acme.Person'); mockField.getName.returns('Bob'); mockField.getFullyQualifiedTypeName.returns('org.acme.Person'); @@ -314,7 +314,7 @@ describe('GraphQLVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getType.returns('string'); mockField.getName.returns('Bob'); mockField.isArray.returns(true); @@ -331,7 +331,7 @@ describe('GraphQLVisitor', function () { }; let mockEnumValueDecl = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDecl._isEnumValueDeclaration = true; + mockEnumValueDecl.isEnumValue.returns(true); mockEnumValueDecl.getName.returns('Bob'); graphQLVisitor.visitEnumValueDeclaration(mockEnumValueDecl, param); @@ -346,7 +346,7 @@ describe('GraphQLVisitor', function () { }; let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getType.returns('string'); mockRelationship.getName.returns('Bob'); @@ -361,7 +361,7 @@ describe('GraphQLVisitor', function () { }; let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getType.returns('string'); mockRelationship.getName.returns('Bob'); mockRelationship.isArray.returns(true); diff --git a/packages/concerto-tools/test/codegen/fromcto/java/javamissingplugin.js b/packages/concerto-tools/test/codegen/fromcto/java/javamissingplugin.js index 8a5338d9de..793d3bf1cf 100644 --- a/packages/concerto-tools/test/codegen/fromcto/java/javamissingplugin.js +++ b/packages/concerto-tools/test/codegen/fromcto/java/javamissingplugin.js @@ -41,7 +41,7 @@ describe('JavaMissingPlugin', function () { }; let mockClass = sinon.createStubInstance(ClassDeclaration); - mockClass._isClassDeclaration = true; + mockClass.isClassDeclaration.returns(true); mockClass.getModelFile.returns({ getNamespace: () => { return 'org.acme.people'; @@ -65,7 +65,7 @@ describe('JavaMissingPlugin', function () { }; let mockEnumDeclaration = sinon.createStubInstance(EnumDeclaration); - mockEnumDeclaration._isEnumDeclaration = true; + mockEnumDeclaration.isEnum.returns(true); mockEnumDeclaration.getName.returns('Bob'); mockEnumDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -93,7 +93,7 @@ describe('JavaMissingPlugin', function () { }; mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Bob'); mockClassDeclaration.getModelFile.returns({ getImports: () => { diff --git a/packages/concerto-tools/test/codegen/fromcto/java/javavisitor.js b/packages/concerto-tools/test/codegen/fromcto/java/javavisitor.js index 0d6d2d35ea..1c37d88ffe 100644 --- a/packages/concerto-tools/test/codegen/fromcto/java/javavisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/java/javavisitor.js @@ -47,7 +47,7 @@ describe('JavaVisitor', function () { it('should call visitModelManager for a ModelManager', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -58,7 +58,7 @@ describe('JavaVisitor', function () { it('should default to callint visitModelManager with no options', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -69,7 +69,7 @@ describe('JavaVisitor', function () { it('should call visitModelFile for a ModelFile', () => { let thing = sinon.createStubInstance(ModelFile); - thing._isModelFile = true; + thing.isModelFile.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitModelFile'); mockSpecialVisit.returns('Duck'); @@ -80,7 +80,7 @@ describe('JavaVisitor', function () { it('should call visitEnumDeclaration for a EnumDeclaration', () => { let thing = sinon.createStubInstance(EnumDeclaration); - thing._isEnumDeclaration = true; + thing.isEnum.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitEnumDeclaration'); mockSpecialVisit.returns('Duck'); @@ -91,7 +91,7 @@ describe('JavaVisitor', function () { it('should call visitClassDeclaration for a ClassDeclaration', () => { let thing = sinon.createStubInstance(ClassDeclaration); - thing._isClassDeclaration = true; + thing.isClassDeclaration.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -102,7 +102,7 @@ describe('JavaVisitor', function () { it('should call visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -113,7 +113,7 @@ describe('JavaVisitor', function () { it('should call visitRelationship for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitRelationship'); mockSpecialVisit.returns('Duck'); @@ -124,7 +124,7 @@ describe('JavaVisitor', function () { it('should call visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(javaVisit, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Duck'); @@ -150,7 +150,7 @@ describe('JavaVisitor', function () { let acceptSpy = sinon.spy(); let mockModelManagerDefinition = sinon.createStubInstance(ModelManager); - mockModelManagerDefinition._isModelManager = true; + mockModelManagerDefinition.isModelManager.returns(true); mockModelManagerDefinition.getModelFiles.returns([{ accept: acceptSpy }, @@ -174,7 +174,7 @@ describe('JavaVisitor', function () { let acceptSpy = sinon.spy(); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getAllDeclarations.returns([{ accept: acceptSpy }, @@ -195,7 +195,7 @@ describe('JavaVisitor', function () { }; let mockClass = sinon.createStubInstance(ClassDeclaration); - mockClass._isClassDeclaration = true; + mockClass.isClassDeclaration.returns(true); mockClass.getModelFile.returns({ getNamespace: () => { return 'org.acme.people'; @@ -223,7 +223,7 @@ describe('JavaVisitor', function () { }; let mockClass = sinon.createStubInstance(ClassDeclaration); - mockClass._isClassDeclaration = true; + mockClass.isClassDeclaration.returns(true); javaVisit.endClassFile(mockClass, param); @@ -240,7 +240,7 @@ describe('JavaVisitor', function () { }; let mockEnumDeclaration = sinon.createStubInstance(EnumDeclaration); - mockEnumDeclaration._isEnumDeclaration = true; + mockEnumDeclaration.isEnum.returns(true); mockEnumDeclaration.getName.returns('Bob'); mockEnumDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -278,7 +278,7 @@ describe('JavaVisitor', function () { }; mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Bob'); mockClassDeclaration.getModelFile.returns({ getImports: () => { @@ -419,7 +419,7 @@ describe('JavaVisitor', function () { it('should default to write a line defining a field', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(false); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -432,7 +432,7 @@ describe('JavaVisitor', function () { it('should default to write a line defining a field and add [] if an array', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(true); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -445,7 +445,7 @@ describe('JavaVisitor', function () { it('should write a line defining a field', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(false); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -458,7 +458,7 @@ describe('JavaVisitor', function () { it('should write a line defining a field and add [] if an array', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(true); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -471,7 +471,7 @@ describe('JavaVisitor', function () { it('should write a line setting a field', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(false); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -487,7 +487,7 @@ describe('JavaVisitor', function () { it('should write a line setting a field and add [] if an array', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(true); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -503,7 +503,7 @@ describe('JavaVisitor', function () { it('should write a line getting a field', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(false); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -519,7 +519,7 @@ describe('JavaVisitor', function () { it('should write a line getting a field and add [] if an array', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.isArray.returns(true); mockField.getName.returns('Bob'); mockField.getType.returns('SpecialType'); @@ -541,7 +541,7 @@ describe('JavaVisitor', function () { }; let mockEnumValueDeclaration = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDeclaration._isEnumValueDeclaration = true; + mockEnumValueDeclaration.isEnumValue.returns(true); mockEnumValueDeclaration.getName.returns('Bob'); javaVisit.visitEnumValueDeclaration(mockEnumValueDeclaration, param); @@ -560,7 +560,7 @@ describe('JavaVisitor', function () { it('should default to write a line defining a field', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(false); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); @@ -573,7 +573,7 @@ describe('JavaVisitor', function () { it('should default to write a line defining a field and add [] if an array', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(true); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); @@ -585,7 +585,7 @@ describe('JavaVisitor', function () { }); it('should write a line defining a field', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(false); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); @@ -598,7 +598,7 @@ describe('JavaVisitor', function () { it('should write a line defining a field and add [] if an array', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(true); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); @@ -611,7 +611,7 @@ describe('JavaVisitor', function () { it('should write a line setting a field', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(false); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); @@ -627,7 +627,7 @@ describe('JavaVisitor', function () { it('should write a line setting a field and add [] if an array', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(true); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); @@ -643,7 +643,7 @@ describe('JavaVisitor', function () { it('should write a line getting a field', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(false); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); @@ -659,7 +659,7 @@ describe('JavaVisitor', function () { it('should write a line getting a field and add [] if an array', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.isArray.returns(true); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('SpecialType'); diff --git a/packages/concerto-tools/test/codegen/fromcto/loopback/loopbackvisitor.js b/packages/concerto-tools/test/codegen/fromcto/loopback/loopbackvisitor.js index f1201fd10e..af56cfb1ab 100644 --- a/packages/concerto-tools/test/codegen/fromcto/loopback/loopbackvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/loopback/loopbackvisitor.js @@ -52,7 +52,7 @@ describe('LoopbackVisitor', () => { it('should call visitModelManager for a ModelManager', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -63,7 +63,7 @@ describe('LoopbackVisitor', () => { it('should call visitModelFile for a ModelFile', () => { let thing = sinon.createStubInstance(ModelFile); - thing._isModelFile = true; + thing.isModelFile.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitModelFile'); mockSpecialVisit.returns('Duck'); @@ -74,7 +74,7 @@ describe('LoopbackVisitor', () => { it('should call visitAssetDeclaration for a AssetDeclaration', () => { let thing = sinon.createStubInstance(AssetDeclaration); - thing._isAssetDeclaration = true; + thing.isAsset.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitAssetDeclaration'); mockSpecialVisit.returns('Duck'); @@ -85,7 +85,7 @@ describe('LoopbackVisitor', () => { it('should call visitParticipantDeclaration for a ParticipantDeclaration', () => { let thing = sinon.createStubInstance(ParticipantDeclaration); - thing._isParticipantDeclaration = true; + thing.isParticipant.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitParticipantDeclaration'); mockSpecialVisit.returns('Duck'); @@ -96,7 +96,7 @@ describe('LoopbackVisitor', () => { it('should call visitConceptDeclaration for a ConceptDeclaration', () => { let thing = sinon.createStubInstance(ConceptDeclaration); - thing._isConceptDeclaration = true; + thing.isConcept.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitConceptDeclaration'); mockSpecialVisit.returns('Duck'); @@ -107,7 +107,7 @@ describe('LoopbackVisitor', () => { it('should call visitTransactionDeclaration for a TransactionDeclaration', () => { let thing = sinon.createStubInstance(TransactionDeclaration); - thing._isTransactionDeclaration = true; + thing.isTransaction.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitTransactionDeclaration'); mockSpecialVisit.returns('Duck'); @@ -118,7 +118,7 @@ describe('LoopbackVisitor', () => { it('should call visitEventDeclaration for a EventDeclaration', () => { let thing = sinon.createStubInstance(EventDeclaration); - thing._isEventDeclaration = true; + thing.isEvent.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitEventDeclaration'); mockSpecialVisit.returns('Duck'); @@ -129,7 +129,7 @@ describe('LoopbackVisitor', () => { it('should call visitEnumDeclaration for a EnumDeclaration', () => { let thing = sinon.createStubInstance(EnumDeclaration); - thing._isEnumDeclaration = true; + thing.isEnum.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitEnumDeclaration'); mockSpecialVisit.returns('Duck'); @@ -140,7 +140,7 @@ describe('LoopbackVisitor', () => { it('should call visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -151,7 +151,7 @@ describe('LoopbackVisitor', () => { it('should call visitRelationshipDeclaration for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitRelationshipDeclaration'); mockSpecialVisit.returns('Duck'); @@ -162,7 +162,7 @@ describe('LoopbackVisitor', () => { it('should call visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(loopbackVisit, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Duck'); @@ -185,14 +185,14 @@ describe('LoopbackVisitor', () => { let param = {}; let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.accept.returns(['Duck', 'Duck']); let mockModelFile2 = sinon.createStubInstance(ModelFile); - mockModelFile2._isModelFile = true; + mockModelFile2.isModelFile.returns(true); mockModelFile2.accept.returns(['Duck', 'Goose']); let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.getModelFiles.returns([mockModelFile, mockModelFile2]); loopbackVisit.visitModelManager(mockModelManager, param).should.deep.equal(['Duck', 'Duck', 'Duck', 'Goose']); @@ -209,23 +209,23 @@ describe('LoopbackVisitor', () => { let param = {}; let mockAssetDeclaration = sinon.createStubInstance(AssetDeclaration); - mockAssetDeclaration._isAssetDeclaration = true; + mockAssetDeclaration.isAsset.returns(true); mockAssetDeclaration.accept.returns('Duck'); let mockConceptDeclaration = sinon.createStubInstance(ConceptDeclaration); - mockConceptDeclaration._isConceptDeclaration = true; + mockConceptDeclaration.isConcept.returns(true); mockConceptDeclaration.accept.returns('Duck'); let mockParticipantDeclaration = sinon.createStubInstance(ParticipantDeclaration); - mockParticipantDeclaration._isParticipantDeclaration = true; + mockParticipantDeclaration.isParticipant.returns(true); mockParticipantDeclaration.accept.returns('Duck'); let mockTransactionDeclaration = sinon.createStubInstance(TransactionDeclaration); - mockTransactionDeclaration._isTransactionDeclaration = true; + mockTransactionDeclaration.isTransaction.returns(true); mockTransactionDeclaration.accept.returns('Goose'); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getNamespace.returns; mockModelFile.getAssetDeclarations.returns([mockAssetDeclaration]); mockModelFile.getTransactionDeclarations.returns([mockTransactionDeclaration]); @@ -246,7 +246,7 @@ describe('LoopbackVisitor', () => { let param = {}; let mockAssetDeclaration = sinon.createStubInstance(AssetDeclaration); - mockAssetDeclaration._isAssetDeclaration = true; + mockAssetDeclaration.isAsset.returns(true); mockAssetDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockAssetDeclaration.getName.returns('Bob'); @@ -264,7 +264,7 @@ describe('LoopbackVisitor', () => { }; let mockAssetDeclaration = sinon.createStubInstance(AssetDeclaration); - mockAssetDeclaration._isAssetDeclaration = true; + mockAssetDeclaration.isAsset.returns(true); mockAssetDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockAssetDeclaration.getName.returns('Bob'); @@ -301,7 +301,7 @@ describe('LoopbackVisitor', () => { }; let mockAssetDeclaration = sinon.createStubInstance(AssetDeclaration); - mockAssetDeclaration._isAssetDeclaration = true; + mockAssetDeclaration.isAsset.returns(true); mockAssetDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockAssetDeclaration.getName.returns('Bob'); @@ -340,7 +340,7 @@ describe('LoopbackVisitor', () => { let param = {}; let mockParticipantDeclaration = sinon.createStubInstance(ParticipantDeclaration); - mockParticipantDeclaration._isParticipantDeclaration = true; + mockParticipantDeclaration.isParticipant.returns(true); mockParticipantDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockParticipantDeclaration.getName.returns('Bob'); @@ -358,7 +358,7 @@ describe('LoopbackVisitor', () => { }; let mockParticipantDeclaration = sinon.createStubInstance(ParticipantDeclaration); - mockParticipantDeclaration._isParticipantDeclaration = true; + mockParticipantDeclaration.isParticipant.returns(true); mockParticipantDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockParticipantDeclaration.getName.returns('Bob'); @@ -395,7 +395,7 @@ describe('LoopbackVisitor', () => { }; let mockParticipantDeclaration = sinon.createStubInstance(ParticipantDeclaration); - mockParticipantDeclaration._isParticipantDeclaration = true; + mockParticipantDeclaration.isParticipant.returns(true); mockParticipantDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockParticipantDeclaration.getName.returns('Bob'); @@ -434,7 +434,7 @@ describe('LoopbackVisitor', () => { let param = {}; let mockConceptDeclaration = sinon.createStubInstance(ConceptDeclaration); - mockConceptDeclaration._isConceptDeclaration = true; + mockConceptDeclaration.isConcept.returns(true); mockConceptDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockConceptDeclaration.getName.returns('Bob'); @@ -452,7 +452,7 @@ describe('LoopbackVisitor', () => { }; let mockConceptDeclaration = sinon.createStubInstance(ConceptDeclaration); - mockConceptDeclaration._isConceptDeclaration = true; + mockConceptDeclaration.isConcept.returns(true); mockConceptDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockConceptDeclaration.getName.returns('Bob'); @@ -488,7 +488,7 @@ describe('LoopbackVisitor', () => { }; let mockConceptDeclaration = sinon.createStubInstance(ConceptDeclaration); - mockConceptDeclaration._isConceptDeclaration = true; + mockConceptDeclaration.isConcept.returns(true); mockConceptDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockConceptDeclaration.getName.returns('Bob'); @@ -526,7 +526,7 @@ describe('LoopbackVisitor', () => { let param = {}; let mockTransactionDeclaration = sinon.createStubInstance(TransactionDeclaration); - mockTransactionDeclaration._isTransactionDeclaration = true; + mockTransactionDeclaration.isTransaction.returns(true); mockTransactionDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockTransactionDeclaration.getName.returns('Bob'); @@ -544,7 +544,7 @@ describe('LoopbackVisitor', () => { }; let mockTransactionDeclaration = sinon.createStubInstance(TransactionDeclaration); - mockTransactionDeclaration._isTransactionDeclaration = true; + mockTransactionDeclaration.isTransaction.returns(true); mockTransactionDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockTransactionDeclaration.getName.returns('Bob'); @@ -581,7 +581,7 @@ describe('LoopbackVisitor', () => { }; let mockTransactionDeclaration = sinon.createStubInstance(TransactionDeclaration); - mockTransactionDeclaration._isTransactionDeclaration = true; + mockTransactionDeclaration.isTransaction.returns(true); mockTransactionDeclaration.getFullyQualifiedName.returns('org.acme.Person.Bob'); mockTransactionDeclaration.getName.returns('Bob'); @@ -618,7 +618,7 @@ describe('LoopbackVisitor', () => { describe('visitEventDeclaration', () => { it('should return null', () => { let mockEventDeclaration = sinon.createStubInstance(EventDeclaration); - mockEventDeclaration._isEventDeclaration = true; + mockEventDeclaration.isEvent.returns(true); mockEventDeclaration.getName.returns('Bob'); should.equal(loopbackVisit.visitEventDeclaration(mockEventDeclaration, {}), null); @@ -634,7 +634,7 @@ describe('LoopbackVisitor', () => { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getProperties.returns([ @@ -685,7 +685,7 @@ describe('LoopbackVisitor', () => { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getProperties.returns([ @@ -740,7 +740,7 @@ describe('LoopbackVisitor', () => { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getNamespace.returns('org.acme'); @@ -806,7 +806,7 @@ describe('LoopbackVisitor', () => { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getProperties.returns([ @@ -870,7 +870,7 @@ describe('LoopbackVisitor', () => { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getProperties.returns([ @@ -929,7 +929,7 @@ describe('LoopbackVisitor', () => { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getProperties.returns([ @@ -990,7 +990,7 @@ describe('LoopbackVisitor', () => { }; let mockTransactionDeclaration = sinon.createStubInstance(TransactionDeclaration); - mockTransactionDeclaration._isTransactionDeclaration = true; + mockTransactionDeclaration.isTransaction.returns(true); mockTransactionDeclaration.getName.returns('Person'); mockTransactionDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockTransactionDeclaration.getIdentifierFieldName.returns('Bob'); @@ -1084,7 +1084,7 @@ describe('LoopbackVisitor', () => { let param = {}; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Horse'); mockField.isPrimitive.returns(true); mockField.getType.returns('String'); @@ -1105,7 +1105,7 @@ describe('LoopbackVisitor', () => { let param = {}; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Farmer'); mockField.isPrimitive.returns(true); mockField.getType.returns('String'); @@ -1133,13 +1133,13 @@ describe('LoopbackVisitor', () => { mockModelFile.accept.withArgs(loopbackVisit, param).returns({ type: 'Square' }); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getType.withArgs('Acreage').returns({ accept: mockModelFile.accept }); let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Horse'); mockField.isTypeEnum.returns(true); mockField.getType.returns('Acreage'); @@ -1163,13 +1163,13 @@ describe('LoopbackVisitor', () => { mockModelFile.accept.withArgs(loopbackVisit, param).returns({ type: 'Square' }); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getType.withArgs('Acreage').returns({ accept: mockModelFile.accept }); let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Horse'); mockField.isTypeEnum.returns(true); mockField.getType.returns('Acreage'); @@ -1192,13 +1192,13 @@ describe('LoopbackVisitor', () => { let param = {}; let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getType.withArgs('Acreage').returns({ accept: mockModelFile.accept }); let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Horse'); mockField.getType.returns('Acreage'); mockField.getFullyQualifiedTypeName.returns('org.acme.Horse.Acreage'); @@ -1221,13 +1221,13 @@ describe('LoopbackVisitor', () => { let param = {}; let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getType.withArgs('Acreage').returns({ accept: mockModelFile.accept }); let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Horse'); mockField.getType.returns('Acreage'); mockField.getFullyQualifiedTypeName.returns('org.acme.Horse.Acreage'); @@ -1254,13 +1254,13 @@ describe('LoopbackVisitor', () => { }; let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getType.withArgs('Acreage').returns({ accept: mockModelFile.accept }); let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Horse'); mockField.getType.returns('Acreage'); mockField.getFullyQualifiedTypeName.returns('org.acme.Horse.Acreage'); @@ -1283,7 +1283,7 @@ describe('LoopbackVisitor', () => { let param = {}; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Horse'); mockField.isPrimitive.returns(true); mockField.getType.returns('String'); @@ -1309,7 +1309,7 @@ describe('LoopbackVisitor', () => { let mockEnumDecl = sinon.createStubInstance(EnumDeclaration); mockEnumDecl.accept.withArgs(loopbackVisit, param).returns('Duck'); - mockEnumDecl._isEnumDeclaration = true; + mockEnumDecl.isEnum.returns(true); mockEnumDecl.getProperties.returns([ { accept: mockEnumDecl.accept @@ -1329,7 +1329,7 @@ describe('LoopbackVisitor', () => { describe('visitEnumValueDeclaration', () => { it('should return the enumValueDeclaration\'s name', () => { let mockEnumValDecl = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValDecl._isEnumValueDeclaration = true; + mockEnumValDecl.isEnumValue.returns(true); mockEnumValDecl.getName.returns('Bob'); loopbackVisit.visitEnumValueDeclaration(mockEnumValDecl, {}).should.deep.equal('Bob'); @@ -1339,7 +1339,7 @@ describe('LoopbackVisitor', () => { describe('visitRelationshipDeclaration', () => { it('should return a JSONSchema for a relationship', () => { let mockRelationshipDeclaration = sinon.createStubInstance(RelationshipDeclaration); - mockRelationshipDeclaration._isRelationshipDeclaration = true; + mockRelationshipDeclaration.isRelationship.returns(true); mockRelationshipDeclaration.getName.returns('Bob'); mockRelationshipDeclaration.isOptional.returns(false); @@ -1352,7 +1352,7 @@ describe('LoopbackVisitor', () => { it('should return a JSONSchema for a relationship that is an array', () => { let mockRelationshipDeclaration = sinon.createStubInstance(RelationshipDeclaration); - mockRelationshipDeclaration._isRelationshipDeclaration = true; + mockRelationshipDeclaration.isRelationship.returns(true); mockRelationshipDeclaration.getName.returns('Bob'); mockRelationshipDeclaration.isOptional.returns(false); mockRelationshipDeclaration.isArray.returns(true); diff --git a/packages/concerto-tools/test/codegen/fromcto/plantuml/plantumlvisitor.js b/packages/concerto-tools/test/codegen/fromcto/plantuml/plantumlvisitor.js index 46f5fcc0b0..2f4f84a68f 100644 --- a/packages/concerto-tools/test/codegen/fromcto/plantuml/plantumlvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/plantuml/plantumlvisitor.js @@ -50,7 +50,7 @@ describe('PlantUMLVisitor', function () { it('should call visitModelManager for a ModelManager', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -60,7 +60,7 @@ describe('PlantUMLVisitor', function () { it('should call visitModelFile for a ModelFile', () => { let thing = sinon.createStubInstance(ModelFile); - thing._isModelFile = true; + thing.isModelFile.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitModelFile'); mockSpecialVisit.returns('Duck'); @@ -70,7 +70,7 @@ describe('PlantUMLVisitor', function () { it('should return visitParticipantDeclaration for a ParticipantDeclaration', () => { let thing = sinon.createStubInstance(ParticipantDeclaration); - thing._isParticipantDeclaration = true; + thing.isParticipant.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitParticipantDeclaration'); mockSpecialVisit.returns('Duck'); plantUMLvisitor.visit(thing, param).should.deep.equal('Duck'); @@ -79,7 +79,7 @@ describe('PlantUMLVisitor', function () { it('should return visitTransactionDeclaration for a TransactionDeclaration', () => { let thing = sinon.createStubInstance(TransactionDeclaration); - thing._isTransactionDeclaration = true; + thing.isTransaction.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitTransactionDeclaration'); mockSpecialVisit.returns('Duck'); @@ -90,7 +90,7 @@ describe('PlantUMLVisitor', function () { it('should return visitAssetDeclaration for a AssetDeclaration', () => { let thing = sinon.createStubInstance(AssetDeclaration); - thing._isAssetDeclaration = true; + thing.isAsset.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitAssetDeclaration'); mockSpecialVisit.returns('Duck'); @@ -101,7 +101,7 @@ describe('PlantUMLVisitor', function () { it('should return visitEnumDeclaration for a EnumDeclaration', () => { let thing = sinon.createStubInstance(EnumDeclaration); - thing._isEnumDeclaration = true; + thing.isEnum.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitEnumDeclaration'); mockSpecialVisit.returns('Duck'); @@ -112,7 +112,7 @@ describe('PlantUMLVisitor', function () { it('should return visitClassDeclaration for a ClassDeclaration', () => { let thing = sinon.createStubInstance(ClassDeclaration); - thing._isClassDeclaration = true; + thing.isClassDeclaration.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -123,7 +123,7 @@ describe('PlantUMLVisitor', function () { it('should return visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -134,7 +134,7 @@ describe('PlantUMLVisitor', function () { it('should return visitRelationship for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitRelationship'); mockSpecialVisit.returns('Duck'); @@ -145,7 +145,7 @@ describe('PlantUMLVisitor', function () { it('should return visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(plantUMLvisitor, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Duck'); @@ -172,7 +172,7 @@ describe('PlantUMLVisitor', function () { let acceptSpy = sinon.spy(); let mockModelManagerDefinition = sinon.createStubInstance(ModelManager); - mockModelManagerDefinition._isModelManager = true; + mockModelManagerDefinition.isModelManager.returns(true); mockModelManagerDefinition.getModelFiles.returns([{ accept: acceptSpy }, @@ -200,7 +200,7 @@ describe('PlantUMLVisitor', function () { it('should visit all declaration in a model file', () => { let acceptSpy = sinon.spy(); let mockModelFileDefinition = sinon.createStubInstance(ModelFile); - mockModelFileDefinition._isModelFile = true; + mockModelFileDefinition.isModelFile.returns(true); mockModelFileDefinition.getNamespace.returns; mockModelFileDefinition.getAllDeclarations.returns([{ accept: acceptSpy @@ -223,7 +223,7 @@ describe('PlantUMLVisitor', function () { }; let mockAssetDeclaration = sinon.createStubInstance(AssetDeclaration); - mockAssetDeclaration._isAssetDeclaration = true; + mockAssetDeclaration.isAsset.returns(true); mockAssetDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockAssetDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -249,7 +249,7 @@ describe('PlantUMLVisitor', function () { }; let mockAssetDeclaration = sinon.createStubInstance(AssetDeclaration); - mockAssetDeclaration._isAssetDeclaration = true; + mockAssetDeclaration.isAsset.returns(true); mockAssetDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockAssetDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -279,7 +279,7 @@ describe('PlantUMLVisitor', function () { }; let mockEnumDeclaration = sinon.createStubInstance(EnumDeclaration); - mockEnumDeclaration._isEnumDeclaration = true; + mockEnumDeclaration.isEnum.returns(true); mockEnumDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockEnumDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -305,7 +305,7 @@ describe('PlantUMLVisitor', function () { }; let mockEnumDeclaration = sinon.createStubInstance(EnumDeclaration); - mockEnumDeclaration._isEnumDeclaration = true; + mockEnumDeclaration.isEnum.returns(true); mockEnumDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockEnumDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -335,7 +335,7 @@ describe('PlantUMLVisitor', function () { }; let mockParticipantDeclaration = sinon.createStubInstance(ParticipantDeclaration); - mockParticipantDeclaration._isParticipantDeclaration = true; + mockParticipantDeclaration.isParticipant.returns(true); mockParticipantDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockParticipantDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -361,7 +361,7 @@ describe('PlantUMLVisitor', function () { }; let mockParticipantDeclaration = sinon.createStubInstance(ParticipantDeclaration); - mockParticipantDeclaration._isParticipantDeclaration = true; + mockParticipantDeclaration.isParticipant.returns(true); mockParticipantDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockParticipantDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -391,7 +391,7 @@ describe('PlantUMLVisitor', function () { }; let mockTransDeclaration = sinon.createStubInstance(TransactionDeclaration); - mockTransDeclaration._isTransactionDeclaration = true; + mockTransDeclaration.isTransaction.returns(true); mockTransDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockTransDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -417,7 +417,7 @@ describe('PlantUMLVisitor', function () { }; let mockTransDeclaration = sinon.createStubInstance(TransactionDeclaration); - mockTransDeclaration._isTransactionDeclaration = true; + mockTransDeclaration.isTransaction.returns(true); mockTransDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockTransDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -447,7 +447,7 @@ describe('PlantUMLVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -473,7 +473,7 @@ describe('PlantUMLVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getFullyQualifiedName.returns('org.acme.Person'); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -501,7 +501,7 @@ describe('PlantUMLVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getType.returns('string'); mockField.getName.returns('Bob'); @@ -516,7 +516,7 @@ describe('PlantUMLVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getType.returns('string'); mockField.getName.returns('Bob'); mockField.isArray.returns(true); @@ -534,7 +534,7 @@ describe('PlantUMLVisitor', function () { }; let mockEnumValueDecl = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDecl._isEnumValueDeclaration = true; + mockEnumValueDecl.isEnumValue.returns(true); mockEnumValueDecl.getName.returns('Bob'); plantUMLvisitor.visitEnumValueDeclaration(mockEnumValueDecl, param); @@ -550,7 +550,7 @@ describe('PlantUMLVisitor', function () { }; let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getType.returns('string'); mockRelationship.getName.returns('Bob'); @@ -565,7 +565,7 @@ describe('PlantUMLVisitor', function () { }; let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getType.returns('string'); mockRelationship.getName.returns('Bob'); mockRelationship.isArray.returns(true); diff --git a/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js b/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js index 3c45885df3..af339dafaf 100644 --- a/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/typescript/typescriptvisitor.js @@ -47,7 +47,7 @@ describe('TypescriptVisitor', function () { it('should return visitModelManager for a ModelManager', () => { let thing = sinon.createStubInstance(ModelManager); - thing._isModelManager = true; + thing.isModelManager.returns(true); let mockSpecialVisit = sinon.stub(typescriptVisitor, 'visitModelManager'); mockSpecialVisit.returns('Duck'); @@ -58,7 +58,7 @@ describe('TypescriptVisitor', function () { it('should return visitModelFile for a ModelFile', () => { let thing = sinon.createStubInstance(ModelFile); - thing._isModelFile = true; + thing.isModelFile.returns(true); let mockSpecialVisit = sinon.stub(typescriptVisitor, 'visitModelFile'); mockSpecialVisit.returns('Duck'); @@ -69,7 +69,7 @@ describe('TypescriptVisitor', function () { it('should return visitEnumDeclaration for a EnumDeclaration', () => { let thing = sinon.createStubInstance(EnumDeclaration); - thing._isEnumDeclaration = true; + thing.isEnum.returns(true); let mockSpecialVisit = sinon.stub(typescriptVisitor, 'visitEnumDeclaration'); mockSpecialVisit.returns('Duck'); @@ -80,7 +80,7 @@ describe('TypescriptVisitor', function () { it('should return visitClassDeclaration for a ClassDeclaration', () => { let thing = sinon.createStubInstance(ClassDeclaration); - thing._isClassDeclaration = true; + thing.isClassDeclaration.returns(true); let mockSpecialVisit = sinon.stub(typescriptVisitor, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -91,7 +91,7 @@ describe('TypescriptVisitor', function () { it('should return visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(typescriptVisitor, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -102,7 +102,7 @@ describe('TypescriptVisitor', function () { it('should return visitRelationship for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); let mockSpecialVisit = sinon.stub(typescriptVisitor, 'visitRelationship'); mockSpecialVisit.returns('Duck'); @@ -113,7 +113,7 @@ describe('TypescriptVisitor', function () { it('should return visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(typescriptVisitor, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Goose'); @@ -138,7 +138,7 @@ describe('TypescriptVisitor', function () { let param = {}; let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.getModelFiles.returns([{ accept: acceptSpy }, @@ -238,7 +238,6 @@ describe('TypescriptVisitor', function () { it('should write lines for the imports that are not in own namespace ignoring primitives and write lines for importing system type', () => { let acceptSpy = sinon.spy(); let mockEnum = sinon.createStubInstance(EnumDeclaration); - mockEnum._isEnumDeclaration = true; mockEnum.isEnum.returns(true); mockEnum.accept = acceptSpy; @@ -270,15 +269,15 @@ describe('TypescriptVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getProperties.returns([property1, property2, property3]); mockClassDeclaration.accept = acceptSpy; let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getNamespace.returns('org.acme'); mockModelFile.getAllDeclarations.returns([ mockEnum, @@ -345,7 +344,7 @@ describe('TypescriptVisitor', function () { let acceptSpy = sinon.spy(); let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy }, @@ -365,7 +364,7 @@ describe('TypescriptVisitor', function () { let acceptSpy = sinon.spy(); let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy }, @@ -450,7 +449,7 @@ describe('TypescriptVisitor', function () { }; let mockEnumValueDeclaration = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDeclaration._isEnumValueDeclaration = true; + mockEnumValueDeclaration.isEnumValue.returns(true); mockEnumValueDeclaration.getName.returns('Bob'); typescriptVisitor.visitEnumValueDeclaration(mockEnumValueDeclaration, param); @@ -468,7 +467,7 @@ describe('TypescriptVisitor', function () { }); it('should write a line for field name and type', () => { let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getName.returns('Bob'); mockRelationship.getType.returns('Person'); typescriptVisitor.visitRelationship(mockRelationship, param); @@ -478,7 +477,7 @@ describe('TypescriptVisitor', function () { it('should write a line for field name and type thats an array', () => { let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getName.returns('Bob'); mockField.getType.returns('Person'); mockField.isArray.returns(true); diff --git a/packages/concerto-tools/test/codegen/fromcto/xmlschema/xmlschemavisitor.js b/packages/concerto-tools/test/codegen/fromcto/xmlschema/xmlschemavisitor.js index 377235631a..15a808409a 100644 --- a/packages/concerto-tools/test/codegen/fromcto/xmlschema/xmlschemavisitor.js +++ b/packages/concerto-tools/test/codegen/fromcto/xmlschema/xmlschemavisitor.js @@ -47,7 +47,7 @@ describe('XmlSchemaVisitor', function () { it('should return visitEnumDeclaration for a EnumDeclaration', () => { let thing = sinon.createStubInstance(EnumDeclaration); - thing._isEnumDeclaration = true; + thing.isEnum.returns(true); let mockSpecialVisit = sinon.stub(xmlSchemaVisitor, 'visitEnumDeclaration'); mockSpecialVisit.returns('Duck'); @@ -58,7 +58,7 @@ describe('XmlSchemaVisitor', function () { it('should return visitClassDeclaration for a ClassDeclaration', () => { let thing = sinon.createStubInstance(ClassDeclaration); - thing._isClassDeclaration = true; + thing.isClassDeclaration.returns(true); let mockSpecialVisit = sinon.stub(xmlSchemaVisitor, 'visitClassDeclaration'); mockSpecialVisit.returns('Duck'); @@ -69,7 +69,7 @@ describe('XmlSchemaVisitor', function () { it('should return visitField for a Field', () => { let thing = sinon.createStubInstance(Field); - thing._isField = true; + thing.isField.returns(true); let mockSpecialVisit = sinon.stub(xmlSchemaVisitor, 'visitField'); mockSpecialVisit.returns('Duck'); @@ -80,7 +80,7 @@ describe('XmlSchemaVisitor', function () { it('should return visitRelationship for a RelationshipDeclaration', () => { let thing = sinon.createStubInstance(RelationshipDeclaration); - thing._isRelationshipDeclaration = true; + thing.isRelationship.returns(true); let mockSpecialVisit = sinon.stub(xmlSchemaVisitor, 'visitRelationship'); mockSpecialVisit.returns('Duck'); @@ -91,7 +91,7 @@ describe('XmlSchemaVisitor', function () { it('should return visitEnumValueDeclaration for a EnumValueDeclaration', () => { let thing = sinon.createStubInstance(EnumValueDeclaration); - thing._isEnumValueDeclaration = true; + thing.isEnumValue.returns(true); let mockSpecialVisit = sinon.stub(xmlSchemaVisitor, 'visitEnumValueDeclaration'); mockSpecialVisit.returns('Duck'); @@ -116,19 +116,19 @@ describe('XmlSchemaVisitor', function () { }; let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.accept = function(visitor, parameters) { return visitor.visit(this, parameters); }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getNamespace.returns('org.imported'); mockModelManager.getType.returns(mockClassDeclaration); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getImports.returns([]); mockModelFile.getModelManager.returns(mockModelManager); @@ -162,20 +162,20 @@ describe('XmlSchemaVisitor', function () { }; let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.accept = function(visitor, parameters) { return visitor.visit(this, parameters); }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getNamespace.returns('org.imported'); mockModelManager.getType.returns(mockClassDeclaration); let mockModelFile = sinon.createStubInstance(ModelFile); mockModelFile.getImports.returns([]); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getModelManager.returns(mockModelManager); mockModelFile.accept = function(visitor, parameters) { @@ -207,32 +207,32 @@ describe('XmlSchemaVisitor', function () { }; let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.accept = function(visitor, parameters) { return visitor.visit(this, parameters); }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getNamespace.returns('org.imported'); mockClassDeclaration.getName.returns('ImportedType'); mockModelManager.getType.withArgs('org.imported.ImportedType').returns(mockClassDeclaration); let mockClassDeclaration2 = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration2._isClassDeclaration = true; + mockClassDeclaration2.isClassDeclaration.returns(true); mockClassDeclaration2.getNamespace.returns('org.imported'); mockClassDeclaration.getName.returns('AnotherImportedType'); mockModelManager.getType.withArgs('org.imported.AnotherImportedType').returns(mockClassDeclaration2); let mockClassDeclaration3 = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration3._isClassDeclaration = true; + mockClassDeclaration3.isClassDeclaration.returns(true); mockClassDeclaration3.getNamespace.returns('org.different'); mockClassDeclaration3.getName.returns('Type'); mockModelManager.getType.withArgs('org.different.Type').returns(mockClassDeclaration3); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getModelManager.returns(mockModelManager); mockModelFile.getImports.returns(['org.imported.ImportedType','org.imported.AnotherImportedType', 'org.different.Type']); @@ -271,7 +271,7 @@ describe('XmlSchemaVisitor', function () { }; let mockEnumDeclaration = sinon.createStubInstance(EnumDeclaration); - mockEnumDeclaration._isEnumDeclaration = true; + mockEnumDeclaration.isEnum.returns(true); mockEnumDeclaration.getName.returns('Person'); mockEnumDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -281,9 +281,9 @@ describe('XmlSchemaVisitor', function () { }]); let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getModelManager.returns(mockModelManager); mockEnumDeclaration.getModelFile.returns(mockModelFile); @@ -306,16 +306,16 @@ describe('XmlSchemaVisitor', function () { }; let mockSuperType = sinon.createStubInstance(EnumDeclaration); - mockSuperType._isEnumDeclaration = true; + mockSuperType.isEnum.returns(true); mockSuperType.getName.returns('Human'); mockSuperType.getNamespace.returns('org.acme'); let mockEnumDeclaration = sinon.createStubInstance(EnumDeclaration); - mockEnumDeclaration._isEnumDeclaration = true; + mockEnumDeclaration.isEnum.returns(true); let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.getType.returns(mockSuperType); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getModelManager.returns(mockModelManager); mockEnumDeclaration.getModelFile.returns(mockModelFile); @@ -355,7 +355,7 @@ describe('XmlSchemaVisitor', function () { }; let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getOwnProperties.returns([{ accept: acceptSpy @@ -383,18 +383,18 @@ describe('XmlSchemaVisitor', function () { }; let mockSuperType = sinon.createStubInstance(ClassDeclaration); - mockSuperType._isClassDeclaration = true; + mockSuperType.isClassDeclaration.returns(true); mockSuperType.getNamespace.returns('org.acme'); mockSuperType.getName.returns('Human'); let mockModelManager = sinon.createStubInstance(ModelManager); - mockModelManager._isModelManager = true; + mockModelManager.isModelManager.returns(true); mockModelManager.getType.returns(mockSuperType); let mockModelFile = sinon.createStubInstance(ModelFile); - mockModelFile._isModelFile = true; + mockModelFile.isModelFile.returns(true); mockModelFile.getModelManager.returns(mockModelManager); let mockClassDeclaration = sinon.createStubInstance(ClassDeclaration); - mockClassDeclaration._isClassDeclaration = true; + mockClassDeclaration.isClassDeclaration.returns(true); mockClassDeclaration.getModelFile.returns(mockModelFile); mockClassDeclaration.getName.returns('Person'); mockClassDeclaration.getNamespace.returns('org.acme'); @@ -429,7 +429,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('String'); mockField.getName.returns('Bob'); @@ -443,7 +443,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('Long'); mockField.getName.returns('Bob'); @@ -457,7 +457,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('Double'); mockField.getName.returns('Bob'); @@ -471,7 +471,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('DateTime'); mockField.getName.returns('Bob'); @@ -485,7 +485,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('Boolean'); mockField.getName.returns('Bob'); @@ -499,7 +499,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('Integer'); mockField.getName.returns('Bob'); @@ -513,7 +513,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('org.acme.Foo'); mockField.getName.returns('Bob'); @@ -527,7 +527,7 @@ describe('XmlSchemaVisitor', function () { }; let mockField = sinon.createStubInstance(Field); - mockField._isField = true; + mockField.isField.returns(true); mockField.getFullyQualifiedTypeName.returns('String'); mockField.getName.returns('Bob'); mockField.isArray.returns(true); @@ -544,7 +544,7 @@ describe('XmlSchemaVisitor', function () { }; let mockEnumValueDecl = sinon.createStubInstance(EnumValueDeclaration); - mockEnumValueDecl._isEnumValueDeclaration = true; + mockEnumValueDecl.isEnumValue.returns(true); mockEnumValueDecl.getName.returns('Bob'); xmlSchemaVisitor.visitEnumValueDeclaration(mockEnumValueDecl, param); @@ -560,7 +560,7 @@ describe('XmlSchemaVisitor', function () { }; let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getFullyQualifiedTypeName.returns('String'); xmlSchemaVisitor.visitRelationship(mockRelationship, param); @@ -574,7 +574,7 @@ describe('XmlSchemaVisitor', function () { }; let mockRelationship = sinon.createStubInstance(RelationshipDeclaration); - mockRelationship._isRelationshipDeclaration = true; + mockRelationship.isRelationship.returns(true); mockRelationship.getFullyQualifiedTypeName.returns('String'); mockRelationship.getName.returns('Bob'); mockRelationship.isArray.returns(true);