PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/gnu/regexp/REException.java

#
Java | 164 lines | 39 code | 23 blank | 102 comment | 0 complexity | ac0e3b8cf0f97c688f8adc895275cd47 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * gnu/regexp/REException.java
  3. * Copyright (C) 1998-2001 Wes Biggs
  4. *
  5. * This library is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published
  7. * by the Free Software Foundation; either version 2.1 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. package gnu.regexp;
  20. import java.text.MessageFormat;
  21. /**
  22. * This is the regular expression exception class. An exception of this type
  23. * defines the three attributes:
  24. * <OL>
  25. * <LI> A descriptive message of the error.
  26. * <LI> An integral type code equivalent to one of the statically
  27. * defined symbols listed below.
  28. * <LI> The approximate position in the input string where the error
  29. * occurred.
  30. * </OL>
  31. *
  32. * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
  33. */
  34. public class REException extends Exception {
  35. private int type;
  36. private int pos;
  37. // Error conditions from GNU regcomp(3) manual
  38. /**
  39. * Error flag.
  40. * Invalid use of repetition operators such as using
  41. * `*' as the first character.
  42. */
  43. public static final int REG_BADRPT = 1;
  44. /**
  45. * Error flag.
  46. * Invalid use of back reference operator.
  47. */
  48. public static final int REG_BADBR = 2;
  49. /**
  50. * Error flag.
  51. * Un-matched brace interval operators.
  52. */
  53. public static final int REG_EBRACE = 3;
  54. /**
  55. * Error flag.
  56. * Un-matched bracket list operators.
  57. */
  58. public static final int REG_EBRACK = 4;
  59. /**
  60. * Error flag.
  61. * Invalid use of the range operator, eg. the ending
  62. * point of the range occurs prior to the starting
  63. * point.
  64. */
  65. public static final int REG_ERANGE = 5;
  66. /**
  67. * Error flag.
  68. * Unknown character class name. <B>Not implemented</B>.
  69. */
  70. public static final int REG_ECTYPE = 6;
  71. /**
  72. * Error flag.
  73. * Un-matched parenthesis group operators.
  74. */
  75. public static final int REG_EPAREN = 7;
  76. /**
  77. * Error flag.
  78. * Invalid back reference to a subexpression.
  79. */
  80. public static final int REG_ESUBREG = 8;
  81. /**
  82. * Error flag.
  83. * Non specific error. <B>Not implemented</B>.
  84. */
  85. public static final int REG_EEND = 9;
  86. /**
  87. * Error flag.
  88. * Invalid escape sequence. <B>Not implemented</B>.
  89. */
  90. public static final int REG_ESCAPE = 10;
  91. /**
  92. * Error flag.
  93. * Invalid use of pattern operators such as group or list.
  94. */
  95. public static final int REG_BADPAT = 11;
  96. /**
  97. * Error flag.
  98. * Compiled regular expression requires a pattern
  99. * buffer larger than 64Kb. <B>Not implemented</B>.
  100. */
  101. public static final int REG_ESIZE = 12;
  102. /**
  103. * Error flag.
  104. * The regex routines ran out of memory. <B>Not implemented</B>.
  105. */
  106. public static final int REG_ESPACE = 13;
  107. REException(String msg, int type, int position) {
  108. super(msg);
  109. this.type = type;
  110. this.pos = position;
  111. }
  112. /**
  113. * Returns the type of the exception, one of the constants listed above.
  114. */
  115. public int getType() {
  116. return type;
  117. }
  118. /**
  119. * Returns the position, relative to the string or character array being
  120. * compiled, where the error occurred. This position is generally the point
  121. * where the error was detected, not necessarily the starting index of
  122. * a bad subexpression.
  123. */
  124. public int getPosition() {
  125. return pos;
  126. }
  127. /**
  128. * Reports the descriptive message associated with this exception
  129. * as well as its index position in the string or character array
  130. * being compiled.
  131. */
  132. public String getMessage() {
  133. Object[] args = {new Integer(pos)};
  134. StringBuffer sb = new StringBuffer();
  135. String prefix = RE.getLocalizedMessage("error.prefix");
  136. sb.append(MessageFormat.format(prefix, args));
  137. sb.append('\n');
  138. sb.append(super.getMessage());
  139. return sb.toString();
  140. }
  141. }