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.

PerFromSuper.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import java.util.Map;
  15. import org.aspectj.bridge.MessageUtil;
  16. import org.aspectj.util.FuzzyBoolean;
  17. import org.aspectj.weaver.CompressingDataOutputStream;
  18. import org.aspectj.weaver.ISourceContext;
  19. import org.aspectj.weaver.ResolvedType;
  20. import org.aspectj.weaver.Shadow;
  21. import org.aspectj.weaver.UnresolvedType;
  22. import org.aspectj.weaver.VersionedDataInputStream;
  23. import org.aspectj.weaver.WeaverMessages;
  24. import org.aspectj.weaver.World;
  25. import org.aspectj.weaver.ast.Test;
  26. public class PerFromSuper extends PerClause {
  27. private PerClause.Kind kind;
  28. public PerFromSuper(PerClause.Kind kind) {
  29. this.kind = kind;
  30. }
  31. public Object accept(PatternNodeVisitor visitor, Object data) {
  32. return visitor.visit(this, data);
  33. }
  34. public int couldMatchKinds() {
  35. return Shadow.ALL_SHADOW_KINDS_BITS;
  36. }
  37. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  38. throw new RuntimeException("unimplemented");
  39. }
  40. protected FuzzyBoolean matchInternal(Shadow shadow) {
  41. throw new RuntimeException("unimplemented");
  42. }
  43. public void resolveBindings(IScope scope, Bindings bindings) {
  44. // this method intentionally left blank
  45. }
  46. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  47. throw new RuntimeException("unimplemented");
  48. }
  49. public PerClause concretize(ResolvedType inAspect) {
  50. PerClause p = lookupConcretePerClause(inAspect.getSuperclass());
  51. if (p == null) {
  52. inAspect.getWorld().getMessageHandler().handleMessage(
  53. MessageUtil.error(WeaverMessages.format(WeaverMessages.MISSING_PER_CLAUSE, inAspect.getSuperclass()),
  54. getSourceLocation()));
  55. return new PerSingleton().concretize(inAspect);// AV: fallback on something else NPE in AJDT
  56. } else {
  57. if (p.getKind() != kind) {
  58. inAspect.getWorld().getMessageHandler().handleMessage(
  59. MessageUtil.error(WeaverMessages.format(WeaverMessages.WRONG_PER_CLAUSE, kind, p.getKind()),
  60. getSourceLocation()));
  61. }
  62. return p.concretize(inAspect);
  63. }
  64. }
  65. public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  66. return this;
  67. }
  68. public PerClause lookupConcretePerClause(ResolvedType lookupType) {
  69. PerClause ret = lookupType.getPerClause();
  70. if (ret == null) {
  71. return null;
  72. }
  73. if (ret instanceof PerFromSuper) {
  74. return lookupConcretePerClause(lookupType.getSuperclass());
  75. }
  76. return ret;
  77. }
  78. public void write(CompressingDataOutputStream s) throws IOException {
  79. FROMSUPER.write(s);
  80. kind.write(s);
  81. writeLocation(s);
  82. }
  83. public static PerClause readPerClause(VersionedDataInputStream s, ISourceContext context) throws IOException {
  84. PerFromSuper ret = new PerFromSuper(Kind.read(s));
  85. ret.readLocation(context, s);
  86. return ret;
  87. }
  88. public String toString() {
  89. return "perFromSuper(" + kind + ", " + inAspect + ")";
  90. }
  91. public String toDeclarationString() {
  92. return "";
  93. }
  94. public PerClause.Kind getKind() {
  95. return kind;
  96. }
  97. public boolean equals(Object other) {
  98. if (!(other instanceof PerFromSuper)) {
  99. return false;
  100. }
  101. PerFromSuper pc = (PerFromSuper) other;
  102. return pc.kind.equals(kind) && ((pc.inAspect == null) ? (inAspect == null) : pc.inAspect.equals(inAspect));
  103. }
  104. public int hashCode() {
  105. int result = 17;
  106. result = 37 * result + kind.hashCode();
  107. result = 37 * result + ((inAspect == null) ? 0 : inAspect.hashCode());
  108. return result;
  109. }
  110. }