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.

ExactTypePattern.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 org.aspectj.weaver.*;
  15. import org.aspectj.util.*;
  16. public class ExactTypePattern extends TypePattern {
  17. protected TypeX type;
  18. public ExactTypePattern(TypeX type, boolean includeSubtypes) {
  19. super(includeSubtypes);
  20. this.type = type;
  21. }
  22. protected boolean matchesExactly(ResolvedTypeX matchType) {
  23. return this.type.equals(matchType);
  24. }
  25. public TypeX getType() { return type; }
  26. public FuzzyBoolean matchesInstanceof(ResolvedTypeX matchType) {
  27. // in our world, Object is assignable from anything
  28. if (type.equals(ResolvedTypeX.OBJECT)) return FuzzyBoolean.YES;
  29. if (type.isAssignableFrom(matchType, matchType.getWorld())) {
  30. return FuzzyBoolean.YES;
  31. }
  32. return matchType.isCoerceableFrom(type) ? FuzzyBoolean.MAYBE : FuzzyBoolean.NO;
  33. }
  34. public boolean equals(Object other) {
  35. if (!(other instanceof ExactTypePattern)) return false;
  36. ExactTypePattern o = (ExactTypePattern)other;
  37. return o.type.equals(this.type);
  38. }
  39. public int hashCode() {
  40. return type.hashCode();
  41. }
  42. public void write(DataOutputStream out) throws IOException {
  43. out.writeByte(TypePattern.EXACT);
  44. type.write(out);
  45. out.writeBoolean(includeSubtypes);
  46. writeLocation(out);
  47. }
  48. public static TypePattern read(DataInputStream s, ISourceContext context) throws IOException {
  49. TypePattern ret = new ExactTypePattern(TypeX.read(s), s.readBoolean());
  50. ret.readLocation(context, s);
  51. return ret;
  52. }
  53. public String toString() {
  54. //Thread.currentThread().dumpStack();
  55. return "ExactTypePattern(" + type.toString() + (includeSubtypes ? "+" : "") + ")";
  56. }
  57. public TypePattern resolveBindings(IScope scope, Bindings bindings,
  58. boolean allowBinding, boolean requireExactType)
  59. {
  60. throw new BCException("trying to re-resolve");
  61. }
  62. }