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(jsii-reflect): library for exploring jsii type systems #328

Merged
merged 7 commits into from
Dec 5, 2018

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Dec 5, 2018

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.

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.
@eladb
Copy link
Contributor Author

eladb commented Dec 5, 2018

Related: aws/aws-cdk#181

packages/jsii-reflect/README.md Show resolved Hide resolved
packages/jsii-reflect/lib/assembly.ts Outdated Show resolved Hide resolved
packages/jsii-reflect/lib/interface.ts Show resolved Hide resolved
/**
* Visualizes a `TypeSystem` as an ASCII tree.
*/
export class TypeSystemTree extends AsciiTree {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

packages/jsii-reflect/test/jsii-tree.test.ts Show resolved Hide resolved
## 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

packages/jsii-reflect/README.md Show resolved Hide resolved
packages/jsii-reflect/bin/jsii-tree.ts Outdated Show resolved Hide resolved
packages/jsii-reflect/bin/jsii-tree.ts Show resolved Hide resolved
packages/jsii-reflect/lib/assembly.ts Outdated Show resolved Hide resolved
public getProperties(inherited = false) {
const out = new Array<Property>();
if (inherited && this.base) {
out.push(...this.base.getProperties(inherited));
Copy link
Contributor

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?

Copy link
Contributor Author

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?

packages/jsii-reflect/lib/method.ts Show resolved Hide resolved
packages/jsii-reflect/lib/tree.ts Show resolved Hide resolved
packages/jsii-reflect/lib/tree.ts Outdated Show resolved Hide resolved
packages/jsii-reflect/package.json Show resolved Hide resolved
packages/oo-ascii-tree/README.md Show resolved Hide resolved
@eladb eladb merged commit 69cdb32 into master Dec 5, 2018
@eladb eladb deleted the benisrae/jsii-reflect branch December 5, 2018 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants