Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Use pointcut syntax for querying classes in source code

The pointcut parser (and matcher) is usable as a standalone entity.
Spring Framework actually uses this.

Here is an example testcase from AspectJ:

		PointcutParser p =
PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingSpecifiedClassloaderForResolution(this.getClass().getClassLoader());
		PointcutExpression pexpr = null;
		ShadowMatch match = null;

		Method a = test.A.class.getMethod("a",new Class[] {String.class});
          // public void a(String s) {}
		Method b = test.A.class.getMethod("b",new Class[] {String.class});
          // public void b(@A1 String s) {}
		Method c = test.A.class.getMethod("c",new Class[] {String.class});
          // public void c(@A1 @A2 String s) {}

		pexpr = p.parsePointcutExpression("execution(public void *(@test.A1 *))");
		assertTrue("Should not match",
pexpr.matchesMethodExecution(a).neverMatches());
		assertTrue("Should not match",
pexpr.matchesMethodExecution(b).neverMatches());
		assertTrue("Should not match",
pexpr.matchesMethodExecution(c).neverMatches());
		
		pexpr = p.parsePointcutExpression("execution(public void *(@test.A1 (*)))");
		assertTrue("Should not match",
pexpr.matchesMethodExecution(a).neverMatches());
		assertTrue("Should match", pexpr.matchesMethodExecution(b).alwaysMatches());
		assertTrue("Should match", pexpr.matchesMethodExecution(c).alwaysMatches());


In this case the entities against which pointcuts are being matched
are actually reflection based.

There is a more general matching scheme where pointcuts can be matched
against shadows conjured up from anything (eg. sourcecode).  But there
is no general builder to construct shadows from Java source right now
(which would enable matching as you type in AJDT), so you have to
construct them yourself.  Examples of this are in
CommonPointcutExpressionTests.

Andy

On 25 February 2010 00:09, Thomas Blaulicht <blaulicht75@xxxxxx> wrote:
> Hi,
>
> is there an API in the AspectJ or AJDT plug-in with which it is possible to query a java source code using the pointcut syntax? Can I find the names of classes and packages in the source code of an eclipse java project which match a given pointcut string?
> In the AJDT there are several features which seem to investigate the source code rather the compiled byte code.
>
> Thanks...
> --
> GMX DSL: Internet, Telefon und Entertainment für nur 19,99 EUR/mtl.!
> http://portal.gmx.net/de/go/dsl02
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top