/** * Detect ignore situation. * @param startLine position of line * @param text file text * @param start line column * @return true is that need to be ignored */ private boolean isIgnore(int startLine, FileText text, LineColumn start) { final LineColumn end; if (matcher.end() == 0) { end = text.lineColumn(0); } else { end = text.lineColumn(matcher.end() - 1); } boolean ignore = false; if (ignoreComments) { final FileContents theFileContents = getFileContents(); final int startColumn = start.getColumn(); final int endLine = end.getLine(); final int endColumn = end.getColumn(); ignore = theFileContents.hasIntersectionWithComment(startLine, startColumn, endLine, endColumn); } return ignore; }
@Test public void testLineColumnBeforeCopyConstructor() throws IOException { final String charsetName = StandardCharsets.ISO_8859_1.name(); final FileText fileText = new FileText(new File(getPath("InputFileTextImportControl.xml")), charsetName); final LineColumn lineColumn = fileText.lineColumn(100); final FileText copy = new FileText(fileText); assertEquals("Invalid linecolumn", lineColumn, copy.lineColumn(100)); }
/** Method that finds the matches. */ private void findMatch() { try { boolean foundMatch = matcher.find(); while (foundMatch) { currentMatches++; if (currentMatches > options.getMaximum()) { final LineColumn start = text.lineColumn(matcher.start()); if (options.getMessage().isEmpty()) { options.getReporter().log(start.getLine(), MSG_REGEXP_EXCEEDED, matcher.pattern().toString()); } else { options.getReporter() .log(start.getLine(), options.getMessage()); } } foundMatch = matcher.find(); } } // see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6337993 et al. catch (StackOverflowError ignored) { // OK http://blog.igorminar.com/2008/05/catching-stackoverflowerror-and-bug-in.html // http://programmers.stackexchange.com/questions/ // 209099/is-it-ever-okay-to-catch-stackoverflowerror-in-java options.getReporter().log(1, MSG_STACKOVERFLOW, matcher.pattern().toString()); } }
/** Recursive method that finds the matches. */ private void findMatch() { final boolean foundMatch = matcher.find(); if (foundMatch) { final FileText text = getFileContents().getText(); final LineColumn start = text.lineColumn(matcher.start()); final int startLine = start.getLine(); final boolean ignore = isIgnore(startLine, text, start); if (!ignore) { matchCount++; if (illegalPattern || checkForDuplicates && matchCount - 1 > duplicateLimit) { errorCount++; logMessage(startLine); } } if (canContinueValidation(ignore)) { findMatch(); } } else if (!illegalPattern && matchCount == 0) { logMessage(0); } }
@Test public void testLineColumnAfterCopyConstructor() throws IOException { final String charsetName = StandardCharsets.ISO_8859_1.name(); final FileText fileText = new FileText(new File(getPath("InputFileTextImportControl.xml")), charsetName); final FileText copy = new FileText(fileText); final LineColumn lineColumn = copy.lineColumn(100); assertEquals("Invalid line", 3, lineColumn.getLine()); if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows")) { assertEquals("Invalid column", 44, lineColumn.getColumn()); } else { assertEquals("Invalid column", 46, lineColumn.getColumn()); } }
@Test public void testLineColumnAtTheStartOfFile() throws IOException { final String charsetName = StandardCharsets.ISO_8859_1.name(); final FileText fileText = new FileText(new File(getPath("InputFileTextImportControl.xml")), charsetName); final FileText copy = new FileText(fileText); final LineColumn lineColumn = copy.lineColumn(0); assertEquals("Invalid line", 1, lineColumn.getLine()); assertEquals("Invalid column", 0, lineColumn.getColumn()); }
/** * Detect ignore situation. * @param startLine position of line * @param text file text * @param start line column * @return true is that need to be ignored */ private boolean isIgnore(int startLine, FileText text, LineColumn start) { final LineColumn end; if (matcher.end() == 0) { end = text.lineColumn(0); } else { end = text.lineColumn(matcher.end() - 1); } boolean ignore = false; if (ignoreComments) { final FileContents theFileContents = getFileContents(); final int startColumn = start.getColumn(); final int endLine = end.getLine(); final int endColumn = end.getColumn(); ignore = theFileContents.hasIntersectionWithComment(startLine, startColumn, endLine, endColumn); } return ignore; }
/** Method that finds the matches. */ private void findMatch() { try { boolean foundMatch = matcher.find(); while (foundMatch) { currentMatches++; if (currentMatches > options.getMaximum()) { final LineColumn start = text.lineColumn(matcher.start()); if (options.getMessage().isEmpty()) { options.getReporter().log(start.getLine(), MSG_REGEXP_EXCEEDED, matcher.pattern().toString()); } else { options.getReporter() .log(start.getLine(), options.getMessage()); } } foundMatch = matcher.find(); } } // see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6337993 et al. catch (StackOverflowError ignored) { // OK http://blog.igorminar.com/2008/05/catching-stackoverflowerror-and-bug-in.html // http://programmers.stackexchange.com/questions/ // 209099/is-it-ever-okay-to-catch-stackoverflowerror-in-java options.getReporter().log(1, MSG_STACKOVERFLOW, matcher.pattern().toString()); } }
/** Recursive method that finds the matches. */ private void findMatch() { final boolean foundMatch = matcher.find(); if (foundMatch) { final FileText text = getFileContents().getText(); final LineColumn start = text.lineColumn(matcher.start()); final int startLine = start.getLine(); final boolean ignore = isIgnore(startLine, text, start); if (!ignore) { matchCount++; if (illegalPattern || checkForDuplicates && matchCount - 1 > duplicateLimit) { errorCount++; logMessage(startLine); } } if (canContinueValidation(ignore)) { findMatch(); } } else if (!illegalPattern && matchCount == 0) { logMessage(0); } }