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.

NotTypePattern.java 3.4KB

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