NotMatchExpression.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. "use strict";
  2. var MatchExpression = require('./MatchExpression');
  3. var NotMatchExpression = module.exports = function NotMatchExpression(){
  4. base.call(this);
  5. this._matchType = 'NOT';
  6. }, klass = NotMatchExpression, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  7. proto._exp = undefined;
  8. /**
  9. *
  10. * Writes a debug string for this object
  11. * @method debugString
  12. * @param level
  13. *
  14. */
  15. proto.debugString = function debugString(level) {
  16. return this._debugAddSpace( level ) + "$not\n" + this._exp._debugString( level + 1 );
  17. };
  18. /**
  19. *
  20. * checks if this expression is == to the other
  21. * @method equivalent
  22. * @param other
  23. *
  24. */
  25. proto.equivalent = function equivalent(other) {
  26. return other._matchType == 'NOT' && this._exp.equivalent(other.getChild(0));
  27. };
  28. /**
  29. *
  30. * Return the reset child
  31. * @method resetChild
  32. *
  33. */
  34. proto.resetChild = function resetChild(newChild) {
  35. this._exp.reset(newChild);
  36. };
  37. /**
  38. *
  39. * Initialize the necessary items
  40. * @method init
  41. * @param exp
  42. *
  43. */
  44. proto.init = function init(exp) {
  45. this._exp = exp;
  46. return {'code':'OK'};
  47. };
  48. /**
  49. *
  50. * matches checks the input doc against the internal element path to see if it is a match
  51. * @method matches
  52. * @param doc
  53. * @param details
  54. *
  55. */
  56. proto.matches = function matches(doc, details) {
  57. return ! this._exp.matches(doc, null);
  58. };
  59. /**
  60. *
  61. * Check if the input element matches
  62. * @method matchesSingleElement
  63. * @param e
  64. *
  65. */
  66. proto.matchesSingleElement = function matchesSingleElement(e) {
  67. return ! this._exp.matchesSingleElement( e );
  68. };
  69. /**
  70. *
  71. * Return the number of children contained by this expression
  72. * @method numChildren
  73. * @param
  74. *
  75. */
  76. proto.numChildren = function numChildren(){
  77. return 1;
  78. };
  79. /**
  80. *
  81. * clone this instance to a new one
  82. * @method shallowClone
  83. *
  84. */
  85. proto.shallowClone = function shallowClone(){
  86. // File: expression_tree.h lines: 128-132
  87. var e = new NotMatchExpression();
  88. e.init(this._exp.shallowClone());
  89. if ( this.getTag() ) {
  90. e.setTag(this.getTag().clone());
  91. }
  92. return e;
  93. };