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.

AndTypePattern.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.util.FuzzyBoolean;
  17. import org.aspectj.weaver.ISourceContext;
  18. import org.aspectj.weaver.ResolvedTypeX;
  19. /**
  20. * left && right
  21. *
  22. * <p>any binding to formals is explicitly forbidden for any composite by the language
  23. *
  24. * @author Erik Hilsdale
  25. * @author Jim Hugunin
  26. */
  27. public class AndTypePattern extends TypePattern {
  28. private TypePattern left, right;
  29. public AndTypePattern(TypePattern left, TypePattern right) {
  30. super(false,false); //?? we override all methods that care about includeSubtypes
  31. this.left = left;
  32. this.right = right;
  33. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  34. }
  35. public FuzzyBoolean matchesInstanceof(ResolvedTypeX type) {
  36. return left.matchesInstanceof(type).and(right.matchesInstanceof(type));
  37. }
  38. protected boolean matchesExactly(ResolvedTypeX type) {
  39. //??? if these had side-effects, this sort-circuit could be a mistake
  40. return left.matchesExactly(type) && right.matchesExactly(type);
  41. }
  42. public boolean matchesStatically(Class type) {
  43. return left.matchesStatically(type) && right.matchesStatically(type);
  44. }
  45. public FuzzyBoolean matchesInstanceof(Class type) {
  46. return left.matchesInstanceof(type).and(right.matchesInstanceof(type));
  47. }
  48. protected boolean matchesExactly(Class type) {
  49. //??? if these had side-effects, this sort-circuit could be a mistake
  50. return left.matchesExactly(type) && right.matchesExactly(type);
  51. }
  52. public boolean matchesStatically(ResolvedTypeX type) {
  53. return left.matchesStatically(type) && right.matchesStatically(type);
  54. }
  55. public void write(DataOutputStream s) throws IOException {
  56. s.writeByte(TypePattern.AND);
  57. left.write(s);
  58. right.write(s);
  59. writeLocation(s);
  60. }
  61. public static TypePattern read(DataInputStream s, ISourceContext context) throws IOException {
  62. TypePattern ret = new AndTypePattern(TypePattern.read(s, context), TypePattern.read(s, context));
  63. ret.readLocation(context, s);
  64. return ret;
  65. }
  66. public TypePattern resolveBindings(
  67. IScope scope,
  68. Bindings bindings,
  69. boolean allowBinding, boolean requireExactType)
  70. {
  71. if (requireExactType) return notExactType(scope);
  72. left = left.resolveBindings(scope, bindings, false, false);
  73. right = right.resolveBindings(scope, bindings, false, false);
  74. return this;
  75. }
  76. public TypePattern resolveBindingsFromRTTI(boolean allowBinding, boolean requireExactType) {
  77. if (requireExactType) return TypePattern.NO;
  78. left = left.resolveBindingsFromRTTI(allowBinding,requireExactType);
  79. right = right.resolveBindingsFromRTTI(allowBinding,requireExactType);
  80. return this;
  81. }
  82. public String toString() {
  83. StringBuffer buff = new StringBuffer();
  84. if (annotationPattern != AnnotationTypePattern.ANY) {
  85. buff.append('(');
  86. buff.append(annotationPattern.toString());
  87. buff.append(' ');
  88. }
  89. buff.append('(');
  90. buff.append(left.toString());
  91. buff.append(" && ");
  92. buff.append(right.toString());
  93. buff.append(')');
  94. if (annotationPattern != AnnotationTypePattern.ANY) {
  95. buff.append(')');
  96. }
  97. return buff.toString();
  98. }
  99. public boolean equals(Object obj) {
  100. if (! (obj instanceof AndTypePattern)) return false;
  101. AndTypePattern atp = (AndTypePattern) obj;
  102. return left.equals(atp.left) && right.equals(atp.right);
  103. }
  104. /* (non-Javadoc)
  105. * @see java.lang.Object#hashCode()
  106. */
  107. public int hashCode() {
  108. int ret = 17;
  109. ret = ret + 37 * left.hashCode();
  110. ret = ret + 37 * right.hashCode();
  111. return ret;
  112. }
  113. }