List of usage examples for org.aspectj.weaver.patterns SignaturePattern getParameterTypes
public TypePatternList getParameterTypes()
From source file:org.caesarj.compiler.aspectj.CaesarWrapperPatternParser.java
License:Open Source License
private CaesarPointcutWrapper parseKindedPointcut() { String kind = parseIdentifier(); eat("(");// ww w.j a v a2s . c o m SignaturePattern sig; Shadow.Kind shadowKind = null; if (kind.equals("execution")) { sig = parseMethodOrConstructorSignaturePattern(); if (sig.getKind() == Member.METHOD) { shadowKind = Shadow.MethodExecution; } else if (sig.getKind() == Member.CONSTRUCTOR) { shadowKind = Shadow.ConstructorExecution; } } else if (kind.equals("call")) { sig = parseMethodOrConstructorSignaturePattern(); if (sig.getKind() == Member.METHOD) { shadowKind = Shadow.MethodCall; } else if (sig.getKind() == Member.CONSTRUCTOR) { shadowKind = Shadow.ConstructorCall; } } else if (kind.equals("get")) { sig = parseFieldSignaturePattern(); shadowKind = Shadow.FieldGet; } else if (kind.equals("set")) { sig = parseFieldSignaturePattern(); shadowKind = Shadow.FieldSet; } else { throw new ParserException("bad kind: " + kind, tokenSource.peek()); } eat(")"); // Creates the wrapper if (Shadow.MethodCall.equals(shadowKind) || Shadow.MethodExecution.equals(shadowKind)) { // Method call and execution are wrapped in an "and pointcut" to avoid getting constructors CaesarKindedPointcut p = new CaesarKindedPointcut(shadowKind, sig); registerPointcut(new CaesarPointcutWrapper(p)); Pointcut andPointcut = new AndPointcut(p, new NotPointcut(new CaesarKindedPointcut(shadowKind, this.createConstructorSignature()), tokenSource.peek().getStart())); return new CaesarPointcutWrapper(andPointcut); } else if (Shadow.ConstructorCall.equals(shadowKind) || Shadow.ConstructorExecution.equals(shadowKind)) { Shadow.Kind cclassShadowKind = null; // Transform the constructor call/execution to a method call/execution, // using $constructor and the same parameters if (Shadow.ConstructorCall.equals(shadowKind)) { cclassShadowKind = Shadow.MethodCall; } else { cclassShadowKind = Shadow.MethodExecution; } CaesarCloner c = CaesarCloner.instance(); SignaturePattern cclassSig = new SignaturePattern(Member.METHOD, sig.getModifiers(), createCaesarObjectPattern(), c.clone(sig.getDeclaringType()), new NamePattern("$constructor"), c.clone(sig.getParameterTypes()), c.clone(sig.getThrowsPattern())); CaesarKindedPointcut regular = new CaesarKindedPointcut(shadowKind, sig); CaesarKindedPointcut cclass = new CaesarKindedPointcut(cclassShadowKind, cclassSig); registerPointcut(new CaesarPointcutWrapper(regular)); registerPointcut(new CaesarPointcutWrapper(cclass)); // Creates an orPointcut for both the regular java and cclass constructors Pointcut orPointcut = new OrPointcut(regular, cclass); return new CaesarPointcutWrapper(orPointcut); } if (Shadow.FieldGet.equals(shadowKind) || Shadow.FieldSet.equals(shadowKind)) { // Creates the wrapper and register it CaesarKindedPointcut p = new CaesarKindedPointcut(shadowKind, sig); CaesarPointcutWrapper wrapper = new CaesarPointcutWrapper(p); registerPointcut(wrapper); // Append something like || get(public * Classname_Impl_Mixin_*.field) TypePattern mixinType = createMixinType(sig.getDeclaringType()); SignaturePattern mixinSignature = createMixinSignature(sig, mixinType); CaesarKindedPointcut mixin = new CaesarKindedPointcut(shadowKind, mixinSignature); // Register the mixin wrapper = new CaesarPointcutWrapper(mixin, sig.getDeclaringType()); 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); } CaesarKindedPointcut p = new CaesarKindedPointcut(shadowKind, sig); return new CaesarPointcutWrapper(p); }
From source file:org.caesarj.compiler.aspectj.CaesarWrapperPatternParser.java
License:Open Source License
/** * Parses a Withincode Pointcut// w ww . j a v a 2s . c o m * * @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); }
From source file:org.caesarj.compiler.aspectj.CaesarWrapperPatternParser.java
License:Open Source License
/** * Creates a signature pattern which is a clone of this signature but has the mixinType * as declaringType/*w w w .j a va2 s.c o m*/ * * @param sig * @param mixinType * @return */ protected SignaturePattern createMixinSignature(SignaturePattern sig, TypePattern mixinType) { CaesarCloner c = CaesarCloner.instance(); return new SignaturePattern(sig.getKind(), sig.getModifiers(), c.clone(sig.getReturnType()), mixinType, c.clone(sig.getName()), c.clone(sig.getParameterTypes()), c.clone(sig.getThrowsPattern())); }