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.

PoliceExtensionUse.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*******************************************************************************
  2. * Copyright (c) 2006 IBM
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * Andy Clement - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.weaver;
  12. import org.aspectj.bridge.IMessage;
  13. import org.aspectj.bridge.MessageUtil;
  14. import org.aspectj.weaver.patterns.AbstractPatternNodeVisitor;
  15. import org.aspectj.weaver.patterns.AndPointcut;
  16. import org.aspectj.weaver.patterns.KindedPointcut;
  17. import org.aspectj.weaver.patterns.NotPointcut;
  18. import org.aspectj.weaver.patterns.OrPointcut;
  19. import org.aspectj.weaver.patterns.Pointcut;
  20. /**
  21. * Walks a pointcut and determines if the synchronization related designators have been used: lock() or unlock()
  22. */
  23. public class PoliceExtensionUse extends AbstractPatternNodeVisitor {
  24. private boolean synchronizationDesignatorEncountered;
  25. private World world;
  26. private Pointcut p;
  27. public PoliceExtensionUse(World w, Pointcut p) {
  28. this.world = w;
  29. this.p = p;
  30. this.synchronizationDesignatorEncountered = false;
  31. }
  32. public boolean synchronizationDesignatorEncountered() {
  33. return synchronizationDesignatorEncountered;
  34. }
  35. public Object visit(KindedPointcut node, Object data) {
  36. if (world == null)
  37. return super.visit(node, data); // error scenario can sometimes lead to this LazyClassGen.toLongString()
  38. if (node.getKind() == Shadow.SynchronizationLock || node.getKind() == Shadow.SynchronizationUnlock)
  39. synchronizationDesignatorEncountered = true;
  40. // Check it!
  41. if (!world.isJoinpointSynchronizationEnabled()) {
  42. if (node.getKind() == Shadow.SynchronizationLock) {
  43. IMessage m = MessageUtil.warn(
  44. "lock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization", p
  45. .getSourceLocation());
  46. world.getMessageHandler().handleMessage(m);
  47. } else if (node.getKind() == Shadow.SynchronizationUnlock) {
  48. IMessage m = MessageUtil.warn(
  49. "unlock() pointcut designator cannot be used without the option -Xjoinpoints:synchronization", p
  50. .getSourceLocation());
  51. world.getMessageHandler().handleMessage(m);
  52. }
  53. }
  54. return super.visit(node, data);
  55. }
  56. public Object visit(AndPointcut node, Object data) {
  57. node.getLeft().accept(this, data);
  58. node.getRight().accept(this, data);
  59. return node;
  60. }
  61. public Object visit(NotPointcut node, Object data) {
  62. node.getNegatedPointcut().accept(this, data);
  63. return node;
  64. }
  65. public Object visit(OrPointcut node, Object data) {
  66. node.getLeft().accept(this, data);
  67. node.getRight().accept(this, data);
  68. return node;
  69. }
  70. }