3

I'm making my first steps in Android development and to understand things like the lifecycle of a Fragment I'm using methods which have calls to a logger as the first line, such as

@Override
public void onCreate(Bundle savedInstanceState) {
    logger.debug("> onCreate(" + savedInstanceState + ")");
    ...
}

That works fine, except adding those messages to each method is rather cumbersome and it makes the code a bit hard to read. I found out that with AspectJ and other tools such as jcabi-aspects one could use something like this instead:

@Loggable(Loggable.DEBUG)
public String load(URL url) {
    return url.openConnection().getContent();
}

which would print:

[DEBUG] #load('http://www.google.com'): returned "<html ..." in 23ms

That sounds pretty cool, but how do I go about adding this functionality to Android Studio? I could find a guide for Eclipse and this IntelliJ help page (but not the mentioned plugins), and I'm at loss. I'd welcome a mini-guide on how to get started with AspectJ (and perhaps jcabi-aspects).

yegor256
  • 102,010
  • 123
  • 446
  • 597
squirrel
  • 5,114
  • 4
  • 31
  • 43

1 Answers1

1

The plug-ins mentioned on the IntelliJ help page can be found easily on my IDEA 13 installation: AspectJ plug-ins in IntelliJ IDEA

As for Eclipse, the AspectJ support is much more mature than for IDEA because AspectJ itself is an Eclipse project. As much as I prefer IDEA for 95% of all my development use cases, when it comes to AspectJ support I use Eclipse. There you need to install the AspectJ Development Tools (AJDT).

The best idea is to set up a Maven project for your Java + AspectJ endeavour, so you can build via command line or easily import the Maven project into both IDEA and Eclipse. You want to use the AspectJ Maven Plugin for that purpose.

Learning AspectJ itself is possible via resources on the official AspectJ documentation. There you find "getting started", "programming guide", "quick reference", "idioms", "pitfalls", "examples" and other sections.

Good luck!

P.S.: You could just have used your favourite web search engine to find what I just told you.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • These plugins, however, are missing from Android Studio. So I'm sort of stuck. – squirrel Aug 03 '14 at 16:58
  • Use Eclipse then or buy IDEA Ultimate. – kriegaex Aug 03 '14 at 17:05
  • To the person who downvoted my answer: Why did you do that? Downvotes are reserved for sloppily written, meaningless answers showing no sign of research or effort to answer comprehensively. – kriegaex Feb 28 '15 at 14:49