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.

PerObjectInterfaceTypeMunger.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 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. * PARC initial implementation
  11. * Alexandre Vasseur rearchitected for #75442 finer grained matching
  12. * ******************************************************************/
  13. package org.aspectj.weaver;
  14. import java.io.IOException;
  15. import org.aspectj.weaver.patterns.PerFromSuper;
  16. import org.aspectj.weaver.patterns.PerObject;
  17. import org.aspectj.weaver.patterns.PerThisOrTargetPointcutVisitor;
  18. import org.aspectj.weaver.patterns.Pointcut;
  19. import org.aspectj.weaver.patterns.TypePattern;
  20. public class PerObjectInterfaceTypeMunger extends ResolvedTypeMunger {
  21. private final UnresolvedType interfaceType;
  22. private final Pointcut testPointcut;
  23. private TypePattern lazyTestTypePattern;
  24. public boolean equals(Object other) {
  25. if (!(other instanceof PerObjectInterfaceTypeMunger)) {
  26. return false;
  27. }
  28. PerObjectInterfaceTypeMunger o = (PerObjectInterfaceTypeMunger) other;
  29. return ((testPointcut == null) ? (o.testPointcut == null) : testPointcut.equals(o.testPointcut))
  30. && ((lazyTestTypePattern == null) ? (o.lazyTestTypePattern == null) : lazyTestTypePattern
  31. .equals(o.lazyTestTypePattern));
  32. }
  33. private volatile int hashCode = 0;
  34. public int hashCode() {
  35. if (hashCode == 0) {
  36. int result = 17;
  37. result = 37 * result + ((testPointcut == null) ? 0 : testPointcut.hashCode());
  38. result = 37 * result + ((lazyTestTypePattern == null) ? 0 : lazyTestTypePattern.hashCode());
  39. hashCode = result;
  40. }
  41. return hashCode;
  42. }
  43. public PerObjectInterfaceTypeMunger(UnresolvedType aspectType, Pointcut testPointcut) {
  44. super(PerObjectInterface, null);
  45. this.testPointcut = testPointcut;
  46. this.interfaceType = AjcMemberMaker.perObjectInterfaceType(aspectType);
  47. }
  48. private TypePattern getTestTypePattern(ResolvedType aspectType) {
  49. if (lazyTestTypePattern == null) {
  50. final boolean isPerThis;
  51. if (aspectType.getPerClause() instanceof PerFromSuper) {
  52. PerFromSuper ps = (PerFromSuper) aspectType.getPerClause();
  53. isPerThis = ((PerObject) ps.lookupConcretePerClause(aspectType)).isThis();
  54. } else {
  55. isPerThis = ((PerObject) aspectType.getPerClause()).isThis();
  56. }
  57. PerThisOrTargetPointcutVisitor v = new PerThisOrTargetPointcutVisitor(!isPerThis, aspectType);
  58. lazyTestTypePattern = v.getPerTypePointcut(testPointcut);
  59. // reset hashCode so that its recalculated with the new lazyTestTypePattern
  60. hashCode = 0;
  61. }
  62. return lazyTestTypePattern;
  63. }
  64. public void write(CompressingDataOutputStream s) throws IOException {
  65. throw new RuntimeException("shouldn't be serialized");
  66. }
  67. public UnresolvedType getInterfaceType() {
  68. return interfaceType;
  69. }
  70. public Pointcut getTestPointcut() {
  71. return testPointcut;
  72. }
  73. public boolean matches(ResolvedType matchType, ResolvedType aspectType) {
  74. if (matchType.isInterface()) {
  75. return false;
  76. }
  77. return getTestTypePattern(aspectType).matchesStatically(matchType);
  78. }
  79. public boolean isLateMunger() {
  80. return true;
  81. }
  82. }