It's not that hard to write some ASM code to detect that simple kind of usage, but more complex usage would be difficult to impossible. For example:

 @PostConstruct
 public void startup() {
     initBlue();
 }

 private void initBlue() {
     blue.doSomeWork();
 }

Now imagine how complex you can make that code and you quickly come to the conclusion that it is almost impossible to detect reliably. Of course if you are only interested somewhat accurate results, you could use a simple detect algorithm, but you will miss some usages and get some false positives (for example if (false) blue.doSomeWork()).

-dain

On Aug 7, 2008, at 12:57 PM, David Blevins wrote:

Along those lines what would be really cool is if the tool could add the @DependsOn automatically for a user.

A singleton needs a @DependsOn declaration only when referring to (invoking) another singleton in either its @PostConstruct or @PreDestroy method. I don't know if it's possible, but if there was some way spot that and add the @DependsOn for them, that'd be really cool.

As an example, the bean has this:

@Singleton
@Startup
public class RedBean {

 @EJB(beanName="BlueBean")
 private BlueLocal blue

 @PostConstruct
 public void startup() {

 }
}

and all is fine, but when they add this to the @PostConstruct method...

 @PostConstruct
 public void startup() {
     blue.doSomeWork();
 }

At that point you need to add the @DependsOn like so:

@Singleton
@Startup
@DependsOn("BlueBean")
public class RedBean {
  ...
}

Don't know if that's possible, but would be cool.

-David


Reply via email to