Skip to content

Commit d648566

Browse files
feat(ModelFile): model file class declarations (#695)
* feat(maps): adds getClassDeclarations Signed-off-by: jonathan.casey <[email protected]> * feat(maps): adds type definition Signed-off-by: jonathan.casey <[email protected]> * feat(maps): adds test Signed-off-by: jonathan.casey <[email protected]> * feat(maps): updates api.txt Signed-off-by: jonathan.casey <[email protected]> * feat(maps): updates changelog hash Signed-off-by: jonathan.casey <[email protected]> --------- Signed-off-by: jonathan.casey <[email protected]>
1 parent 8894748 commit d648566

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

packages/concerto-core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class ModelFile extends Decorated {
211211
+ TransactionDeclaration[] getTransactionDeclarations()
212212
+ EventDeclaration[] getEventDeclarations()
213213
+ ParticipantDeclaration[] getParticipantDeclarations()
214+
+ ClassDeclaration[] getClassDeclarations()
214215
+ ConceptDeclaration[] getConceptDeclarations()
215216
+ EnumDeclaration[] getEnumDeclarations()
216217
+ MapDeclaration[] getMapDeclarations()

packages/concerto-core/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
# Note that the latest public API is documented using JSDocs and is available in api.txt.
2525
#
2626

27+
Version 3.12.2 {bb8951ea059e312cd347b715bc9fc8d7} 2023-08-28
28+
- Adds ModelFile :: getClassDeclarations
29+
2730
Version 3.10.1 {399b057614d1178c02b744184b09f845} 2023-08-22
2831
- Change return type for MapDeclaration :: MapKeyType MapValueType
2932

packages/concerto-core/lib/introspect/modelfile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const packageJson = require('../../package.json');
2020
const semver = require('semver');
2121
const AssetDeclaration = require('./assetdeclaration');
2222
const EnumDeclaration = require('./enumdeclaration');
23+
const ClassDeclaration = require('./classdeclaration');
2324
const ConceptDeclaration = require('./conceptdeclaration');
2425
const ScalarDeclaration = require('./scalardeclaration');
2526
const ParticipantDeclaration = require('./participantdeclaration');
@@ -575,6 +576,14 @@ class ModelFile extends Decorated {
575576
return this.getDeclarations(ParticipantDeclaration);
576577
}
577578

579+
/**
580+
* Get the ClassDeclarations defined in this ModelFile
581+
* @return {ClassDeclaration[]} the ClassDeclarations defined in the model file
582+
*/
583+
getClassDeclarations() {
584+
return this.getDeclarations(ClassDeclaration);
585+
}
586+
578587
/**
579588
* Get the ConceptDeclarations defined in this ModelFile
580589
* @return {ConceptDeclaration[]} the ParticipantDeclaration defined in the model file

packages/concerto-core/test/introspect/modelfile.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const should = chai.should();
3737
chai.use(require('chai-things'));
3838
const sinon = require('sinon');
3939
const ScalarDeclaration = require('../../lib/introspect/scalardeclaration');
40+
const ClassDeclaration = require('../../lib/introspect/classdeclaration');
4041

4142
describe('ModelFile', () => {
4243

@@ -720,6 +721,15 @@ describe('ModelFile', () => {
720721
});
721722
});
722723

724+
describe('#getClassDeclarations', () => {
725+
it('should return the expected number of Class declarations', () => {
726+
let modelFile = ParserUtil.newModelFile(modelManager, carLeaseModel);
727+
let decls = modelFile.getClassDeclarations();
728+
decls.should.all.be.an.instanceOf(ClassDeclaration);
729+
decls.length.should.equal(16);
730+
});
731+
});
732+
723733
describe('#getFullyQualifiedTypeName', () => {
724734
it('should return null if not prmative, imported or local type', () => {
725735
const ast = {

packages/concerto-core/types/lib/introspect/modelfile.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ declare class ModelFile extends Decorated {
202202
* @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model file
203203
*/
204204
getParticipantDeclarations(): ParticipantDeclaration[];
205+
/**
206+
* Get the ClassDeclarations defined in this ModelFile
207+
* @return {ClassDeclaration[]} the ClassDeclarations defined in the model file
208+
*/
209+
getClassDeclarations(): ClassDeclaration[];
205210
/**
206211
* Get the ConceptDeclarations defined in this ModelFile
207212
* @return {ConceptDeclaration[]} the ParticipantDeclaration defined in the model file

0 commit comments

Comments
 (0)