Project: Eclipse_Platform_UI
Bug 294777 [context] Clarify default state of @Optional
Reported: 2009-11-10 13:42:48 | Status: resolved fixed

The "@Optional" annotation now is mixed up about its default state. The Javadoc says that its default state is "true", while some code paths think it is "false". What we need to consider: - in *all* cases in demos we have so far we use "@Optional(true)" - the original intent was (AFAIK): constructors: default is @Optional(false) method arguments: default is @Optional(false) methods on #make: default should be @Optional(true) ? I'd like to propose the following scheme based on the patters we see in demos: - arguments (of either method or constructor) are required by default - calling injectable methods [and setting fields] is optional by default This would mean that any explicit calls (#invoke(), #make()) must have their arguments available in the context to succeed. However, any calls generated by DI behind the scene (as a result of #inject()) are optional. On, in other terms, we don't have to call injectable methods unless specifically instructed. However, if we do call a method, we expect its arguments to be in the context. (This, of course, is the deafult state and can be change by using @Optional annotation.) The upside of this approach is that it fits well into patterns we see in the E4 demos (= DI "just works"). The downside is that, as evident from this text, it is not that easy to explain exactly what are the default states. From simplicicty of the programming model, it would be much better to just say that the default is always true or always false. Any opinions on this proposal?

Files changed in fix:
examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/DetailsView.java examples/org.eclipse.e4.demo.e4photo/src/org/eclipse/e4/demo/e4photo/ExifTable.java