Looking for aspect oriented framework for java (Android) which allows to modify sources [closed]

StackOverflow https://stackoverflow.com/questions/14276381

  •  14-01-2022
  •  | 
  •  

Frage

I was trying to find aspect oriented framework which modify .java source files rather then .class itself with no luck so far? I know it could be a silly idea... but what I want is to understand what exact code was pasted to .class.

Basically Im trying to apply logging and other aspects for huge android project. I was playing with AspectJ but one of the issue is that we already reach method declaration limit and I cant just add AspectJ to be packed into .apk. However without AspectJ library I get no class def exception ( Caused by: java.lang.NoClassDefFoundError: org.aspectj.runtime.reflect.Factory)

War es hilfreich?

Lösung

You are unlikely to find an aspectJ-equivalent that operates on source code.

What you appear to want is a source-to-source program transformation tool that can replicate aspect insertion (or at enough to do logging).

As a practical matter, the transformation system needs to understand how Java entities are named in order to carry out the transformation on the named Java entities.

You would have to write the transformations that apply the aspects; since some AspectJ aspects do rather sophisticated things involving control flow, you might find some of the transformations difficult to write. Logging is relatively easy.

You would run the transformation tool to apply the aspects to your source code base, generating an aspectized source code base. That resulting code base would be compiled and delivered into the Android context. Nothing of the transformation system itself would be include as excess baggage. You might find it necessary as part of inserting the aspects, to insert calls on additional libraries (as AspectJ seemed to find need for a support library "runtime.reflect.Factory") but at least you'd know what the code was; you'd have inspectable source code. In fact, you'd know because such calls would be visible directly in the transformation rules themselves.

Of the transformation tools that I know about, only our DMS Software Reengineering Toolkit understands Java down to the level of naming, and handles control flow. DMS can apply aspects encoded in the form of explicit transformation rules.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top