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.

OrSignaturePattern.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* *******************************************************************
  2. * Copyright (c) 2010 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Andy Clement - SpringSource
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import java.util.Map;
  17. import org.aspectj.weaver.ISourceContext;
  18. import org.aspectj.weaver.Member;
  19. import org.aspectj.weaver.ResolvedType;
  20. import org.aspectj.weaver.UnresolvedType;
  21. import org.aspectj.weaver.VersionedDataInputStream;
  22. import org.aspectj.weaver.World;
  23. /**
  24. * Represents the OR of two other signature patterns.
  25. *
  26. * @author Andy Clement
  27. * @since 1.6.9
  28. */
  29. public class OrSignaturePattern extends AbstractSignaturePattern {
  30. private ISignaturePattern leftSp;
  31. private ISignaturePattern rightSp;
  32. private List<ExactTypePattern> exactDeclaringTypes;
  33. public OrSignaturePattern(ISignaturePattern leftSp, ISignaturePattern rightSp) {
  34. this.leftSp = leftSp;
  35. this.rightSp = rightSp;
  36. }
  37. public boolean couldEverMatch(ResolvedType type) {
  38. return leftSp.couldEverMatch(type) || rightSp.couldEverMatch(type);
  39. }
  40. public List<ExactTypePattern> getExactDeclaringTypes() {
  41. if (exactDeclaringTypes == null) {
  42. exactDeclaringTypes = new ArrayList<>();
  43. exactDeclaringTypes.addAll(leftSp.getExactDeclaringTypes());
  44. exactDeclaringTypes.addAll(rightSp.getExactDeclaringTypes());
  45. }
  46. return exactDeclaringTypes;
  47. }
  48. public boolean isMatchOnAnyName() {
  49. return leftSp.isMatchOnAnyName() || rightSp.isMatchOnAnyName();
  50. }
  51. public boolean isStarAnnotation() {
  52. return leftSp.isStarAnnotation() || rightSp.isStarAnnotation();
  53. }
  54. public boolean matches(Member member, World world, boolean b) {
  55. return (leftSp.matches(member, world, b)) || (rightSp.matches(member, world, b));
  56. }
  57. public ISignaturePattern parameterizeWith(Map<String, UnresolvedType> typeVariableBindingMap, World world) {
  58. return new OrSignaturePattern(leftSp.parameterizeWith(typeVariableBindingMap, world), rightSp.parameterizeWith(
  59. typeVariableBindingMap, world));
  60. }
  61. public ISignaturePattern resolveBindings(IScope scope, Bindings bindings) {
  62. // Whilst the real SignaturePattern returns 'this' we are safe to return 'this' here rather than build a new
  63. // AndSignaturePattern
  64. leftSp.resolveBindings(scope, bindings);
  65. rightSp.resolveBindings(scope, bindings);
  66. return this;
  67. }
  68. public static ISignaturePattern readOrSignaturePattern(VersionedDataInputStream s, ISourceContext context) throws IOException {
  69. OrSignaturePattern ret = new OrSignaturePattern(readCompoundSignaturePattern(s, context), readCompoundSignaturePattern(s,
  70. context));
  71. s.readInt();
  72. s.readInt();
  73. // ret.readLocation(context, s); // TODO output position currently useless so dont need to do this
  74. return ret;
  75. }
  76. public ISignaturePattern getLeft() {
  77. return leftSp;
  78. }
  79. public ISignaturePattern getRight() {
  80. return rightSp;
  81. }
  82. public String toString() {
  83. StringBuilder sb = new StringBuilder();
  84. sb.append(leftSp.toString()).append(" || ").append(rightSp.toString());
  85. return sb.toString();
  86. }
  87. }