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.

DeclareDominates.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.*;
  14. import java.util.List;
  15. import org.aspectj.weaver.*;
  16. import org.aspectj.weaver.ResolvedTypeX;
  17. public class DeclareDominates extends Declare {
  18. private TypePatternList patterns;
  19. public DeclareDominates(List patterns) {
  20. this(new TypePatternList(patterns));
  21. }
  22. private DeclareDominates(TypePatternList patterns) {
  23. this.patterns = patterns;
  24. }
  25. public String toString() {
  26. StringBuffer buf = new StringBuffer();
  27. buf.append("declare dominates: ");
  28. buf.append(patterns);
  29. buf.append(";");
  30. return buf.toString();
  31. }
  32. public boolean equals(Object other) {
  33. if (!(other instanceof DeclareDominates)) return false;
  34. DeclareDominates o = (DeclareDominates)other;
  35. return o.patterns.equals(patterns);
  36. }
  37. public int hashCode() {
  38. return patterns.hashCode();
  39. }
  40. public void write(DataOutputStream s) throws IOException {
  41. s.writeByte(Declare.DOMINATES);
  42. patterns.write(s);
  43. writeLocation(s);
  44. }
  45. public static Declare read(DataInputStream s, ISourceContext context) throws IOException {
  46. Declare ret = new DeclareDominates(TypePatternList.read(s, context));
  47. ret.readLocation(context, s);
  48. return ret;
  49. }
  50. public void resolve(IScope scope) {
  51. patterns = patterns.resolveBindings(scope, Bindings.NONE, false, false);
  52. }
  53. public TypePatternList getPatterns() {
  54. return patterns;
  55. }
  56. private int matchingIndex(ResolvedTypeX a) {
  57. int knownMatch = -1;
  58. int starMatch = -1;
  59. for (int i=0, len=patterns.size(); i < len; i++) {
  60. TypePattern p = patterns.get(i);
  61. if (p.isStar()) {
  62. starMatch = i;
  63. } else if (p.matchesExactly(a)) {
  64. if (knownMatch != -1) {
  65. throw new BCException("multiple matches: " + this + " with " + a);
  66. } else {
  67. knownMatch = i;
  68. }
  69. }
  70. }
  71. if (knownMatch == -1) return starMatch;
  72. else return knownMatch;
  73. }
  74. public int compare(ResolvedTypeX aspect1, ResolvedTypeX aspect2) {
  75. int index1 = matchingIndex(aspect1);
  76. int index2 = matchingIndex(aspect2);
  77. //System.out.println("a1: " + aspect1 + ", " + aspect2 + " = " + index1 + ", " + index2);
  78. if (index1 == -1 || index2 == -1) return 0;
  79. if (index1 == index2) return 0;
  80. else if (index1 > index2) return -1;
  81. else return +1;
  82. }
  83. public boolean isAdviceLike() {
  84. return false;
  85. }
  86. }