Added
Link Here
|
1 |
package org.aspectj.weaver; |
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Collection; |
5 |
import java.util.List; |
6 |
|
7 |
import org.aspectj.weaver.AjAttribute.TypeMunger; |
8 |
import org.aspectj.weaver.patterns.Declare; |
9 |
|
10 |
public privileged aspect CustomMungerExtension { |
11 |
|
12 |
private List<CustomMungerFactory> customMungerFactories = new ArrayList<CustomMungerFactory>(); |
13 |
private boolean enabled = false; |
14 |
|
15 |
pointcut addOrReplaceAspect(ResolvedType aspectType, boolean inWeavingPhase): |
16 |
execution(* CrosscuttingMembersSet.addOrReplaceAspect(..)) && args(aspectType, inWeavingPhase); |
17 |
|
18 |
after(ResolvedType aspectType, boolean inWeavingPhase, |
19 |
CrosscuttingMembersSet xSet): |
20 |
addOrReplaceAspect(aspectType, inWeavingPhase) && this(xSet) { |
21 |
if (inWeavingPhase && isEnabled()) { |
22 |
CrosscuttingMembers xcut = (CrosscuttingMembers) xSet.members |
23 |
.get(aspectType); |
24 |
for (CustomMungerFactory factory : customMungerFactories) { |
25 |
Collection<TypeMunger> customTypeMungers = factory.createCustomTypeMungers(aspectType); |
26 |
if (customTypeMungers != null) |
27 |
xcut.addTypeMungers(customTypeMungers); |
28 |
Collection<ShadowMunger> customShadowMungers = factory.createCustomShadowMungers(aspectType); |
29 |
if (customShadowMungers != null) |
30 |
xcut.addShadowMungers(customShadowMungers); |
31 |
Collection<Declare> customDeclare = factory.createCustomDeclares(aspectType); |
32 |
if (customDeclare != null) |
33 |
xcut.addDeclares(customDeclare); |
34 |
} |
35 |
} |
36 |
} |
37 |
|
38 |
public boolean isEnabled() { |
39 |
return enabled; |
40 |
} |
41 |
|
42 |
public void setEnabled(boolean enabled) { |
43 |
this.enabled = enabled; |
44 |
} |
45 |
|
46 |
public void addCustomMungerFactory(CustomMungerFactory factory) { |
47 |
customMungerFactories.add(factory); |
48 |
} |
49 |
} |