123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- /* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * PARC initial implementation
- * ******************************************************************/
-
-
- package org.aspectj.weaver.patterns;
-
- import java.io.*;
- import java.util.*;
-
- import org.aspectj.testing.util.TestUtil;
- import org.aspectj.weaver.*;
- import org.aspectj.weaver.bcel.*;
- import org.aspectj.weaver.bcel.WeaveTestCase;
-
- public class ConcretizationTestCase extends WeaveTestCase {
- {
- regenerate = false;
- }
- public ConcretizationTestCase(String name) {
- super(name);
- }
-
- String[] none = new String[0];
-
-
- public void testCflowResidual() throws IOException {
-
- BcelAdvice a = (BcelAdvice) makeConcreteTestAdviceEntryPart();
-
- TestShadow shadow = new TestShadow(Shadow.MethodCall,
- Member.methodFromString("int Aspect.i(int x)"),
- TypeX.OBJECT,
- world);
-
- ExposedState state = new ExposedState(1);
-
- a.specializeOn(shadow);
-
- //System.err.println(shadow);
- //System.err.println(a);
-
- //System.err.println(a.exposedState);
-
-
- }
-
-
-
- public Advice makeConcreteTestAdviceEntryPart() throws IOException {
- // XXX copied from below, refactor later
-
-
- // returns the advice for the entry part of cflow(foo(a))
- Pointcut in =
- createResolvedPointcut(
- "cflow(foo(a)) && (args(b) && !cflow(foo(int)))",
- new String[] { "b", "a" },
- new String[] { "float", "int" });
-
- ResolvedPointcutDefinition ref =
- new ResolvedPointcutDefinition(
- TypeX.forName("Aspect"),
- 0,
- "foo",
- new TypeX[] { ResolvedTypeX.INT },
- createResolvedPointcut(
- "args(refA)",
- new String[] { "refA" },
- new String[] { "int" }));
- BcelObjectType target = (BcelObjectType) world.resolve("Aspect");
-
- // now munge this to get the pointcut in it
-
- target.addPointcutDefinition(ref);
- CrosscuttingMembers xcut = new CrosscuttingMembers(target);
- target.crosscuttingMembers = xcut;
-
- Advice adviceMember =
- new BcelAdvice(
- AdviceKind.Before,
- in,
- Member.method(TypeX.forName("FOO"), 0, "garadf", "(FI)V"),
- 0,
- 0, 0, null,
- null);
- // The pointcut to concretize
-
- // this returns the actual advice, but we don't care about it now.
- in.concretize(target, 2, adviceMember);
-
- List c = (List)xcut.getCflowEntries(); //target.getExtraConcreteShadowMungers();
-
- return (Advice) c.get(0);
- }
-
- public void XtestCflow() throws IOException {
- Pointcut in = createResolvedPointcut("cflow(foo(a)) && (args(b) && !cflow(foo(int)))",
- new String[] {"b", "a"}, new String[] {"float", "int"} );
-
- ResolvedPointcutDefinition ref =
- new ResolvedPointcutDefinition(TypeX.forName("Aspect"),
- 0, "foo", new TypeX[] { ResolvedTypeX.INT },
- createResolvedPointcut("args(refA)",
- new String[] {"refA"}, new String[] {"int"}));
-
- List expectedSlots = new ArrayList();
- expectedSlots.add(new ConcreteCflowPointcut.Slot(1, ResolvedTypeX.INT, 0));
-
- checkConcr(in, ref, expectedSlots);
- }
-
- public void checkConcr(
- Pointcut in,
- ResolvedPointcutDefinition referredTo,
- List expectedSlots) throws IOException {
-
- BcelObjectType target = (BcelObjectType)world.resolve("Aspect");
-
- // now munge this to get the pointcut in it
-
- target.addPointcutDefinition(referredTo);
-
-
- Advice adviceMember = new BcelAdvice(AdviceKind.Before, in,
- Member.method(TypeX.forName("FOO"), 0, "garadf", "(FI)V"), 0, 0, 0, null, null);
-
- // The pointcut to concretize
- AndPointcut ap = (AndPointcut)in.concretize(target, 2, adviceMember);
-
-
- ConcreteCflowPointcut conc = (ConcreteCflowPointcut)ap.left;
-
- List slots = conc.slots;
- TestUtil.assertSetEquals(expectedSlots, slots);
-
- }
-
-
- public Pointcut createResolvedPointcut(
- String pointcutSource, String[] formalNames, String[] formalTypes) {
- final Pointcut sp = Pointcut.fromString(pointcutSource);
- final Pointcut rp =
- sp.resolve(
- new SimpleScope(
- world,
- SimpleScope.makeFormalBindings(TypeX.forNames(formalTypes),
- formalNames)
- ));
- return rp;
- }
- }
|