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 3.4KB

15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
15 jaren geleden
9 jaren geleden
15 jaren geleden
15 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* *******************************************************************
  2. * Copyright (c) 2002, 2010 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. * Nieraj Singh
  12. * ******************************************************************/
  13. package org.aspectj.weaver.patterns;
  14. import java.io.IOException;
  15. import java.util.Map;
  16. import org.aspectj.weaver.AjAttribute;
  17. import org.aspectj.weaver.CompressingDataOutputStream;
  18. import org.aspectj.weaver.ISourceContext;
  19. import org.aspectj.weaver.IntMap;
  20. import org.aspectj.weaver.UnresolvedType;
  21. import org.aspectj.weaver.VersionedDataInputStream;
  22. import org.aspectj.weaver.World;
  23. public class BindingTypePattern extends ExactTypePattern implements BindingPattern {
  24. private int formalIndex;
  25. private String bindingName;
  26. public BindingTypePattern(UnresolvedType type, int index, boolean isVarArgs) {
  27. super(type, false, isVarArgs);
  28. this.formalIndex = index;
  29. }
  30. public BindingTypePattern(FormalBinding binding, boolean isVarArgs) {
  31. this(binding.getType(), binding.getIndex(), isVarArgs);
  32. this.bindingName = binding.getName();
  33. }
  34. public int getFormalIndex() {
  35. return formalIndex;
  36. }
  37. public String getBindingName() {
  38. return bindingName;
  39. }
  40. public boolean equals(Object other) {
  41. if (!(other instanceof BindingTypePattern)) {
  42. return false;
  43. }
  44. BindingTypePattern o = (BindingTypePattern) other;
  45. if (includeSubtypes != o.includeSubtypes) {
  46. return false;
  47. }
  48. if (isVarArgs != o.isVarArgs) {
  49. return false;
  50. }
  51. return o.type.equals(this.type) && o.formalIndex == this.formalIndex;
  52. }
  53. public int hashCode() {
  54. int result = 17;
  55. result = 37 * result + super.hashCode();
  56. result = 37 * result + formalIndex;
  57. return result;
  58. }
  59. public void write(CompressingDataOutputStream out) throws IOException {
  60. out.writeByte(TypePattern.BINDING);
  61. type.write(out);
  62. out.writeShort((short) formalIndex);
  63. out.writeBoolean(isVarArgs);
  64. writeLocation(out);
  65. }
  66. public static TypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  67. UnresolvedType type = UnresolvedType.read(s);
  68. int index = s.readShort();
  69. boolean isVarargs = false;
  70. if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) {
  71. isVarargs = s.readBoolean();
  72. }
  73. TypePattern ret = new BindingTypePattern(type, index, isVarargs);
  74. ret.readLocation(context, s);
  75. return ret;
  76. }
  77. public TypePattern remapAdviceFormals(IntMap bindings) {
  78. if (!bindings.hasKey(formalIndex)) {
  79. return new ExactTypePattern(type, false, isVarArgs);
  80. } else {
  81. int newFormalIndex = bindings.get(formalIndex);
  82. return new BindingTypePattern(type, newFormalIndex, isVarArgs);
  83. }
  84. }
  85. public TypePattern parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  86. ExactTypePattern superParameterized = (ExactTypePattern) super.parameterizeWith(typeVariableMap, w);
  87. BindingTypePattern ret = new BindingTypePattern(superParameterized.getExactType(), this.formalIndex, this.isVarArgs);
  88. ret.copyLocationFrom(this);
  89. return ret;
  90. }
  91. public String toString() {
  92. // Thread.currentThread().dumpStack();
  93. return "BindingTypePattern(" + super.toString() + ", " + formalIndex + ")";
  94. }
  95. }