Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.DataOutputStream;
  14. import java.io.IOException;
  15. import org.aspectj.util.FuzzyBoolean;
  16. import org.aspectj.weaver.ISourceContext;
  17. import org.aspectj.weaver.ResolvedTypeX;
  18. import org.aspectj.weaver.VersionedDataInputStream;
  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. /* (non-Javadoc)
  36. * @see org.aspectj.weaver.patterns.TypePattern#couldEverMatchSameTypesAs(org.aspectj.weaver.patterns.TypePattern)
  37. */
  38. protected boolean couldEverMatchSameTypesAs(TypePattern other) {
  39. return true;
  40. }
  41. public FuzzyBoolean matchesInstanceof(ResolvedTypeX type) {
  42. return pattern.matchesInstanceof(type).not();
  43. }
  44. protected boolean matchesExactly(ResolvedTypeX type) {
  45. return !pattern.matchesExactly(type);
  46. }
  47. public boolean matchesStatically(Class type) {
  48. return !pattern.matchesStatically(type);
  49. }
  50. public FuzzyBoolean matchesInstanceof(Class type) {
  51. return pattern.matchesInstanceof(type).not();
  52. }
  53. protected boolean matchesExactly(Class type) {
  54. return !pattern.matchesExactly(type);
  55. }
  56. public boolean matchesStatically(ResolvedTypeX type) {
  57. return !pattern.matchesStatically(type);
  58. }
  59. public void write(DataOutputStream s) throws IOException {
  60. s.writeByte(TypePattern.NOT);
  61. pattern.write(s);
  62. writeLocation(s);
  63. }
  64. public static TypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  65. TypePattern ret = new NotTypePattern(TypePattern.read(s, context));
  66. ret.readLocation(context, s);
  67. return ret;
  68. }
  69. public TypePattern resolveBindings(
  70. IScope scope,
  71. Bindings bindings,
  72. boolean allowBinding, boolean requireExactType)
  73. {
  74. if (requireExactType) return notExactType(scope);
  75. pattern = pattern.resolveBindings(scope, bindings, false, false);
  76. return this;
  77. }
  78. public TypePattern resolveBindingsFromRTTI(boolean allowBinding, boolean requireExactType) {
  79. if (requireExactType) return TypePattern.NO;
  80. pattern = pattern.resolveBindingsFromRTTI(allowBinding,requireExactType);
  81. return this;
  82. }
  83. public String toString() {
  84. StringBuffer buff = new StringBuffer();
  85. if (annotationPattern != AnnotationTypePattern.ANY) {
  86. buff.append('(');
  87. buff.append(annotationPattern.toString());
  88. buff.append(' ');
  89. }
  90. buff.append('!');
  91. buff.append(pattern);
  92. if (annotationPattern != AnnotationTypePattern.ANY) {
  93. buff.append(')');
  94. }
  95. return buff.toString();
  96. }
  97. /* (non-Javadoc)
  98. * @see java.lang.Object#equals(java.lang.Object)
  99. */
  100. public boolean equals(Object obj) {
  101. if (! (obj instanceof NotTypePattern)) return false;
  102. return (pattern.equals(((NotTypePattern)obj).pattern));
  103. }
  104. /* (non-Javadoc)
  105. * @see java.lang.Object#hashCode()
  106. */
  107. public int hashCode() {
  108. return 17 + 37 * pattern.hashCode();
  109. }
  110. }