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.

BindingTypePattern.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.DataInputStream;
  14. import java.io.DataOutputStream;
  15. import java.io.IOException;
  16. import org.aspectj.weaver.ISourceContext;
  17. import org.aspectj.weaver.IntMap;
  18. import org.aspectj.weaver.TypeX;
  19. public class BindingTypePattern extends ExactTypePattern implements BindingPattern {
  20. private int formalIndex;
  21. public BindingTypePattern(TypeX type, int index,boolean isVarArgs) {
  22. super(type, false,isVarArgs);
  23. this.formalIndex = index;
  24. }
  25. public BindingTypePattern(FormalBinding binding, boolean isVarArgs) {
  26. this(binding.getType(), binding.getIndex(),isVarArgs);
  27. }
  28. public int getFormalIndex() {
  29. return formalIndex;
  30. }
  31. public boolean equals(Object other) {
  32. if (!(other instanceof BindingTypePattern)) return false;
  33. BindingTypePattern o = (BindingTypePattern)other;
  34. if (includeSubtypes != o.includeSubtypes) return false;
  35. if (isVarArgs != o.isVarArgs) return false;
  36. return o.type.equals(this.type) && o.formalIndex == this.formalIndex;
  37. }
  38. public int hashCode() {
  39. int result = 17;
  40. result = 37*result + type.hashCode();
  41. result = 37*result + formalIndex;
  42. return result;
  43. }
  44. public void write(DataOutputStream out) throws IOException {
  45. out.writeByte(TypePattern.BINDING);
  46. type.write(out);
  47. out.writeShort((short)formalIndex);
  48. out.writeBoolean(isVarArgs);
  49. writeLocation(out);
  50. }
  51. public static TypePattern read(DataInputStream s, ISourceContext context) throws IOException {
  52. TypePattern ret = new BindingTypePattern(TypeX.read(s), s.readShort(), s.readBoolean());
  53. ret.readLocation(context, s);
  54. return ret;
  55. }
  56. public TypePattern remapAdviceFormals(IntMap bindings) {
  57. if (!bindings.hasKey(formalIndex)) {
  58. return new ExactTypePattern(type, false, isVarArgs);
  59. } else {
  60. int newFormalIndex = bindings.get(formalIndex);
  61. return new BindingTypePattern(type, newFormalIndex, isVarArgs);
  62. }
  63. }
  64. public String toString() {
  65. //Thread.currentThread().dumpStack();
  66. return "BindingTypePattern(" + super.toString() + ", " + formalIndex + ")";
  67. }
  68. }