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.

DeclareParents.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 DeclareParents extends Declare {
  18. private TypePattern child;
  19. private TypePatternList parents;
  20. public DeclareParents(TypePattern child, List parents) {
  21. this(child, new TypePatternList(parents));
  22. }
  23. private DeclareParents(TypePattern child, TypePatternList parents) {
  24. this.child = child;
  25. this.parents = parents;
  26. }
  27. public boolean match(ResolvedTypeX typeX) {
  28. return child.matchesStatically(typeX);
  29. }
  30. public String toString() {
  31. StringBuffer buf = new StringBuffer();
  32. buf.append("declare parents: ");
  33. buf.append(child);
  34. buf.append(" extends "); //extends and implements are treated equivalently
  35. buf.append(parents);
  36. buf.append(";");
  37. return buf.toString();
  38. }
  39. public boolean equals(Object other) {
  40. if (!(other instanceof DeclareParents)) return false;
  41. DeclareParents o = (DeclareParents)other;
  42. return o.child.equals(child) && o.parents.equals(parents);
  43. }
  44. //??? cache this
  45. public int hashCode() {
  46. int result = 23;
  47. result = 37*result + child.hashCode();
  48. result = 37*result + parents.hashCode();
  49. return result;
  50. }
  51. public void write(DataOutputStream s) throws IOException {
  52. s.writeByte(Declare.PARENTS);
  53. child.write(s);
  54. parents.write(s);
  55. writeLocation(s);
  56. }
  57. public static Declare read(DataInputStream s, ISourceContext context) throws IOException {
  58. Declare ret = new DeclareParents(TypePattern.read(s, context), TypePatternList.read(s, context));
  59. ret.readLocation(context, s);
  60. return ret;
  61. }
  62. public void resolve(IScope scope) {
  63. child = child.resolveBindings(scope, Bindings.NONE, false, false);
  64. parents = parents.resolveBindings(scope, Bindings.NONE, false, true);
  65. // for (int i=0; i < parents.size(); i++) {
  66. // parents.get(i).assertExactType(scope.getMessageHandler());
  67. // }
  68. }
  69. public TypePatternList getParents() {
  70. return parents;
  71. }
  72. public TypePattern getChild() {
  73. return child;
  74. }
  75. public boolean isAdviceLike() {
  76. return false;
  77. }
  78. }