-
Notifications
You must be signed in to change notification settings - Fork 245
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(jsii-reflect): library for exploring jsii type systems #328
Conversation
jsii-reflect is a library for strong-type reflection of jsii type systems. it creates an in-memory object graph from .jsii module specifications and exposes a rich API for exploring the type system. jsii-tree is a command-line utility bundled with jsii-reflect which prints an ascii tree of a jsii type system. oo-ascii-tree is an object-oriented library for producing ascii trees. it supports multi-line nodes and some other cool features. See README files for more details.
Related: aws/aws-cdk#181 |
/** | ||
* Visualizes a `TypeSystem` as an ASCII tree. | ||
*/ | ||
export class TypeSystemTree extends AsciiTree { |
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.
Why inheritance? Why is-a
type system tree an ascii tree?
Couldn't visualizeTypeSystemTree()
be an operation that produces an AsciiTree?
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.
It is an is-a relationship, a TypeSystemTree is an AsciiTree. I can rename it to TypeSystemAsciiTree
if it will be clearer.
I didn't want a dependency between TypeSystem
and the AsciiTree
, so those are decoupled class hierarchies. I originally thought to extract jsii-tree
to a separate module, but for pragmatic reasons decided to just bundle it together with jsii-reflect
.
## Advanced Usage | ||
|
||
You can also subclass `AsciiTree` to encapsulate some model. The following | ||
example declares a `TitleNode` which formats a title with "====" underline and a |
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.
This is good, but there's no actual need to subclass right?
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.
It's a useful paradigm for certain use cases. Not required.
public getProperties(inherited = false) { | ||
const out = new Array<Property>(); | ||
if (inherited && this.base) { | ||
out.push(...this.base.getProperties(inherited)); |
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 this class is abstract, should this also include implemented interface's members?
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 believe it will include them since they will be explicitly called out in the class's API, or did I misunderstood you?
jsii-reflect is a library for strong-type reflection of jsii type systems. It creates an in-memory object graph from .jsii module specifications and exposes a rich API for exploring the type system.
jsii-tree is a command-line utility bundled with jsii-reflect which prints an ascii tree of a jsii type system.
oo-ascii-tree is an object-oriented library for producing ascii trees. It supports multi-line nodes and some other cool features.
See jsii-reflect README and oo-ascii-tree README for more details.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.