Skip to content

Refactor Container class and children #2206

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

Merged
merged 7 commits into from
May 11, 2020
Merged

Refactor Container class and children #2206

merged 7 commits into from
May 11, 2020

Conversation

jcollins-g
Copy link
Contributor

@jcollins-g jcollins-g commented May 8, 2020

Rename and change semantics for many getters on the Container class.

This makes Dartdoc's use of terminology for class members more closely aligned with Dart and Analyzer internals, and improves separation between the generation layer and Dartdoc internals.

  • "Properties" are now called Fields internally outside of the templates themselves.
  • Move everything having to do with inheritance to the Class class out of Container.
  • Move everything common to all Containers out of Class and into Container and eliminate some duplication.
  • Use a consistent naming scheme for template getters in particular:
    • sorted for getters where ordering matters. Don't store and sort lists of items over and over for non-documented ModelElements.
    • staticFields now includes constant static fields, variableStaticFields has the old behavior.
    • instanceMethods and instanceFields for non-statics, rather than methods excluding statics by default.
  • Compose getters out of words with consistent meanings, e.g. hasPublicInheritedFields and publicConstantFields rather than using so many abbreviations, so templates are clearer.

Note: this completely breaks markdown generation until the templates are updated. Will add a smoke test for markdown and update those templates in a followup.

@googlebot googlebot added the cla: yes Google CLA check succeeded. label May 8, 2020
@coveralls
Copy link

coveralls commented May 8, 2020

Coverage Status

Coverage decreased (-0.04%) to 91.44% when pulling 02b8138 on nnbd-pre-cleanup into 1196ef0 on master.

@jcollins-g jcollins-g marked this pull request as ready for review May 8, 2020 23:46
Copy link
Contributor

@jdkoren jdkoren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcollins-g There are a lot of additions under testing/test_package_custom_templates/templates. That directory really only exists to check that running with the --templates-dir option works; IMO those templates don't need to exercise all the features or access all the template-able members, and I didn't intially intend for them to do that since since other tests will. Is there a reason you feel those additions are necessary?

Will do another pass on the rest a bit later.

@jcollins-g
Copy link
Contributor Author

I didn't want to hand-edit all the templates so I just copied the whole directory across for the templates-dir test, modifying only the index so it's possible to tell the difference by examining the output (and therefore verifying that dartdoc is using the right template dir).

There is probably a better way to do this, open to better ideas.

Copy link
Member

@srawlins srawlins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming and reorganization looks good.

Full disclosure I did not thoroughly review HTML / markdown templates; just scanned.

Iterable<Method> get declaredMethods =>
_declaredMethods ??= element.methods.map((e) {
return ModelElement.from(e, library, packageGraph) as Method;
}).toList(growable: false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, does the toList here add anything important?

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 don't think so. Removed.

bool get isExtension => element is ExtensionElement;

List<Method> get methods => [];
@mustCallSuper
Iterable<ModelElement> get allModelElements => quiver.concat([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should we just use spread here? Does quiver.concat buy us something in a getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quiver.concat allows for lazy evaluation. Perhaps that is unimportant compared to the clarity of the spread operator, though....

@jdkoren
Copy link
Contributor

jdkoren commented May 11, 2020

I didn't want to hand-edit all the templates so I just copied the whole directory across for the templates-dir test, modifying only the index so it's possible to tell the difference by examining the output (and therefore verifying that dartdoc is using the right template dir).

Checking the index afterward for a specific string seems reasonable.

I did sort of like that the template directories were quite different as it ensures that we don't inadvertently rely on specific filenames or directory structure (aside from what's documented in the help string). Not sure how strongly I feel about it, though.

@jcollins-g
Copy link
Contributor Author

@jdkoren I hear you on not wanting to throw out any coverage we might have been getting there. However, code coverage results suggests we didn't lose much by changing to a simpler construction, though. Yes, we probably should be testing edge cases in custom templating more effectively. Maybe at some point we can do that with more deliberate intention.

@jcollins-g jcollins-g merged commit 5da18a7 into master May 11, 2020
@jcollins-g jcollins-g deleted the nnbd-pre-cleanup branch May 11, 2020 23:50
jcollins-g added a commit that referenced this pull request May 11, 2020
jcollins-g added a commit that referenced this pull request May 12, 2020
* intermediate

* tests pass, ship it

* Fix a missing variable static fields change in mixin template

* Fix some remaining templating bugs

* Review comments

* Update markdown templates per #2206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants