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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.util.FuzzyBoolean;
  15. import org.aspectj.weaver.*;
  16. import org.aspectj.weaver.ResolvedTypeX;
  17. /**
  18. * left && right
  19. *
  20. * <p>any binding to formals is explicitly forbidden for any composite by the language
  21. *
  22. * @author Erik Hilsdale
  23. * @author Jim Hugunin
  24. */
  25. public class AndTypePattern extends TypePattern {
  26. private TypePattern left, right;
  27. public AndTypePattern(TypePattern left, TypePattern right) {
  28. super(false); //??? we override all methods that care about includeSubtypes
  29. this.left = left;
  30. this.right = right;
  31. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  32. }
  33. public FuzzyBoolean matchesInstanceof(ResolvedTypeX type) {
  34. return left.matchesInstanceof(type).and(right.matchesInstanceof(type));
  35. }
  36. protected boolean matchesExactly(ResolvedTypeX type) {
  37. //??? if these had side-effects, this sort-circuit could be a mistake
  38. return left.matchesExactly(type) && right.matchesExactly(type);
  39. }
  40. public boolean matchesStatically(ResolvedTypeX type) {
  41. return left.matchesStatically(type) && right.matchesStatically(type);
  42. }
  43. public void write(DataOutputStream s) throws IOException {
  44. s.writeByte(TypePattern.AND);
  45. left.write(s);
  46. right.write(s);
  47. writeLocation(s);
  48. }
  49. public static TypePattern read(DataInputStream s, ISourceContext context) throws IOException {
  50. TypePattern ret = new AndTypePattern(TypePattern.read(s, context), TypePattern.read(s, context));
  51. ret.readLocation(context, s);
  52. return ret;
  53. }
  54. public TypePattern resolveBindings(
  55. IScope scope,
  56. Bindings bindings,
  57. boolean allowBinding, boolean requireExactType)
  58. {
  59. if (requireExactType) return notExactType(scope);
  60. left = left.resolveBindings(scope, bindings, false, false);
  61. right = right.resolveBindings(scope, bindings, false, false);
  62. return this;
  63. }
  64. public String toString() {
  65. return "(" + left.toString() + " && " + right.toString() + ")";
  66. }
  67. }