It is a bit more advanced than simple pattern matching, but it is reusable
with certain constraints. The matching is separate to the weaving, captured
in the org.aspectj.matcher.jar that we ship. It does rely on a 'world'
(based on a class path) in order to resolve type references because we
support patterns that need to know about type relationships.  Here is an
example test case we have (from
https://github.com/eclipse/org.aspectj/blob/93c58e39cf0512d0920c37a40026a6aa5f1ff26b/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonPointcutExpressionTests.java
):

public void testMethodExecutionMatching02() {

checkAlwaysMatches("execution(* *val*(..))", "java.lang.String", "valueOf",
"(Z)Ljava/lang/String;");

checkAlwaysMatches("execution(String *(..))", "java.lang.String",
"valueOf", "(Z)Ljava/lang/String;");

checkAlwaysMatches("execution(* *(boolean))", "java.lang.String",
"valueOf", "(Z)Ljava/lang/String;");

checkAlwaysMatches("execution(* j*..*.valueOf(..))", "java.lang.String",
"valueOf", "(Z)Ljava/lang/String;");

checkAlwaysMatches("execution(* *(*))", "java.lang.String", "valueOf",
"(Z)Ljava/lang/String;");


 checkNeverMatches("execution(* vulueOf(..))", "java.lang.String",
"valueOf", "(Z)Ljava/lang/String;");

checkNeverMatches("execution(int *(..))", "java.lang.String", "valueOf",
"(Z)Ljava/lang/String;");

checkNeverMatches("execution(* valueOf(String))", "java.lang.String",
"valueOf", "(Z)Ljava/lang/String;");

checkNeverMatches("execution(private * valueOf(..))", "java.lang.String",
"valueOf", "(Z)Ljava/lang/String;");

}


The method 'checkAlwaysMatches' constructs a pointcut expression from the
first string:


StandardPointcutExpression ex =
pointcutParser.parsePointcutExpression(pointcutExpression);


Then uses the world to retrieve the specified member (e.g. "String
valueOf(boolean)" from the String class, in the case of the first test
entry there:


ResolvedType resolvedType = world.resolve(type);

ResolvedMember method = getMethod(resolvedType, methodName,
methodSignature);


Then compares the two:


boolean b = ex.matchesMethodExecution(method).alwaysMatches();


Using it without a world of types, I'm not sure about that.


cheers,

Andy




On 7 October 2014 13:22, Henrique Rebêlo <h...@cin.ufpe.br> wrote:

> Hi Andy and all,
>
> I was wondering if there is a way to reuse/use explicitly the ajc code
> responsible for pattern matching. That is, given a method signature pattern
> (using wildcarding etc) in some format (like String etc) and a method
> signature (also in some format), I want to know if that method signature
> pattern matches such method signature.
>
> For example:
>
> Given a signature pattern like "void C.set(..)" and a method signature
> like "void C.set(int, int)" I want to return "true" for this query.
>
> Does AspectJ use Regular expressions or something like to perform such
> pattern matching? I just want to reuse such feature...
>
> All the best,
> Henrique
>
>
>
> --
>
> ...............................................................................................................................
> Henrique Rebelo
> http://www.cin.ufpe.br/~hemr
> Informatics Center, UFPE, Brazil
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to