Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ConcretizationTestCase.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.*;
  14. import java.util.*;
  15. import org.aspectj.testing.util.TestUtil;
  16. import org.aspectj.weaver.*;
  17. import org.aspectj.weaver.bcel.*;
  18. import org.aspectj.weaver.bcel.WeaveTestCase;
  19. public class ConcretizationTestCase extends WeaveTestCase {
  20. {
  21. regenerate = false;
  22. }
  23. public ConcretizationTestCase(String name) {
  24. super(name);
  25. }
  26. String[] none = new String[0];
  27. public void testCflowResidual() throws IOException {
  28. BcelAdvice a = (BcelAdvice) makeConcreteTestAdviceEntryPart();
  29. TestShadow shadow = new TestShadow(Shadow.MethodCall,
  30. Member.methodFromString("int Aspect.i(int x)"),
  31. TypeX.OBJECT,
  32. world);
  33. ExposedState state = new ExposedState(1);
  34. a.specializeOn(shadow);
  35. //System.err.println(shadow);
  36. //System.err.println(a);
  37. //System.err.println(a.exposedState);
  38. }
  39. public Advice makeConcreteTestAdviceEntryPart() throws IOException {
  40. // XXX copied from below, refactor later
  41. // returns the advice for the entry part of cflow(foo(a))
  42. Pointcut in =
  43. createResolvedPointcut(
  44. "cflow(foo(a)) && (args(b) && !cflow(foo(int)))",
  45. new String[] { "b", "a" },
  46. new String[] { "float", "int" });
  47. ResolvedPointcutDefinition ref =
  48. new ResolvedPointcutDefinition(
  49. TypeX.forName("Aspect"),
  50. 0,
  51. "foo",
  52. new TypeX[] { ResolvedTypeX.INT },
  53. createResolvedPointcut(
  54. "args(refA)",
  55. new String[] { "refA" },
  56. new String[] { "int" }));
  57. BcelObjectType target = (BcelObjectType) world.resolve("Aspect");
  58. // now munge this to get the pointcut in it
  59. target.addPointcutDefinition(ref);
  60. CrosscuttingMembers xcut = new CrosscuttingMembers(target);
  61. target.crosscuttingMembers = xcut;
  62. Advice adviceMember =
  63. new BcelAdvice(
  64. AdviceKind.Before,
  65. in,
  66. Member.method(TypeX.forName("FOO"), 0, "garadf", "(FI)V"),
  67. 0,
  68. 0, 0, null,
  69. null);
  70. // The pointcut to concretize
  71. // this returns the actual advice, but we don't care about it now.
  72. in.concretize(target, 2, adviceMember);
  73. List c = (List)xcut.getCflowEntries(); //target.getExtraConcreteShadowMungers();
  74. return (Advice) c.get(0);
  75. }
  76. public void XtestCflow() throws IOException {
  77. Pointcut in = createResolvedPointcut("cflow(foo(a)) && (args(b) && !cflow(foo(int)))",
  78. new String[] {"b", "a"}, new String[] {"float", "int"} );
  79. ResolvedPointcutDefinition ref =
  80. new ResolvedPointcutDefinition(TypeX.forName("Aspect"),
  81. 0, "foo", new TypeX[] { ResolvedTypeX.INT },
  82. createResolvedPointcut("args(refA)",
  83. new String[] {"refA"}, new String[] {"int"}));
  84. List expectedSlots = new ArrayList();
  85. expectedSlots.add(new ConcreteCflowPointcut.Slot(1, ResolvedTypeX.INT, 0));
  86. checkConcr(in, ref, expectedSlots);
  87. }
  88. public void checkConcr(
  89. Pointcut in,
  90. ResolvedPointcutDefinition referredTo,
  91. List expectedSlots) throws IOException {
  92. BcelObjectType target = (BcelObjectType)world.resolve("Aspect");
  93. // now munge this to get the pointcut in it
  94. target.addPointcutDefinition(referredTo);
  95. Advice adviceMember = new BcelAdvice(AdviceKind.Before, in,
  96. Member.method(TypeX.forName("FOO"), 0, "garadf", "(FI)V"), 0, 0, 0, null, null);
  97. // The pointcut to concretize
  98. AndPointcut ap = (AndPointcut)in.concretize(target, 2, adviceMember);
  99. ConcreteCflowPointcut conc = (ConcreteCflowPointcut)ap.left;
  100. List slots = conc.slots;
  101. TestUtil.assertSetEquals(expectedSlots, slots);
  102. }
  103. public Pointcut createResolvedPointcut(
  104. String pointcutSource, String[] formalNames, String[] formalTypes) {
  105. final Pointcut sp = Pointcut.fromString(pointcutSource);
  106. final Pointcut rp =
  107. sp.resolve(
  108. new SimpleScope(
  109. world,
  110. SimpleScope.makeFormalBindings(TypeX.forNames(formalTypes),
  111. formalNames)
  112. ));
  113. return rp;
  114. }
  115. }