-
Notifications
You must be signed in to change notification settings - Fork 107
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
Remove some analyzer ast and src imports #384
Conversation
- Use `LibraryElement.exportNamespace` to find types across a libraries entire visible surface area rather than referencing a `NamespaceBuilder`. - Use the different getters for element typs from `CompilationUnitElement` to get all members of a library rather than getting the declarations from a `CompilationUnit`. - Increase minimum anlayzer version to ensure that the `mixins` getter is available.
for (var compUnitMember in cu.unit.declarations) { | ||
yield* _getElements(compUnitMember); | ||
} | ||
yield* cu.accessors; |
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'd be GREAT if analyzer had an API for this ( CC @scheglov @bwilkerson ) – could we get a TODO in here w/ a feature request?
These are places where things fall apart for weird reasons if things are reclassified, etc...
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.
Filed dart-lang/sdk#34892
source_gen/pubspec.yaml
Outdated
@@ -1,12 +1,12 @@ | |||
name: source_gen | |||
version: 0.9.1+3 | |||
version: 0.9.2-dev | |||
author: Dart Team <[email protected]> | |||
description: Automated source code generation for Dart. | |||
homepage: https://github.com/dart-lang/source_gen | |||
environment: | |||
sdk: '>=2.0.0-dev.64.0 <3.0.0' |
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.
Might as well drop 2.0.0-dev version support while you're at it...
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.
Done
import 'package:analyzer/dart/element/element.dart'; | ||
// ignore: implementation_imports | ||
import 'package:analyzer/src/dart/resolver/scope.dart'; |
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.
Nice to get rid of src
imports!
ClassElement findType(String name) { | ||
var type = element.exportNamespace.get(name); | ||
return type is ClassElement ? type : null; | ||
} | ||
|
||
/// All of the declarations in this library. | ||
Iterable<Element> get allElements sync* { | ||
for (var cu in element.units) { |
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.
So units
is fine but unit
isn't?
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.
Yup, one gives CompilationUnitElement
and the other CompilationUnit
.
Yes. Members that access elements from the element model are safe; members
that access the AST from the element model are not.
…On Mon, Oct 22, 2018 at 7:17 AM Jacob MacDonald ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In source_gen/lib/src/library.dart
<#384 (comment)>:
> /// Returns a top-level [ClassElement] publicly visible in by [name].
///
/// Unlike [LibraryElement.getType], this also correctly traverses identifiers
/// that are accessible via one or more `export` directives.
- ClassElement findType(String name) =>
- element.getType(name) ?? _namespace.get(name) as ClassElement;
+ ClassElement findType(String name) {
+ var type = element.exportNamespace.get(name);
+ return type is ClassElement ? type : null;
+ }
/// All of the declarations in this library.
Iterable<Element> get allElements sync* {
for (var cu in element.units) {
So units is fine but unit isn't?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#384 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFkeqxqo_pcHihNrrJuPSXAlOz09xwDoks5undOGgaJpZM4Xxm_n>
.
|
- Use `LibraryElement.exportNamespace` to find types across a libraries entire visible surface area rather than referencing a `NamespaceBuilder`. - Use the different getters for element types from `CompilationUnitElement` to get all members of a library rather than getting the declarations from a `CompilationUnit`. - Increase minimum analyzer version to ensure that the `mixins` getter is available.
- Use `LibraryElement.exportNamespace` to find types across a libraries entire visible surface area rather than referencing a `NamespaceBuilder`. - Use the different getters for element types from `CompilationUnitElement` to get all members of a library rather than getting the declarations from a `CompilationUnit`. - Increase minimum analyzer version to ensure that the `mixins` getter is available.
LibraryElement.exportNamespace
to find types across a librariesentire visible surface area rather than referencing a
NamespaceBuilder
.CompilationUnitElement
to get all members of a library rather thangetting the declarations from a
CompilationUnit
.mixins
getteris available.