rule.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. var RuleFailurePosition = (function () {
  3. function RuleFailurePosition(position, lineAndCharacter) {
  4. this.position = position;
  5. this.lineAndCharacter = lineAndCharacter;
  6. }
  7. RuleFailurePosition.prototype.getPosition = function () {
  8. return this.position;
  9. };
  10. RuleFailurePosition.prototype.getLineAndCharacter = function () {
  11. return this.lineAndCharacter;
  12. };
  13. RuleFailurePosition.prototype.toJson = function () {
  14. return {
  15. character: this.lineAndCharacter.character,
  16. line: this.lineAndCharacter.line,
  17. position: this.position
  18. };
  19. };
  20. RuleFailurePosition.prototype.equals = function (ruleFailurePosition) {
  21. var ll = this.lineAndCharacter;
  22. var rr = ruleFailurePosition.lineAndCharacter;
  23. return this.position === ruleFailurePosition.position
  24. && ll.line === rr.line
  25. && ll.character === rr.character;
  26. };
  27. return RuleFailurePosition;
  28. }());
  29. exports.RuleFailurePosition = RuleFailurePosition;
  30. var RuleFailure = (function () {
  31. function RuleFailure(sourceFile, start, end, failure, ruleName) {
  32. this.sourceFile = sourceFile;
  33. this.fileName = sourceFile.fileName;
  34. this.startPosition = this.createFailurePosition(start);
  35. this.endPosition = this.createFailurePosition(end);
  36. this.failure = failure;
  37. this.ruleName = ruleName;
  38. }
  39. RuleFailure.prototype.getFileName = function () {
  40. return this.fileName;
  41. };
  42. RuleFailure.prototype.getRuleName = function () {
  43. return this.ruleName;
  44. };
  45. RuleFailure.prototype.getStartPosition = function () {
  46. return this.startPosition;
  47. };
  48. RuleFailure.prototype.getEndPosition = function () {
  49. return this.endPosition;
  50. };
  51. RuleFailure.prototype.getFailure = function () {
  52. return this.failure;
  53. };
  54. RuleFailure.prototype.toJson = function () {
  55. return {
  56. endPosition: this.endPosition.toJson(),
  57. failure: this.failure,
  58. name: this.fileName,
  59. ruleName: this.ruleName,
  60. startPosition: this.startPosition.toJson()
  61. };
  62. };
  63. RuleFailure.prototype.equals = function (ruleFailure) {
  64. return this.failure === ruleFailure.getFailure()
  65. && this.fileName === ruleFailure.getFileName()
  66. && this.startPosition.equals(ruleFailure.getStartPosition())
  67. && this.endPosition.equals(ruleFailure.getEndPosition());
  68. };
  69. RuleFailure.prototype.createFailurePosition = function (position) {
  70. var lineAndCharacter = this.sourceFile.getLineAndCharacterOfPosition(position);
  71. return new RuleFailurePosition(position, lineAndCharacter);
  72. };
  73. return RuleFailure;
  74. }());
  75. exports.RuleFailure = RuleFailure;