Java Code Examples for java.util.regex.PatternSyntaxException#getLocalizedMessage()

The following examples show how to use java.util.regex.PatternSyntaxException#getLocalizedMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplaceConfigurationPage.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
final void updateOKStatus() {
    RefactoringStatus status = new RefactoringStatus();
    if (fReplaceWithRegex != null && fReplaceWithRegex.getSelection()) {
        try {
            PatternConstructor.interpretReplaceEscapes(fReplaceWithRegex.getText(), fReplaceRefactoring.getQuery()
                    .getSearchString(), "\n"); //$NON-NLS-1$
        } catch (PatternSyntaxException e) {
            String locMessage = e.getLocalizedMessage();
            int i = 0;
            while (i < locMessage.length() && "\n\r".indexOf(locMessage.charAt(i)) == -1) { //$NON-NLS-1$
                i++;
            }
            status.addError(locMessage.substring(0, i)); // only take first line
        }
    }
    setPageComplete(status);
}
 
Example 2
Source File: GoSearchPage.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
private boolean validateRegex() {
  if (fIsRegExCheckbox.getSelection()) {
    try {
      PatternConstructor.createPattern(fPattern.getText(), fIsCaseSensitive, true);
    } catch (PatternSyntaxException e) {
      String locMessage = e.getLocalizedMessage();
      int i = 0;
      while (i < locMessage.length() && "\n\r".indexOf(locMessage.charAt(i)) == -1) { //$NON-NLS-1$
        i++;
      }
      statusMessage(true, locMessage.substring(0, i)); // only take first line
      return false;
    }
    statusMessage(false, ""); //$NON-NLS-1$
  } else {
    statusMessage(false, "(* = any string, ? = any character, \\ = escape for literals: * ? \\)");
  }
  return true;
}
 
Example 3
Source File: IgnoredFilesPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Returns true if ignored files pattern is valid, false otherwise and
 * syntax error message can be obtained by getSyntaxError method.
 * @param ignoredFiles ignored files pattern
 * @return true if ignored files pattern is valid, false otherwise.
 */
static boolean isValid(String ignoredFiles) {
    try {
        Pattern.compile(ignoredFiles);
    } catch (PatternSyntaxException e) {
        syntaxError = e.getLocalizedMessage();
        return false;
    }
    syntaxError = null;
    return true;
}