What the build checks
The generator fails the build, naming the member and what to change, when an annotation is on a member it cannot follow.
Why
The bean's proxy is a generated class that extends the bean's class and overrides its members. A member it cannot override would be a field that silently tells nobody. So the mistake is a build error, not a stale screen.
Example
@Component()
class Basket {
@Signal()
final List<Book> items = []; // fails the build: a final field
@Signal()
String? _coupon; // fails the build: a private field
}
What fails the build
| Annotation | Fails on |
|---|---|
@Signal |
A private, static or final field; a getter or a method |
@Computed |
A field; a private or static member; a method with parameters or without a value |
@Effect |
A private or static method; a method with parameters, or with a value |
| Any of them | An abstract member; a member that overrides a followed one without repeating its annotation; a member the proxy cannot override (an operator, a field of a private type) |
| Any of them | A class with such members that a generated class cannot extend: final, sealed, generic, a factory constructor |
Members must be public because the proxy is generated in another library.
Where the annotations do not go
The annotations work on the members of a component class (@Component, @Service, a @Repository class with a body), of its base classes and of its mixins. Anywhere else nothing would follow them, so the build fails there too:
| Where | What to do instead |
|---|---|
A class that is no bean: a widget, a State, a data class |
Make it a component, or keep the state in one |
A @Configuration or @ConfigurationProperties class |
Keep the state in a component (one that reads the properties) |
The class a @Bean method returns |
Declare the class as a component |
A repository (DataRepository) or an HTTP client (@FeignClient): their methods are written by the generator |
Call the method in a @Computed getter of a component |
A bean the container does not proxy: an @Aspect, a post-processor |
Move the member into a component of its own |
| An enum, an extension, a top-level variable or function | Move it into a component |
abstract interface class BookRepository implements DataRepository<Book, int> {
@Computed() // fails the build
Future<List<Book>> findByGenre(String genre);
}
@Service()
class Catalog {
Catalog(this.repository);
final BookRepository repository;
@Signal()
String genre = 'fiction';
@Computed() // the place for it
Future<List<Book>> get books => repository.findByGenre(genre);
}
An abstract class and a mixin may declare followed members for the components that extend them. A member that overrides a followed one repeats its annotation.
What is not checked
Not checked by the build: a field read after an await in an asynchronous @Computed getter. It compiles, and the value is not loaded again when that field changes. Read what the value depends on before the first await (see Asynchronous state).
At the start
A bean with such members must be made by the container and proxied. One that is not advised stops the start with a message that names it: the application must be built by the generator with proxies (aop_proxies: all, the default), and the bean made by the container.