Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Parameters

(Sorry, replying to self)

Wes Isberg wrote:

...
[using getArgs()] won't pick out a null ClassX arg, and it
can be expensive, depending on the rest of your pointcut.

A hack to pick up any declaration (regardless of whether the
value was null) would inspect the signature for an appropriate
argument.  (Even more expensive.)

    static boolean hasArg(Class cl, String sig) {
         int loc = sig.indexOf("(");
         if (-1 == loc) { return false; }
         loc = sig.indexOf(cl.getName(), loc);
         if (-1 == loc) { return false; }
         int after = 1 + loc + cl.getName().length();
         if (after < sig.length()) {
            char c = sig.charAt(after);
            return ((',' == after) || (')' == after));
         }
         return false;
    }
   ... if(hasArg(
           thisJoinPoint.StaticPart.getSignature().toLongString()))

Wes


Wes


DiFrango, Ron wrote:

All,

I could not find an answer to this in any of the old postings.  I have
methods that take a common parameter. The problem is that depending on the method call this parameter may be listed anywhere in the method signature.
So for example:

    public class ParametersInMethodCalls
    {
        public void example1(ClassX x, double I, String s)
        {
        }

        public void example2(int I, ClassX x, double d)
        {
        }

        public void example2(float I, String s, ClassX x)
        {
        }
    }

My question is can I define a pointcuts that picks out all the above
combinations without having to "code if you will" the different permutations
possible?  I have tried the following examples/permutations:

pointcut examples(ClassX x) : execution(public * ParametersInMethodCalls.*(..))
        && args(.., x);

    ==> Afected example2

pointcut examples(ClassX x) : execution(public * ParametersInMethodCalls.*(..))
        && args(x, ..);

    ==> Afected example1

pointcut examples(ClassX x) : execution(public * ParametersInMethodCalls.*(..))
        && args(*, x);

    ==> Affect nothing

The important thing to note is that all the methods I want to pick out have
the common input of ClassX, but there is an indeterminate number of other
parameters to these methods. Furthermore, I would prefer to avoid having to
change the underlying code as it affects a large body of code.

Thanks in advance,

Ron DiFrango
************************************************************************** The information transmitted herewith is sensitive information intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top