Comments (7)
The problem is that the
ClassTypeBuilder
onClassTypesMacro
can't return the properties and methods. Why can'tClassTypesMacro
access these values? What do you suggest to solve this?
Before I try to explain why (it's complicated), can I ask exactly what you need it for exactly? I don't see anything that specifically looks like you need to do this, in the types phase, in the example provided here.
First one assumption I am making, is that there were some typos here, correct me if I am wrong about them:
@GenerateModifier()
class OpacityModifier {
final double opacity;
/// Should this have been OpacityModifier? I am in general a bit confused how this class comes into play.
/// Is it really an interface?
const OpacityModifierSpec(this.opacity);
...
}
// Should the extended type have been WidgetModifierSpec<OpacityModifier>?
class OpacityModifierSpec extends WidgetModifierSpec<OpacityModifierSpec> { ... }
As far as generating the OpacityModifierSpec
, OpacityModifierAttribute
, and OpacityUtility
classes, all you need to generate is the header initially. It sounds like you are trying to generate the entire class up front. Instead, you should try to fill in the declarations and definitions in later phases, by applying macros to the classes which you add in the first phase.
So, you should have a ClassTypesMacro
, which when it calls declareType
, it only generates the following code, with additional macro annotations that will fill in the later code:
@GenerateModifierSpec()
class OpacityModifierSpec extends WidgetModifierSpec<OpacityModifier> {}
@GenerateModifierAttribute()
class OpacityModifierAttribute extends WidgetModifierAttribute<
OpacityModifierAttribute, OpacityModifierSpec> {}
@GenerateUtility()
class OpacityUtility<T extends Attribute>
extends MixUtility<T, OpacityModifierAttribute> {}
Each of these macros will implement ClassDeclarationsMacro
, and possibly ClassDefinitionsMacro
. These will add all the methods, and the implementations of those methods, to each of the classes.
If you need access to the original class you would provide that as an argument to the macros - so they would look like @GenerateModifierSpec(OpacityModifier)
as an example. This will not work today I don't think though, as it isn't implemented yet.
Let me know if I can help further, or if there is some additional thing I am missing here.
from language.
@jakemac53, Thank you for the answer!
Currently, for each attribute, we need to create those 3 classes, so my idea with the macros features is to generate them from a new simple class that contains only the attributes, the constructor, and the build method. However, as you said it's impossible to do today because I can't get those infos in the type phase.
from language.
By attribute, do you mean field, as in final double opacity;
?
You could require the macro to be applied to each field, although that isn't as nice to be sure.
It is possible we might in the future allow looking at the user written macros in this types phase also, but note that it means your macro would not compose well with other macros that want to add fields.
So, let's say somebody wrote a data class macro which generate fields based on a constructor signature. Your macro would not ever be able to see those fields.
from language.
Sorry, I didn't give you the context. Our package is to help Flutter Developers stylize their Widgets, and attributes
are how we named the methods that can apply style to the widget.
If you need access to the original class you would provide that as an argument to the macros - so they would look like @GenerateModifierSpec(OpacityModifier) as an example. This will not work today I don't think though, as it isn't implemented yet.
In your first answer, you mention providing the class as an argument. Will I be able to access the constructors, methods, and properties of this class in this manner?
from language.
In your first answer, you mention providing the class as an argument. Will I be able to access the constructors, methods, and properties of this class in this manner?
After the types phase, yes
from language.
Sorry, I didn't give you the context. Our package is to help Flutter Developers stylize their Widgets, and
attributes
are how we named the methods that can apply style to the widget.
In the example above, which thing is an attribute?
from language.
It is the class Attribute
. Each attribute can be applied as a Style for our own Widgets, and then they can be resolved in the Spec
.
from language.
Related Issues (20)
- Runtime Error when override a function where the parameter is a function that return a genetic type and the parameter is generic type. HOT 1
- Uninitialized final var is allowed and causes stack overflow HOT 4
- Allow augmenting an abstract variable with a concrete getter/setter? HOT 6
- Free Venezuela 🇻🇪 HOT 1
- `?.` operator doen't infere null safety HOT 4
- Add an operator `!??` for when an expression is not null HOT 2
- Do we allow static or library members whose implementation is omitted? HOT 9
- Allow `augmented` to be a regular identifier inside an augmenting declaration? HOT 8
- Optional parentheses HOT 5
- introduce move-semantics ,for efficient data-sharing between isolates HOT 4
- generic type should be non-null by default ,instead of requiring `<T extends Object>` to mandate non-null HOT 2
- Make duplication of superinterfaces a warning, not an error HOT 3
- Is it possible to augment the `values` of an enum? HOT 6
- How can we augment an abstract variable? HOT 18
- Enforce strict method override behavior in Dart HOT 4
- Allow `augmented` as the name of a named argument or as a member name? HOT 3
- Allow `with` as function name HOT 4
- Allow use switch expression to init a const variable HOT 2
- Parameter name of implicit setter. HOT 7
- Add `yield` to collection for HOT 3
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 language.