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.

PerTypeWithinTargetTypeMunger.java 2.7KB

14 lat temu
14 lat temu
14 lat temu
14 lat temu
14 lat temu
14 lat temu
14 lat temu
14 lat temu
14 lat temu
14 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* *******************************************************************
  2. * Copyright (c) 2005 IBM, Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Andy Clement initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.IOException;
  14. import org.aspectj.util.FuzzyBoolean;
  15. import org.aspectj.weaver.patterns.PerTypeWithin;
  16. import org.aspectj.weaver.patterns.Pointcut;
  17. // PTWIMPL Target type munger adds the localAspectOf() method
  18. public class PerTypeWithinTargetTypeMunger extends ResolvedTypeMunger {
  19. private UnresolvedType aspectType;
  20. private PerTypeWithin testPointcut;
  21. public PerTypeWithinTargetTypeMunger(UnresolvedType aspectType, PerTypeWithin testPointcut) {
  22. super(PerTypeWithinInterface, null);
  23. this.aspectType = aspectType;
  24. this.testPointcut = testPointcut;
  25. }
  26. @Override
  27. public boolean equals(Object other) {
  28. if (!(other instanceof PerTypeWithinTargetTypeMunger)) {
  29. return false;
  30. }
  31. PerTypeWithinTargetTypeMunger o = (PerTypeWithinTargetTypeMunger) other;
  32. return ((o.testPointcut == null) ? (testPointcut == null) : testPointcut.equals(o.testPointcut))
  33. && ((o.aspectType == null) ? (aspectType == null) : aspectType.equals(o.aspectType));
  34. }
  35. private volatile int hashCode = 0;
  36. @Override
  37. public int hashCode() {
  38. if (hashCode == 0) {
  39. int result = 17;
  40. result = 37 * result + ((testPointcut == null) ? 0 : testPointcut.hashCode());
  41. result = 37 * result + ((aspectType == null) ? 0 : aspectType.hashCode());
  42. hashCode = result;
  43. }
  44. return hashCode;
  45. }
  46. @Override
  47. public void write(CompressingDataOutputStream s) throws IOException {
  48. throw new RuntimeException("shouldn't be serialized");
  49. }
  50. public UnresolvedType getAspectType() {
  51. return aspectType;
  52. }
  53. public Pointcut getTestPointcut() {
  54. return testPointcut;
  55. }
  56. // This is a lexical within() so if you say PerTypeWithin(Test) and matchType is an
  57. // inner type (e.g. Test$NestedType) then it should match successfully
  58. // Does not match if the target is an interface
  59. @Override
  60. public boolean matches(ResolvedType matchType, ResolvedType aspectType) {
  61. return isWithinType(matchType).alwaysTrue() && !matchType.isInterface() && (matchType.canBeSeenBy(aspectType) || aspectType.isPrivilegedAspect());
  62. }
  63. private FuzzyBoolean isWithinType(ResolvedType type) {
  64. while (type != null) {
  65. if (testPointcut.getTypePattern().matchesStatically(type)) {
  66. return FuzzyBoolean.YES;
  67. }
  68. type = type.getDeclaringType();
  69. }
  70. return FuzzyBoolean.NO;
  71. }
  72. }