You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomMungerExtensionTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. package org.aspectj.systemtest.ajc154;
  13. import java.io.File;
  14. import java.util.ArrayList;
  15. import java.util.Collection;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import org.aspectj.ajde.core.AjCompiler;
  20. import org.aspectj.bridge.ISourceLocation;
  21. import org.aspectj.systemtest.incremental.tools.AjdeInteractionTestbed;
  22. import org.aspectj.weaver.Advice;
  23. import org.aspectj.weaver.Checker;
  24. import org.aspectj.weaver.ConcreteTypeMunger;
  25. import org.aspectj.weaver.CustomMungerFactory;
  26. import org.aspectj.weaver.Member;
  27. import org.aspectj.weaver.ResolvedType;
  28. import org.aspectj.weaver.ResolvedTypeMunger;
  29. import org.aspectj.weaver.Shadow;
  30. import org.aspectj.weaver.ShadowMunger;
  31. import org.aspectj.weaver.World;
  32. import org.aspectj.weaver.AjAttribute.AdviceAttribute;
  33. import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
  34. import org.aspectj.weaver.patterns.IfPointcut;
  35. import org.aspectj.weaver.patterns.Pointcut;
  36. public class CustomMungerExtensionTest extends AjdeInteractionTestbed {
  37. protected void setUp() throws Exception {
  38. super.setUp();
  39. sandboxDir = new File(".");
  40. }
  41. public void testExtension() {
  42. String testFileDir = "bugs/pointcutdoctor-bug193065";
  43. AjCompiler compiler = getCompilerForProjectWithName(testFileDir);
  44. compiler.setCustomMungerFactory(new DumbCustomMungerFactory());
  45. doBuild(testFileDir);
  46. CustomMungerFactory factory = (CustomMungerFactory)compiler.getCustomMungerFactory();
  47. assertTrue(factory.getAllCreatedCustomShadowMungers().size()>0);
  48. for (Iterator i = factory.getAllCreatedCustomShadowMungers().iterator(); i.hasNext();)
  49. assertTrue(((DumbShadowMunger)i.next()).called);
  50. assertTrue(factory.getAllCreatedCustomTypeMungers().size()>0);
  51. for (Iterator i = factory.getAllCreatedCustomTypeMungers().iterator(); i.hasNext();)
  52. assertTrue(((DumbTypeMunger)i.next()).called);
  53. }
  54. class DumbCustomMungerFactory implements CustomMungerFactory {
  55. Collection allShadowMungers = new ArrayList();
  56. Collection allTypeMungers = new ArrayList();
  57. public Collection createCustomShadowMungers(ResolvedType aspectType) {
  58. List/* ShadowMunger */ mungers = new ArrayList/*ShadowMunger*/();
  59. Pointcut pointcut = new IfPointcut("abc");
  60. mungers.add(new DumbShadowMunger(new DeclareErrorOrWarning(false, pointcut, "")));
  61. allShadowMungers.addAll(mungers);
  62. return mungers;
  63. }
  64. public Collection createCustomTypeMungers(ResolvedType aspectType) {
  65. List/*ConcreteTypeMunger*/ mungers = new ArrayList/*ShadowMunger*/();
  66. mungers.add(new DumbTypeMunger(null, aspectType));
  67. allTypeMungers.addAll(mungers);
  68. return mungers;
  69. }
  70. public Collection getAllCreatedCustomShadowMungers() {
  71. return allShadowMungers;
  72. }
  73. public Collection getAllCreatedCustomTypeMungers() {
  74. return allTypeMungers;
  75. }
  76. }
  77. class DumbShadowMunger extends Checker {
  78. public DumbShadowMunger(DeclareErrorOrWarning deow) {
  79. super(deow);
  80. }
  81. public ISourceLocation getSourceLocation() {
  82. return ISourceLocation.EMPTY;
  83. }
  84. boolean called;
  85. public boolean match(Shadow shadow, World world) {
  86. called = true;
  87. return false;
  88. }
  89. }
  90. class DumbTypeMunger extends ConcreteTypeMunger {
  91. boolean called;
  92. public DumbTypeMunger(ResolvedTypeMunger munger, ResolvedType aspectType) {
  93. super(munger, aspectType);
  94. }
  95. public ConcreteTypeMunger parameterizedFor(ResolvedType targetType) {
  96. return null;
  97. }
  98. public boolean matches(ResolvedType onType) {
  99. called = true;
  100. return false;
  101. }
  102. }
  103. }