Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ModelFile): model file class declarations #695

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class ModelFile extends Decorated {
+ TransactionDeclaration[] getTransactionDeclarations()
+ EventDeclaration[] getEventDeclarations()
+ ParticipantDeclaration[] getParticipantDeclarations()
+ ClassDeclaration[] getClassDeclarations()
+ ConceptDeclaration[] getConceptDeclarations()
+ EnumDeclaration[] getEnumDeclarations()
+ MapDeclaration[] getMapDeclarations()
Expand Down
3 changes: 3 additions & 0 deletions packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 3.12.2 {bb8951ea059e312cd347b715bc9fc8d7} 2023-08-28
- Adds ModelFile :: getClassDeclarations

Version 3.10.1 {399b057614d1178c02b744184b09f845} 2023-08-22
- Change return type for MapDeclaration :: MapKeyType MapValueType

Expand Down
9 changes: 9 additions & 0 deletions packages/concerto-core/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const packageJson = require('../../package.json');
const semver = require('semver');
const AssetDeclaration = require('./assetdeclaration');
const EnumDeclaration = require('./enumdeclaration');
const ClassDeclaration = require('./classdeclaration');
const ConceptDeclaration = require('./conceptdeclaration');
const ScalarDeclaration = require('./scalardeclaration');
const ParticipantDeclaration = require('./participantdeclaration');
Expand Down Expand Up @@ -575,6 +576,14 @@ class ModelFile extends Decorated {
return this.getDeclarations(ParticipantDeclaration);
}

/**
* Get the ClassDeclarations defined in this ModelFile
* @return {ClassDeclaration[]} the ClassDeclarations defined in the model file
*/
getClassDeclarations() {
return this.getDeclarations(ClassDeclaration);
}

/**
* Get the ConceptDeclarations defined in this ModelFile
* @return {ConceptDeclaration[]} the ParticipantDeclaration defined in the model file
Expand Down
10 changes: 10 additions & 0 deletions packages/concerto-core/test/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const should = chai.should();
chai.use(require('chai-things'));
const sinon = require('sinon');
const ScalarDeclaration = require('../../lib/introspect/scalardeclaration');
const ClassDeclaration = require('../../lib/introspect/classdeclaration');

describe('ModelFile', () => {

Expand Down Expand Up @@ -720,6 +721,15 @@ describe('ModelFile', () => {
});
});

describe('#getClassDeclarations', () => {
it('should return the expected number of Class declarations', () => {
let modelFile = ParserUtil.newModelFile(modelManager, carLeaseModel);
let decls = modelFile.getClassDeclarations();
decls.should.all.be.an.instanceOf(ClassDeclaration);
decls.length.should.equal(16);
});
});

describe('#getFullyQualifiedTypeName', () => {
it('should return null if not prmative, imported or local type', () => {
const ast = {
Expand Down
5 changes: 5 additions & 0 deletions packages/concerto-core/types/lib/introspect/modelfile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ declare class ModelFile extends Decorated {
* @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model file
*/
getParticipantDeclarations(): ParticipantDeclaration[];
/**
* Get the ClassDeclarations defined in this ModelFile
* @return {ClassDeclaration[]} the ClassDeclarations defined in the model file
*/
getClassDeclarations(): ClassDeclaration[];
/**
* Get the ConceptDeclarations defined in this ModelFile
* @return {ConceptDeclaration[]} the ParticipantDeclaration defined in the model file
Expand Down