Example usage for org.aspectj.weaver.patterns WithincodePointcut WithincodePointcut

List of usage examples for org.aspectj.weaver.patterns WithincodePointcut WithincodePointcut

Introduction

In this page you can find the example usage for org.aspectj.weaver.patterns WithincodePointcut WithincodePointcut.

Prototype

public WithincodePointcut(SignaturePattern signature) 

Source Link

Usage

From source file:org.caesarj.compiler.aspectj.CaesarWrapperPatternParser.java

License:Open Source License

/**
 * Parses a Withincode Pointcut/*from   w  w w . jav a  2  s . c  om*/
 * 
 * @return
 */
private CaesarPointcutWrapper parseWithinCodePointcut() {

    // Parses the signature pattern
    parseIdentifier();
    eat("(");
    SignaturePattern sig = parseMethodOrConstructorSignaturePattern();
    eat(")");

    // Gets the declaring type
    TypePattern type = sig.getDeclaringType();

    // Creates the wrapper and register it
    Pointcut p = new WithincodePointcut(sig);
    CaesarPointcutWrapper wrapper = new CaesarPointcutWrapper(p);
    wrapper.setDeclaringType(type);
    registerPointcut(wrapper);

    if (Member.CONSTRUCTOR.equals(sig.getKind())) {

        // Transform the constructor withincode to a method withincode, 
        // using $constructor and the same parameters (for cclasses)
        CaesarCloner c = CaesarCloner.instance();

        sig = new SignaturePattern(Member.METHOD, sig.getModifiers(), createCaesarObjectPattern(),
                c.clone(type), new NamePattern("$constructor"), c.clone(sig.getParameterTypes()),
                c.clone(sig.getThrowsPattern()));

        WithincodePointcut cclass = new WithincodePointcut(sig);
        wrapper = new CaesarPointcutWrapper(cclass);
        wrapper.setDeclaringType(sig.getDeclaringType());
        registerPointcut(wrapper);

        // Creates an orPointcut for both the regular java and cclass constructors
        p = new OrPointcut(p, cclass);
    }

    // Creates something like || withincode(* Classname_Impl_Mixin_*.m())
    TypePattern mixinType = createMixinType(type);
    SignaturePattern mixinSignature = createMixinSignature(sig, mixinType);

    WithincodePointcut mixin = new WithincodePointcut(mixinSignature);

    // Register the mixin
    wrapper = new CaesarPointcutWrapper(mixin, type);
    wrapper.setDeclaringType(mixinType);
    registerPointcut(wrapper);

    // Creates an orPointcut for both the type and the mixin
    Pointcut orPointcut = new OrPointcut(p, mixin);

    return new CaesarPointcutWrapper(orPointcut);
}