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.

NotSignaturePattern.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement - SpringSource
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import java.util.List;
  15. import java.util.Map;
  16. import org.aspectj.weaver.ISourceContext;
  17. import org.aspectj.weaver.Member;
  18. import org.aspectj.weaver.ResolvedType;
  19. import org.aspectj.weaver.UnresolvedType;
  20. import org.aspectj.weaver.VersionedDataInputStream;
  21. import org.aspectj.weaver.World;
  22. /**
  23. * Represents the NOT of a signature pattern
  24. *
  25. * @author Andy Clement
  26. * @since 1.6.9
  27. */
  28. public class NotSignaturePattern extends AbstractSignaturePattern {
  29. private ISignaturePattern negatedSp;
  30. public NotSignaturePattern(ISignaturePattern negatedSp) {
  31. this.negatedSp = negatedSp;
  32. }
  33. public boolean couldEverMatch(ResolvedType type) {
  34. if (negatedSp.getExactDeclaringTypes().size() == 0) {
  35. return true;
  36. }
  37. return !negatedSp.couldEverMatch(type);
  38. }
  39. public List<ExactTypePattern> getExactDeclaringTypes() {
  40. return negatedSp.getExactDeclaringTypes();
  41. }
  42. public boolean isMatchOnAnyName() {
  43. return negatedSp.isMatchOnAnyName();
  44. }
  45. public boolean isStarAnnotation() {
  46. return negatedSp.isStarAnnotation();
  47. }
  48. public boolean matches(Member member, World world, boolean b) {
  49. return !negatedSp.matches(member, world, b);
  50. }
  51. public ISignaturePattern parameterizeWith(Map<String, UnresolvedType> typeVariableBindingMap, World world) {
  52. return new NotSignaturePattern(negatedSp.parameterizeWith(typeVariableBindingMap, world));
  53. }
  54. public ISignaturePattern resolveBindings(IScope scope, Bindings bindings) {
  55. // Whilst the real SignaturePattern returns 'this' we are safe to return 'this' here rather than build a new
  56. // AndSignaturePattern
  57. negatedSp.resolveBindings(scope, bindings);
  58. return this;
  59. }
  60. public static ISignaturePattern readNotSignaturePattern(VersionedDataInputStream s, ISourceContext context) throws IOException {
  61. NotSignaturePattern ret = new NotSignaturePattern(readCompoundSignaturePattern(s, context));
  62. // ret.readLocation(context, s); // TODO output position currently useless so dont need to do this
  63. s.readInt();
  64. s.readInt();
  65. return ret;
  66. }
  67. public ISignaturePattern getNegated() {
  68. return negatedSp;
  69. }
  70. public String toString() {
  71. StringBuilder sb = new StringBuilder();
  72. sb.append("!").append(negatedSp.toString());
  73. return sb.toString();
  74. }
  75. }