diff --git a/packages/concerto-core/lib/introspect/mapkeytype.js b/packages/concerto-core/lib/introspect/mapkeytype.js index acf7ef280..51a3b31e6 100644 --- a/packages/concerto-core/lib/introspect/mapkeytype.js +++ b/packages/concerto-core/lib/introspect/mapkeytype.js @@ -71,7 +71,8 @@ class MapKeyType extends Decorated { validate() { if (!ModelUtil.isPrimitiveType(this.type)) { - const decl = ModelUtil.getTypeDeclaration(this.ast.type.name, this.modelFile); + + const decl = this.modelFile.getType(this.ast.type.name); if (!ModelUtil.isValidMapKeyScalar(decl)) { throw new IllegalModelException( diff --git a/packages/concerto-core/lib/introspect/mapvaluetype.js b/packages/concerto-core/lib/introspect/mapvaluetype.js index 9ede733a0..0ea4d8a6a 100644 --- a/packages/concerto-core/lib/introspect/mapvaluetype.js +++ b/packages/concerto-core/lib/introspect/mapvaluetype.js @@ -69,7 +69,8 @@ class MapValueType extends Decorated { */ validate() { if (!ModelUtil.isPrimitiveType(this.type)) { - const decl = ModelUtil.getTypeDeclaration(this.ast.type.name, this.modelFile); + + const decl = this.modelFile.getType(this.ast.type.name); // All declarations, with the exception of MapDeclarations, are valid Values. if(decl.isMapDeclaration?.()) { diff --git a/packages/concerto-core/lib/modelutil.js b/packages/concerto-core/lib/modelutil.js index 44a269d0b..d83210b21 100644 --- a/packages/concerto-core/lib/modelutil.js +++ b/packages/concerto-core/lib/modelutil.js @@ -338,21 +338,6 @@ class ModelUtil { `${MetaModelNamespace}.ObjectMapValueType` ].includes(value.$class); } - - /** - * Returns the corresponding ClassDeclaration representation of the Map Type - * @param {string} type - the Type of the Map Value - * @param {ModelFile} modelFile - the ModelFile that owns the Property - * @return {Object} the corresponding ClassDeclaration representation - */ - static getTypeDeclaration(type, modelFile) { - if (modelFile.isLocalType(type)) { - return modelFile.getAllDeclarations().find(d => d.name === type); - } else { - const fqn = modelFile.resolveImport(type); - return modelFile.getModelManager().getType(fqn); - } - } } module.exports = ModelUtil; diff --git a/packages/concerto-core/test/data/parser/mapdeclaration/base.cto b/packages/concerto-core/test/data/parser/mapdeclaration/base.cto index 867f10ee5..d18ec501d 100644 --- a/packages/concerto-core/test/data/parser/mapdeclaration/base.cto +++ b/packages/concerto-core/test/data/parser/mapdeclaration/base.cto @@ -18,3 +18,8 @@ concept Thing { } scalar Time extends DateTime + +enum Stuff { + o Thing + o Foo +} diff --git a/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.declaration.participant.cto b/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.declaration.participant.cto index c3d08c9cc..0c2f4a697 100644 --- a/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.declaration.participant.cto +++ b/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.declaration.participant.cto @@ -13,11 +13,11 @@ */ namespace com.testing@1.0.0 -participant Customer identified by email { +participant CustomerParticipant identified by email { o String email } map Customer { o String - o Customer + o CustomerParticipant } diff --git a/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.thing.cto b/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.concept.cto similarity index 100% rename from packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.thing.cto rename to packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.concept.cto diff --git a/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.scalar.cto b/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.scalar.cto new file mode 100644 index 000000000..0acc76113 --- /dev/null +++ b/packages/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.scalar.cto @@ -0,0 +1,21 @@ +/* + * 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 com.testing@1.0.0 + +import com.testing.base@1.0.0.Time + +map Dictionary { + o String + o Time +} diff --git a/packages/concerto-core/test/introspect/mapdeclaration.js b/packages/concerto-core/test/introspect/mapdeclaration.js index c5e753f35..bc3d73ac4 100644 --- a/packages/concerto-core/test/introspect/mapdeclaration.js +++ b/packages/concerto-core/test/introspect/mapdeclaration.js @@ -263,10 +263,17 @@ describe('MapDeclaration', () => { decl.validate(); }); - it('should validate when map value is imported and is of valid map key type', () => { + it('should validate when map value is imported and is of valid map key type (Concept import)', () => { const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8'); introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto'); - let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.thing.cto', MapDeclaration); + let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.concept.cto', MapDeclaration); + decl.validate(); + }); + + it('should validate when map value is imported and is of valid map key type (Scalar Import)', () => { + const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8'); + introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto'); + let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.scalar.cto', MapDeclaration); decl.validate(); }); }); diff --git a/packages/concerto-core/types/lib/modelutil.d.ts b/packages/concerto-core/types/lib/modelutil.d.ts index 1ee8ce2d4..0ee83e4b3 100644 --- a/packages/concerto-core/types/lib/modelutil.d.ts +++ b/packages/concerto-core/types/lib/modelutil.d.ts @@ -162,12 +162,4 @@ declare class ModelUtil { * @return {boolean} true if the Value is a valid Map Value */ static isValidMapValue(value: any): boolean; - /** - * Returns the corresponding ClassDeclaration representation of the Map Type - * @param {string} type - the Type of the Map Value - * @param {ModelFile} modelFile - the ModelFile that owns the Property - * @return {Object} the corresponding ClassDeclaration representation - */ - static getTypeDeclaration(type: string, modelFile: ModelFile): any; } -import ModelFile = require("../lib/introspect/modelfile");