View | Details | Raw Unified | Return to bug 193065 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/aspectj/weaver/CustomMungerFactory.java (-3 / +40 lines)
Lines 14-21 Link Here
14
14
15
import java.util.Collection;
15
import java.util.Collection;
16
16
17
/**
18
 * <p>
19
 * This interface is introduced to support tools like PointcutDoctor.
20
 * </p>
21
 * <p>
22
 * A CustomMungerFactory is used to create ShadowMungers and/or
23
 * ConcreteTypeMungers so that an extender can extract extra information during
24
 * the weaving process.
25
 * </p>
26
 * <p>
27
 * A CustomMungerFactory is assigned to a weaver through its AjCompiler in
28
 * extenders' code, and gets invoked by the weaver right before the weaving
29
 * starts. The custom shadow/type mungers being created will be added into the
30
 * shadow/type munger list in the weaver and participate the weaving process.
31
 * For example, the match method of each custom shadow munger will be called
32
 * against each shadow.
33
 * </p>
34
 * @author lintonye
35
 * 
36
 */
17
public interface CustomMungerFactory {
37
public interface CustomMungerFactory {
18
	public Collection/*ShadowMunger*/ createCustomShadowMungers(ResolvedType aspectType);
38
19
	public Collection/*ConcreteTypeMunger*/ createCustomTypeMungers(ResolvedType aspectType);
39
	/**
20
//	public Collection<Declare> createCustomDeclares(ResolvedType aspectType);
40
	 * @param aspectType
41
	 * @return a Collection&lt;ShadowMunger&gt; of custom shadow mungers for the
42
	 *         given aspect
43
	 */
44
	public Collection/* ShadowMunger */createCustomShadowMungers(
45
			ResolvedType aspectType);
46
47
	/**
48
	 * @param aspectType
49
	 * @return a Collection&lt;ConcreteTypeMunger&gt; of custom type mungers for the
50
	 *         given aspect
51
	 */
52
	public Collection/* ConcreteTypeMunger */createCustomTypeMungers(
53
			ResolvedType aspectType);
54
	
55
	public Collection/* ShadowMunger */getAllCreatedCustomShadowMungers();
56
57
	public Collection/* ConcreteTypeMunger */getAllCreatedCustomTypeMungers();
21
}
58
}
(-)bugs/pointcutdoctor-bug193065/Foo.java (+9 lines)
Added Link Here
1
public class Foo {
2
	public void method1() {
3
		
4
	}
5
	
6
	public void method2() {
7
		
8
	}
9
}
(-)bugs/pointcutdoctor-bug193065/Bar.java (+6 lines)
Added Link Here
1
public class Bar {
2
	public void bar() {
3
		Foo f = new Foo();
4
		f.method1();
5
	}
6
}
(-)bugs/pointcutdoctor-bug193065/Aspect.aj (+18 lines)
Added Link Here
1
2
public aspect Aspect {
3
	//:method-call(void Foo.method1())=real
4
	//:(virtual) method-call(void Foo.method2())=virtual
5
	pointcut calls(): call(* Foo.*(..));
6
	
7
	//:(virtual) method-call(void Bar.bar())=virtual
8
	pointcut callBar():call(* Bar.*(..));
9
	
10
	//:method-call(void Foo.method1())=real
11
	//:(virtual) method-call(void Foo.method2())=virtual
12
	pointcut callsWithin(): call(* Foo.*(..)) && within(Bar);
13
14
	//:method-call(void Foo.method1())=real
15
	//:(virtual) method-call(void Foo.method2())=virtual
16
	pointcut callsWithincode(): call(* Foo.*(..))&&withincode(* Bar.*(..));
17
18
}
(-)src/org/aspectj/systemtest/ajc154/CustomMungerExtensionTest.java (+127 lines)
Added Link Here
1
/* *******************************************************************
2
 * Copyright (c) 2007 Contributors
3
 * All rights reserved. 
4
 * This program and the accompanying materials are made available 
5
 * under the terms of the Eclipse Public License v1.0 
6
 * which accompanies this distribution and is available at 
7
 * http://www.eclipse.org/legal/epl-v10.html 
8
 *  
9
 * Contributors: 
10
 *     Linton Ye https://bugs.eclipse.org/bugs/show_bug.cgi?id=193065
11
 * ******************************************************************/
12
13
package org.aspectj.systemtest.ajc154;
14
15
import java.io.File;
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Map;
21
22
import org.aspectj.ajde.core.AjCompiler;
23
import org.aspectj.bridge.ISourceLocation;
24
import org.aspectj.systemtest.incremental.tools.AjdeInteractionTestbed;
25
import org.aspectj.weaver.Advice;
26
import org.aspectj.weaver.Checker;
27
import org.aspectj.weaver.ConcreteTypeMunger;
28
import org.aspectj.weaver.CustomMungerFactory;
29
import org.aspectj.weaver.Member;
30
import org.aspectj.weaver.ResolvedType;
31
import org.aspectj.weaver.ResolvedTypeMunger;
32
import org.aspectj.weaver.Shadow;
33
import org.aspectj.weaver.ShadowMunger;
34
import org.aspectj.weaver.World;
35
import org.aspectj.weaver.AjAttribute.AdviceAttribute;
36
import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
37
import org.aspectj.weaver.patterns.IfPointcut;
38
import org.aspectj.weaver.patterns.Pointcut;
39
40
public class CustomMungerExtensionTest extends AjdeInteractionTestbed {
41
	
42
	@Override
43
	protected void setUp() throws Exception {
44
		super.setUp();
45
		sandboxDir = new File(".");
46
	}
47
	
48
	public void testExtension() {
49
		String testFileDir = "bugs/pointcutdoctor-bug193065";
50
		AjCompiler compiler = getCompilerForProjectWithName(testFileDir);
51
		compiler.setCustomMungerFactory(new DumbCustomMungerFactory());
52
53
		doBuild(testFileDir);
54
		
55
		CustomMungerFactory factory = (CustomMungerFactory)compiler.getCustomMungerFactory();
56
		assertTrue(factory.getAllCreatedCustomShadowMungers().size()>0);
57
		for (Iterator i = factory.getAllCreatedCustomShadowMungers().iterator(); i.hasNext();)
58
			assertTrue(((DumbShadowMunger)i.next()).called);
59
		
60
		assertTrue(factory.getAllCreatedCustomTypeMungers().size()>0);
61
		for (Iterator i = factory.getAllCreatedCustomTypeMungers().iterator(); i.hasNext();)
62
			assertTrue(((DumbTypeMunger)i.next()).called);
63
	}
64
	
65
	class DumbCustomMungerFactory implements CustomMungerFactory {
66
		Collection allShadowMungers = new ArrayList();
67
		Collection allTypeMungers = new ArrayList();
68
		public Collection createCustomShadowMungers(ResolvedType aspectType) {
69
			List/* ShadowMunger */ mungers = new ArrayList/*ShadowMunger*/(); 
70
			Pointcut pointcut = new IfPointcut("abc");
71
			mungers.add(new DumbShadowMunger(new DeclareErrorOrWarning(false, pointcut, "")));
72
			allShadowMungers.addAll(mungers);
73
			return mungers;
74
		}
75
76
		public Collection createCustomTypeMungers(ResolvedType aspectType) {
77
			List/*ConcreteTypeMunger*/ mungers = new ArrayList/*ShadowMunger*/(); 
78
			mungers.add(new DumbTypeMunger(null, aspectType));
79
			allTypeMungers.addAll(mungers);
80
			return mungers;
81
		}
82
83
		public Collection getAllCreatedCustomShadowMungers() {
84
			return allShadowMungers;
85
		}
86
87
		public Collection getAllCreatedCustomTypeMungers() {
88
			return allTypeMungers;
89
		}
90
	}
91
92
	class DumbShadowMunger extends Checker {
93
		public DumbShadowMunger(DeclareErrorOrWarning deow) {
94
			super(deow);
95
		}
96
		@Override
97
		public ISourceLocation getSourceLocation() {
98
			return ISourceLocation.EMPTY;
99
		}
100
101
		boolean called;
102
		@Override
103
		public boolean match(Shadow shadow, World world) {
104
			called = true;
105
			return false;
106
		}
107
	}
108
109
	class DumbTypeMunger extends ConcreteTypeMunger {
110
		boolean called;
111
112
		public DumbTypeMunger(ResolvedTypeMunger munger, ResolvedType aspectType) {
113
			super(munger, aspectType);
114
		}
115
116
		@Override
117
		public ConcreteTypeMunger parameterizedFor(ResolvedType targetType) {
118
			return null;
119
		}
120
		
121
		@Override
122
		public boolean matches(ResolvedType onType) {
123
			called = true;
124
			return false;
125
		}
126
	}
127
}
(-)src/org/aspectj/ajde/core/AjCompiler.java (-3 / +17 lines)
Lines 59-68 Link Here
59
		buildManager = new AjdeCoreBuildManager(this);
59
		buildManager = new AjdeCoreBuildManager(this);
60
	}
60
	}
61
	
61
	
62
	public void setCustomMungerFactory(Class factoryClass) {
62
	/**
63
		buildManager.setCustomMungerFactory(factoryClass);
63
	 * Set a CustomMungerFactory to the compiler's weaver
64
	 * 
65
	 * The type of factory should be org.aspectj.weaver.CustomMungerFactory but
66
	 * due to dependency problem of project ajde.core, it is Object for now.
67
	 * 
68
	 * @param factory
69
	 */
70
	public void setCustomMungerFactory(Object factory) {
71
		buildManager.setCustomMungerFactory(factory);
64
	}
72
	}
65
	
73
74
	/**
75
	 * @return the CustomMungerFactory from the compiler's weaver
76
	 * 
77
	 * The return type should be org.aspectj.weaver.CustomMungerFactory but
78
	 * due to dependency problem of project ajde.core, it is Object for now.
79
	 */
66
	public Object getCustomMungerFactory() {
80
	public Object getCustomMungerFactory() {
67
		return buildManager.getCustomMungerFactory();
81
		return buildManager.getCustomMungerFactory();
68
	}
82
	}

Return to bug 193065