DSLD: Pointcut problems

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DSLD: Pointcut problems

Peter Niederwieser
Administrator
This pointcut matches:

contribute(enclosingClass(subType("spock.lang.Specification")) &
        enclosingCall(name("Mock")) & enclosingClosure()) { ... }

But these don't:

contribute(enclosingClass(subType("spock.lang.Specification")) &
        enclosingCall(name("Mock") & declaringType("spock.lang.MockingApi")) & enclosingClosure()) { ... }

contribute(enclosingClass(subType("spock.lang.Specification")) &
        enclosingCall(name("Mock") & hasArgument(type(Class))) & enclosingClosure()) { ... }

Is there anything obviously wrong with these pointcuts? I can't spot a difference from the examples given in the documentation. I'm trying to match an invocation of the following method (overload):

package spock.lang;

public class MockingApi extends SpecInternals {
  public <T> T Mock(Class<T> type, Closure closure) { ... }
}

Invocation looks like so:

class MySpec extends Specification {
  def foo() {
    def list = Mock(List) { ... }
  }
}

Could it be that the AST transform gets in the way? It rewrites the Mock() call to MockImpl() (declared in SpecInternals) and adds some arguments. But then the first pointcut is working, and matching "MockImpl" doesn't change things either.

Cheers,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: DSLD: Pointcut problems

Peter Niederwieser
Administrator
I should add that this is what I'm really after:

contribute(enclosingClass(subType("spock.lang.Specification")) &
    enclosingCall(name("Mock") & declaringType("spock.lang.MockingApi") &
    hasArgument(delegateType: type(Class))) & enclosingClosure()) {
  delegatesTo(delegateType)
}

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: DSLD: Pointcut problems

Andrew Eisenberg
In reply to this post by Peter Niederwieser
I'll have to try this out tomorrow.  I don't think it would be the AST
transform getting in the way since they are usually disabled during
reconciling.

On Thu, Jul 5, 2012 at 8:41 PM, Peter Niederwieser <[hidden email]> wrote:

> This pointcut matches:
>
> contribute(enclosingClass(subType("spock.lang.Specification")) &
>         enclosingCall(name("Mock")) & enclosingClosure()) { ... }
>
> But these don't:
>
> contribute(enclosingClass(subType("spock.lang.Specification")) &
>         enclosingCall(name("Mock") & declaringType("spock.lang.MockingApi")) &
> enclosingClosure()) { ... }
>
> contribute(enclosingClass(subType("spock.lang.Specification")) &
>         enclosingCall(name("Mock") & hasArgument(type(Class))) &
> enclosingClosure()) { ... }
>
> Is there anything obviously wrong with these pointcuts? I can't spot a
> difference from the examples given in the documentation. I'm trying to match
> an invocation of the following method (overload):
>
> package spock.lang;
>
> public class MockingApi extends SpecInternals {
>   public <T> T Mock(Class<T> type, Closure closure) { ... }
> }
>
> Invocation looks like so:
>
> class MySpec extends Specification {
>   def foo() {
>     def list = Mock(List) { ... }
>   }
> }
>
> Could it be that the AST transform gets in the way? It rewrites the Mock()
> call to MockImpl() (declared in SpecInternals) and adds some arguments. But
> then the first pointcut is working, and matching "MockImpl" doesn't change
> things either.
>
> Cheers,
> Peter
>
>
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/DSLD-Pointcut-problems-tp4025003.html
> Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email