[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Dynamically defining fields
|
I have a software project where we are attempting to allieviate some
of the responsibility from the end-user by automatically defining some
static, final fields in their code, based on other declarations made in
their software. These declarations are in the form of user-defined
methods that follow a particular pattern. For each method that matches
that pattern, we would like to define a field in their class to
correspond with that method name.
The effect that we are looking for could be provided with C-like
pre-processors, however, we are already utilizing aspects for other
areas of the project. Thus, rather than adding a new tool, we would
prefer to re-utilize an existing one, in this case, AJC.
There are two problems as I see it:
1) For this particular problem, we are interested in method
declarations, versus method invocations
2) We do not need to modify the code in the method declaration, but we
want to add code in the class (in this case, primitive class variables),
and what we want to add is not know apriori.
I would love to be able to write something such as the following:
pointcut actionMethod(MyBaseClass mbc) : declare (void
MyBaseClass+.action*(..)) && target(mbc) {
// Get the name of the method
String name = thisJoinPoint.getSignature().getName();
// Strip off the "action" designator
name = name.substring(5);
// Declare a variable in this class with the name of the method
thisJoinPoint.addTypeDeclaration("public static final int _"+name+" =
5;");
}
My (basic) understanding of Aspects at this point says that this isn't
possible. Does anyone have thoughts on how a similar capability might
be accomplished, either with the current AJC, or with modifications to AJC?
Thanks in advance!
--
Keven Ring | "Oh no, Not Again..."
The MITRE Corporation | Bowl of Petunias -
7515 Colshire Drive | The Hitchhikers Guide to the Galaxy
McLean VA 22102-7508 |
PH: (703)883-7026 |