Comments (3)
Hi Dan,
with recent versions of reflectable we have some implications: declarationsCapability
is an instance of a subtype of the type of typeCapability
, and this means that you cannot have declarationsCapability
without typeCapability
. The point is that you can never reach any declarations if you cannot reach any types, so declarationsCapability
makes no sense without typeCapability
.
That was the first step. Second: When you have typeCapability
you can also get a mirror of the class of a type annotation for any given declaration mirror (e.g., with a field among the declarations, you can get the class of the type annotation in the declaration of that variable, if any; similarly for method arguments and return types). We even follow that track recursively: If support for a class C
causes support for a class D
used as a type annotation in C
, then you will also get support for class E
if it is used in a type annotation in D
(all of this: if your capabilities provide support for those members, which might not be the case if you are using ..Meta..
capabilities or using a non-trivial regexp). This is already enough of a reason to make your supported universe larger than you expect---and need, presumably. This also matches the situation as you described it.
If this is the right diagnostic then there is a solution which is just about to be released:
We have introduced the notion of typeAnnotationQuatifyCapability
to give you more control. The idea is that the transitive closure of types reachable via type annotations is not any more taken as soon as you have the typeCapability
and declarationsCapability
, we only take that step if you request it explicitly.
You do that by including typeAnnotationQuatifyCapability
or typeAnnotationDeepQuatifyCapability
among your capabilities (both instances of a class but providing different arguments for a constructor argument called transitive
); the former will cause type annotation classes to be included in one step, and the latter will run a fixed point iteration such that all reachable types (traversing declarations and their types) are included. With deep/transitive quantification we have the old behavior that you are probably using today. If you don't include any of them then you don't get any of the type annotation classes at all (except of course if you have included some of them in some other way).
You can get support for the new quantifiers by switching to commit 195e18b of reflectable or something newer (not yet published, and it only implements the quantifiers for non-transformed code so you can test but you can't really see the space improvement; but it's just about ready for transformed code as well and then we'll publish it in a version '0.3.').
I'm closing the issue now because I think the solution is upcoming. Please create a new issue if it turns out to be a different problem.
from reflectable.dart.
Thanks, that sounds like what I'm looking for.
from reflectable.dart.
Hey @eernstg, I tried out the latest release (0.3.2) and I'm having some issues with the new typeAnnotationQuantifyCapability
. When reflecting on an instance, it returns null
for InstanceMirror.type
.
What I'm trying to do is define a class that I can mixin, and be able to inspect the values of the host. For example, something like:
class Person extends Object with Inspectable {
final String name;
}
var person = new Person("Jim");
print(person.inspect()); // Person {name: "Jim"}
My Reflectable
and mixin looks like this:
class ReflectSubtypes extends Reflectable {
const ReflectSubtypes() : super(typeAnnotationQuantifyCapability, instanceInvokeCapability, subtypeQuantifyCapability);
}
const _inspector = const ReflectSubtypes();
@ReflectSubtypes()
class Inspectable {
Map<String, dynamic> inspectValues() {
var mirror = _inspector.reflect(this);
var valueMirrors = mirror.type.declarations.values.where((value) => value is VariableMirror);
var valueMap = new Map.fromIterable(valueMirrors,
key: (value) => value.simpleName,
value: (value) => mirror.invokeGetter(value.simpleName));
return valueMap;
}
String inspect() {
return _inspectWithOptions();
}
String _inspectWithOptions({String indent: ""}) {
var mirror = _inspector.reflect(this);
var buffer = new StringBuffer();
buffer.writeln("$indent${mirror.type.qualifiedName} {");
inspectValues().forEach((key, value) {
if (value is Inspectable) {
value = value._inspectWithOptions(indent: "$indent ").trim();
}
buffer.writeln("$indent $key: $value");
});
buffer.writeln("$indent}");
return buffer.toString();
}
}
Any help on the correct capabilities to use that'll have the smallest JS output would be appreciated.
from reflectable.dart.
Related Issues (20)
- [question] - Is it possible to have Annotations with Parameters? HOT 2
- [Question] - how to get Constructor arguments? HOT 2
- [Bug?] ERROR: This requires the 'constructor-tearoffs' language feature to be enabled. HOT 12
- [Question] - Listening to Method invocation HOT 6
- [Question] - Stats on Bundle Sizes and Performance Implications/metrics of using Reflectable ? HOT 1
- Cannot reflect ```flutter/material.dart``` URIs for ```Container``` type HOT 12
- This reflector does not match anything HOT 11
- Reflectable is not a know builder HOT 1
- Unsupported operation: location HOT 4
- Reflectable don't find "main" but im using in my library not an application HOT 5
- How to generate code according to filter rules HOT 2
- The build_runner those not generate anything HOT 1
- Annotated parameter and Functions
- Include annotated types that are not imported to `main.dart` HOT 2
- Severe error during build with @reflector and @JsonKey on the same class. HOT 1
- isSubtype exception for classes without parents HOT 2
- Where is initializeReflectable method? HOT 3
- Error: Reflecting on un-marked type "Type" HOT 2
- bug: issue with using mixins HOT 5
- importing private libaries during build_runner build HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reflectable.dart.