-
Notifications
You must be signed in to change notification settings - Fork 20
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(vocabulary): vocab support for map in vocab auto generation #74
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ class VocabularyVisitor { | |
} else if (thing.isClassDeclaration?.()) { | ||
return this.visitDeclaration(thing, parameters); | ||
} else if (thing.isMapDeclaration?.()) { | ||
return; | ||
return this.visitMapDeclaration(thing, parameters); | ||
} else if (thing.isScalarDeclaration?.()) { | ||
return this.visitScalarDeclaration(thing, parameters); | ||
} else if (thing.isField?.()) { | ||
|
@@ -54,6 +54,10 @@ class VocabularyVisitor { | |
return this.visitProperty(thing, parameters); | ||
} else if (thing.isEnumValue?.()) { | ||
return this.visitProperty(thing, parameters); | ||
} else if (thing.isKey?.()) { | ||
return this.visitMapKey(thing, parameters); | ||
} else if (thing.isValue?.()) { | ||
return this.visitMapValue(thing, parameters); | ||
} | ||
else { | ||
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { | ||
|
@@ -141,6 +145,30 @@ class VocabularyVisitor { | |
return null; | ||
} | ||
|
||
/** | ||
* Visitor design pattern | ||
* @param {MapDeclaration} mapDeclaration - the object being visited | ||
* @param {Object} parameters - the parameter | ||
* @return {Object} the result of visiting or null | ||
* @private | ||
*/ | ||
visitMapDeclaration(mapDeclaration, parameters) { | ||
const mapDeclarationName = mapDeclaration.getName(); | ||
const mapDeclarationVocabulary = VocabularyManager.englishMissingTermGenerator(null, null, mapDeclarationName); | ||
|
||
parameters.fileWriter.writeLine(0, ` - ${mapDeclarationName}: ${mapDeclarationVocabulary}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the whitespaces before these lines standard? i.e., if this is adding to an existing vocab yaml file, will it be at the same indentation level as the one in the yaml file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we support passing an existing YAML file to this. The purpose of |
||
|
||
parameters.fileWriter.writeLine(0, ' properties:'); | ||
|
||
const mapKey = mapDeclaration.getKey(); | ||
const mapValue = mapDeclaration.getValue(); | ||
|
||
mapKey.accept(this, parameters); | ||
mapValue.accept(this, parameters); | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Visitor design pattern | ||
* @param {Property} property - the object being visited | ||
|
@@ -157,6 +185,38 @@ class VocabularyVisitor { | |
|
||
return null; | ||
} | ||
|
||
/** | ||
* Visitor design pattern | ||
* @param {MapKeyType} mapKey - the object being visited | ||
* @param {Object} parameters - the parameter | ||
* @return {Object} the result of visiting or null | ||
* @private | ||
*/ | ||
visitMapKey(mapKey, parameters) { | ||
const mapDeclarationName = mapKey.getParent().getName(); | ||
const mapKeyVocabulary = VocabularyManager.englishMissingTermGenerator(null, null, mapDeclarationName, 'KEY'); | ||
|
||
parameters.fileWriter.writeLine(0, ` - KEY: ${mapKeyVocabulary}`); | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Visitor design pattern | ||
* @param {MapValueType} mapValue - the object being visited | ||
* @param {Object} parameters - the parameter | ||
* @return {Object} the result of visiting or null | ||
* @private | ||
*/ | ||
visitMapValue(mapValue, parameters) { | ||
const mapDeclarationName = mapValue.getParent().getName(); | ||
const mapValueVocabulary = VocabularyManager.englishMissingTermGenerator(null, null, mapDeclarationName, 'VALUE'); | ||
|
||
parameters.fileWriter.writeLine(0, ` - VALUE: ${mapValueVocabulary}`); | ||
|
||
return null; | ||
} | ||
} | ||
|
||
module.exports = VocabularyVisitor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, it's a bit late to do anything about it now, but
isValue
looks a lot more generic than it should be. We could have made it likeisMapValue
, just as we did for declarations. Just a remark, nothing actionable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe to future-proof this, if possible, we can check if the parent of the
thing
is a map, os something similar to scope this to map declarations only. The same goes for the keys.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I believe keys and values are only scoped to Maps as of now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are suggesting for readability and interpretation, that's why kept the visitor method names as
visitMapKey
visitMapValue
.I agree with you the method name is very generic.