Package java.util.regex

Examples of java.util.regex.PatternSyntaxException


    /**
     * @tests serialization/deserialization compatibility.
     */
    public void testSerializationSelf() throws Exception {
        PatternSyntaxException object = new PatternSyntaxException("TESTDESC",
                "TESTREGEX", 3);
        SerializationTest.verifySelf(object, PATTERNSYNTAXEXCEPTION_COMPARATOR);
    }
View Full Code Here


    /**
     * @tests serialization/deserialization compatibility with RI.
     */
    public void testSerializationCompatibility() throws Exception {
        PatternSyntaxException object = new PatternSyntaxException("TESTDESC",
                "TESTREGEX", 3);
        SerializationTest.verifyGolden(this, object,
                PATTERNSYNTAXEXCEPTION_COMPARATOR);
    }
View Full Code Here

  public boolean hasWildcard() {
    return hasWildcard;
  }

  private static void error(String message, String pattern, int pos) {
    throw new PatternSyntaxException(message, pattern, pos);
  }
View Full Code Here

        Pattern pattern = Pattern.compile( "(?s).*?([0-9]+\\.[0-9]+)(\\.([0-9]+))?.*" );

        Matcher matcher = pattern.matcher( output );
        if ( !matcher.matches() )
        {
            throw new PatternSyntaxException( "Unrecognized version of Javadoc: '" + output + "'", pattern.pattern(),
                                              pattern.toString().length() - 1 );
        }

        String version = matcher.group( 3 );
        if ( version == null )
View Full Code Here

        try {
          replaceText= interpretReplaceEscapes(replaceText, prevMatch);
          Matcher replaceTextMatcher= pattern.matcher(prevMatch);
          replaceText= replaceTextMatcher.replaceFirst(replaceText);
        } catch (IndexOutOfBoundsException ex) {
          throw new PatternSyntaxException(ex.getLocalizedMessage(), replaceText, -1);
        }
      }

      int offset= fFindReplaceMatcher.start();
      int length= fFindReplaceMatcher.group().length();

      if (fDocument instanceof IRepairableDocumentExtension
          && ((IRepairableDocumentExtension)fDocument).isLineInformationRepairNeeded(offset, length, replaceText)) {
        String message= TextMessages.getString("FindReplaceDocumentAdapter.incompatibleLineDelimiter"); //$NON-NLS-1$
        throw new PatternSyntaxException(message, replaceText, offset);
      }

      fDocument.replace(offset, length, replaceText);

      if (operationCode == REPLACE) {
        return new Region(offset, replaceText.length());
      }
    }

    if (operationCode != REPLACE) {
      try {
        if (forwardSearch) {

          boolean found= false;
          if (operationCode == FIND_FIRST)
            found= fFindReplaceMatcher.find(startOffset);
          else
            found= fFindReplaceMatcher.find();

          if (operationCode == REPLACE_FIND_NEXT)
            fFindReplaceState= FIND_NEXT;

          if (found && fFindReplaceMatcher.group().length() > 0)
            return new Region(fFindReplaceMatcher.start(), fFindReplaceMatcher.group().length());
          return null;
        }
        // backward search
        boolean found= fFindReplaceMatcher.find(0);
        int index= -1;
        int length= -1;
        while (found && fFindReplaceMatcher.start() + fFindReplaceMatcher.group().length() <= fFindReplaceMatchOffset + 1) {
          index= fFindReplaceMatcher.start();
          length= fFindReplaceMatcher.group().length();
          found= fFindReplaceMatcher.find(index + 1);
        }
        fFindReplaceMatchOffset= index;
        if (index > -1) {
          // must set matcher to correct position
          fFindReplaceMatcher.find(index);
          return new Region(index, length);
        }
        return null;
      } catch (StackOverflowError e) {
        String message= TextMessages.getString("FindReplaceDocumentAdapter.patternTooComplex"); //$NON-NLS-1$
        throw new PatternSyntaxException(message, findString, -1);
      }
    }

    return null;
  }
View Full Code Here

              i++;

            } else if (ch1 == 'R') {
              if (inCharGroup > 0 || inBraces > 0) {
                String msg= TextMessages.getString("FindReplaceDocumentAdapter.illegalLinebreak"); //$NON-NLS-1$
                throw new PatternSyntaxException(msg, findString, i);
              }
              buf.append("(?>\\r\\n?|\\n)"); //$NON-NLS-1$
              i++;

            } else {
View Full Code Here

          char ch1= replaceText.charAt(i + 1);
          interpretRetainCase(buf, (char)(ch1 ^ 64));
          i++;
        } else {
          String msg= TextMessages.getFormattedString("FindReplaceDocumentAdapter.illegalControlEscape", "\\c"); //$NON-NLS-1$ //$NON-NLS-2$
          throw new PatternSyntaxException(msg, replaceText, i);
        }
        break;

      case 'x':
        if (i + 2 < length) {
          int parsedInt;
          try {
            parsedInt= Integer.parseInt(replaceText.substring(i + 1, i + 3), 16);
            if (parsedInt < 0)
              throw new NumberFormatException();
          } catch (NumberFormatException e) {
            String msg= TextMessages.getFormattedString("FindReplaceDocumentAdapter.illegalHexEscape", replaceText.substring(i - 1, i + 3)); //$NON-NLS-1$
            throw new PatternSyntaxException(msg, replaceText, i);
          }
          interpretRetainCase(buf, (char) parsedInt);
          i+= 2;
        } else {
          String msg= TextMessages.getFormattedString("FindReplaceDocumentAdapter.illegalHexEscape", replaceText.substring(i - 1, length)); //$NON-NLS-1$
          throw new PatternSyntaxException(msg, replaceText, i);
        }
        break;

      case 'u':
        if (i + 4 < length) {
          int parsedInt;
          try {
            parsedInt= Integer.parseInt(replaceText.substring(i + 1, i + 5), 16);
            if (parsedInt < 0)
              throw new NumberFormatException();
          } catch (NumberFormatException e) {
            String msg= TextMessages.getFormattedString("FindReplaceDocumentAdapter.illegalUnicodeEscape", replaceText.substring(i - 1, i + 5)); //$NON-NLS-1$
            throw new PatternSyntaxException(msg, replaceText, i);
          }
          interpretRetainCase(buf, (char) parsedInt);
          i+= 4;
        } else {
          String msg= TextMessages.getFormattedString("FindReplaceDocumentAdapter.illegalUnicodeEscape", replaceText.substring(i - 1, length)); //$NON-NLS-1$
          throw new PatternSyntaxException(msg, replaceText, i);
        }
        break;

      case 'C':
        if(foundText.toUpperCase().equals(foundText)) // is whole match upper-case?
View Full Code Here

            int index = indexOf(m.group(INDEX_GROUP_NAME));
            if (index >= 0) {
                index++;
            } else {
                throw new PatternSyntaxException("unknown group name", input.toString(), m.start(INDEX_GROUP_NAME));
            }

            // since we're replacing the original string being matched,
            // we have to reset the matcher so that it searches the new
            // string
View Full Code Here

  public boolean hasWildcard() {
    return hasWildcard;
  }

  private static void error(String message, String pattern, int pos) {
    throw new PatternSyntaxException(message, pattern, pos);
  }
View Full Code Here

  public boolean hasWildcard() {
    return hasWildcard;
  }

  private static void error(String message, String pattern, int pos) {
    throw new PatternSyntaxException(message, pattern, pos);
  }
View Full Code Here

TOP

Related Classes of java.util.regex.PatternSyntaxException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.