-
Notifications
You must be signed in to change notification settings - Fork 59
Update reflectable such that test_reflectable can run tests using pub run build_runner test
#119
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
Conversation
… build_runner test`
Also removed unused imports.
…generator input file
…er generalization
@@ -835,7 +852,7 @@ class _ReflectorDomain { | |||
classDomain._instanceMembers.forEach(members.add); | |||
|
|||
// Add all the formal parameters (as a single, global set) which | |||
// are declared by any of the methods in `classDomain._declarations` | |||
// are declared by any of the methods in `classDomain._declarations` |
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.
Stray space?
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.
Indeed, fixed.
@@ -856,8 +873,7 @@ class _ReflectorDomain { | |||
} else if (variable is TopLevelVariableElement) { | |||
topLevelVariables.add(variable); | |||
} else { | |||
throw unimplementedError( | |||
"This kind of variable is not yet supported"); | |||
logger.error("This kind of variable is not yet supported"); |
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.
Can you add the typename to the error message for easier diagnostics?
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.
// Requested: just the name of the typedef; get it and return. | ||
int dartTypeNumber = typedefs.containsKey(dartType) | ||
? typedefs[dartType] | ||
: typedefNumber++; |
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.
Could you use typedefs.size instead of typedefNumber?
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.
Resolved IRL: Could not do that due to ordering conflicts in the collection of information about typedefs.
typeVariablesInScope = new Set<String>(); | ||
} | ||
for (TypeParameterElement element in dartType.typeFormals) { | ||
typeVariablesInScope.add(element.name); |
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.
Nit: You can use Set.addAll
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.
} else { | ||
// Requested: the spelled-out generic function type; continue. | ||
if (typeVariablesInScope == null) { | ||
typeVariablesInScope = new Set<String>(); |
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.
Nit: Could be
typeVariablesInScope ?= new Set<String>();
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.
importCollector, typeVariablesInScope, typedefs, logger, | ||
useNameOfGenericFunctionType: useNameOfGenericFunctionType); | ||
String typeArguments = ""; | ||
if (!dartType.typeFormals.isEmpty) { |
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.
Nit: we have Set.isNotEmpty
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.
Fixed several similar occurrences.
_capabilities, constructorName, _getEvaluatedMetadata(metadata)); | ||
Resolver resolver, | ||
TransformLogger logger) { | ||
var result = _supportsNewInstance(_capabilities, constructorName, |
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.
Nit: Could you just
return _supportsNewInstance(...);
?
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 (was an leftover from printf debugging).
@@ -2596,22 +2773,26 @@ class _Capabilities { | |||
bool supportsInstanceInvoke( | |||
String methodName, | |||
Iterable<ElementAnnotation> metadata, | |||
Iterable<ElementAnnotation> getterMetadata) { | |||
Iterable<ElementAnnotation> getterMetadata, | |||
TransformLogger logger) { | |||
var v = _supportsInstanceInvoke( |
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.
Nit: Could you just
return _supportsInstanceInvoke(...);
?
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.
@@ -3774,6 +3973,7 @@ initializeReflectable() { | |||
if (const bool.fromEnvironment("reflectable.pause.at.exit")) { | |||
_processedEntryPointCount++; | |||
} | |||
_resolver.release(); |
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.
Could we wrap this code in a local function, so we only have to release the resolver in one spot?
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.
Reorganized the code without abstractions, because they seemed to require a non-local return. See https://dartpad.dartlang.org/e6351d655334455c511288345c5fbaec for details.
One rather voluminous change in this PR is about function types: Until now, reflectable was not aware of inline function types (like an inline
int Function()
, as opposed to the ones which were defined indirectly defined via atypedef
). This PR introduces support for the new function type syntax.There is one outstanding issue: We cannot recognize generic function types, because they must be defined in terms of a
typedef
, and the correspondingType
objects are not equal even though two giventypedef
s define the same generic function type. However, it is still possible to use generic function types if they are defined via atypedef
and the client is careful to always use the sametypedef
for the same function type. This will be fixed, but this is a change toType
and not a change to reflectable.A number of other changes are associated with the "administration" of the package, e.g.,
.gitignore
was updated to match the new paths used by Dart tools for generated files, CHANGELOG.md and README.md were updated, and so was pubspec.yaml. Changes tobuild.yaml
were necessary in order to get the desired behavior of the build package (which handles code generation and accepts the reflectable code generator as a kind of plugin).