/** * Get the line from text of the file. * @param index index of the line * @return line from text of the file */ public String getLine(int index) { return text.get(index); }
/** * Get a single line. * For internal use only, as getText().get(lineNo) is just as * suitable for external use and avoids method duplication. * @param lineNo the number of the line to get * @return the corresponding line, without terminator * @throws IndexOutOfBoundsException if lineNo is invalid */ private String line(int lineNo) { return text.get(lineNo); }
/** * Tries to extract the suppression from the given line. * @param fileText {@link FileText} instance. * @param lineNo line number. * @return {@link Optional} of {@link Suppression}. */ private Optional<Suppression> getSuppression(FileText fileText, int lineNo) { final String line = fileText.get(lineNo); final Matcher onCommentMatcher = onCommentFormat.matcher(line); final Matcher offCommentMatcher = offCommentFormat.matcher(line); Suppression suppression = null; if (onCommentMatcher.find()) { suppression = new Suppression(onCommentMatcher.group(0), lineNo + 1, onCommentMatcher.start(), SuppressionType.ON, this); } if (offCommentMatcher.find()) { suppression = new Suppression(offCommentMatcher.group(0), lineNo + 1, offCommentMatcher.start(), SuppressionType.OFF, this); } return Optional.ofNullable(suppression); }
/** * Returns the column number with tabs expanded. * @param ast {@code DetailAST} root ast * @return the column number with tabs expanded */ private int expandedTabColumn(DetailAST ast) { return 1 + CommonUtil.lengthExpandedTabs(fileText.get(lineNumber - 1), ast.getColumnNo(), tabWidth); }
/** * Method returns line number the key is detected in the checked properties * files first. * * @param fileText * {@link FileText} object contains the lines to process * @param keyName * key name to look for * @return line number of first occurrence. If no key found in properties * file, 1 is returned */ private static int getLineNumber(FileText fileText, String keyName) { final Pattern keyPattern = getKeyPattern(keyName); int lineNumber = 1; final Matcher matcher = keyPattern.matcher(""); for (int index = 0; index < fileText.size(); index++) { final String line = fileText.get(index); matcher.reset(line); if (matcher.matches()) { break; } ++lineNumber; } // -1 as check seeks for the first duplicate occurrence in file, // so it cannot be the last line. if (lineNumber > fileText.size() - 1) { lineNumber = 1; } return lineNumber; }
@Override protected void processFiltered(File file, FileText fileText) { int lineNum = 0; for (int index = 0; index < fileText.size(); index++) { final String line = fileText.get(index); lineNum++; final int tabPosition = line.indexOf('\t'); if (tabPosition != -1) { if (eachLine) { log(lineNum, tabPosition + 1, MSG_CONTAINS_TAB); } else { log(lineNum, tabPosition + 1, MSG_FILE_CONTAINS_TAB); break; } } } }
@Override protected void processFiltered(File file, FileText fileText) { if (getHeaderLines().size() > fileText.size()) { log(1, MSG_MISSING); } else { for (int i = 0; i < getHeaderLines().size(); i++) { if (!isMatch(i, fileText.get(i))) { log(i + 1, MSG_MISMATCH, getHeaderLines().get(i)); break; } } } }
/** * Processes a set of lines looking for matches. * @param fileText {@link FileText} object contains the lines to process. */ public void processLines(FileText fileText) { resetState(); int lineNo = 0; for (int index = 0; index < fileText.size(); index++) { final String line = fileText.get(index); lineNo++; checkLine(lineNo, line, options.getPattern().matcher(line), 0); } finish(); }
int index; for (index = 0; headerLineNo < headerSize && index < fileSize; index++) { final String line = fileText.get(index); boolean isMatch = isMatch(line, headerLineNo); while (!isMatch && isMultiLine(headerLineNo)) {
/** * Get a single line. * For internal use only, as getText().get(lineNo) is just as * suitable for external use and avoids method duplication. * @param lineNo the number of the line to get * @return the corresponding line, without terminator * @throws IndexOutOfBoundsException if lineNo is invalid */ private String line(int lineNo) { return text.get(lineNo); }
/** * Get the line from text of the file. * @param index index of the line * @return line from text of the file */ public String getLine(int index) { return text.get(index); }
/** * Tries to extract the suppression from the given line. * @param fileText {@link FileText} instance. * @param lineNo line number. * @return {@link Optional} of {@link Suppression}. */ private Optional<Suppression> getSuppression(FileText fileText, int lineNo) { final String line = fileText.get(lineNo); final Matcher onCommentMatcher = onCommentFormat.matcher(line); final Matcher offCommentMatcher = offCommentFormat.matcher(line); Suppression suppression = null; if (onCommentMatcher.find()) { suppression = new Suppression(onCommentMatcher.group(0), lineNo + 1, onCommentMatcher.start(), SuppressionType.ON, this); } if (offCommentMatcher.find()) { suppression = new Suppression(offCommentMatcher.group(0), lineNo + 1, offCommentMatcher.start(), SuppressionType.OFF, this); } return Optional.ofNullable(suppression); }
@Override public boolean run(FileText fileText) { if (this.lines.size() > fileText.size()) { log(1, RegexpHeaderCheck.MSG_HEADER_MISSING); return false; } for (int i = 0; i < this.lines.size(); i++) { String fileLine = fileText.get(i); Pattern pattern = this.lines.get(i); if (!pattern.matcher(fileLine).matches()) { log(i + 1, RegexpHeaderCheck.MSG_HEADER_MISMATCH, pattern); return false; } } return true; }
/** * Returns the column number with tabs expanded. * @param ast {@code DetailAST} root ast * @return the column number with tabs expanded */ private int expandedTabColumn(DetailAST ast) { return 1 + CommonUtil.lengthExpandedTabs(fileText.get(lineNumber - 1), ast.getColumnNo(), tabWidth); }
@Override public boolean run(FileText fileText) { for (int i = 0; i < fileText.size(); i++) { String fileLine = fileText.get(i); if (fileLine.trim().isEmpty()) { continue; } if (isHeaderComment(fileLine)) { log(i, "header.unexpected"); return false; } return true; } return true; }
@Override public void processFiltered(final File file, final FileText lines) { int first = -1; int last = -1; for (int pos = 0; pos < lines.size(); pos += 1) { final String line = lines.get(pos); if (line.startsWith(ImportCohesionCheck.IMPORT)) { if (first == -1) { first = pos; } last = pos; } } if (first == -1) { return; } if (this.check(first, last, lines)) { this.fireErrors(file.getPath()); } }
@Override protected void processFiltered(File file, FileText fileText) { int lineNum = 0; for (int index = 0; index < fileText.size(); index++) { final String line = fileText.get(index); lineNum++; final int tabPosition = line.indexOf('\t'); if (tabPosition != -1) { if (eachLine) { log(lineNum, tabPosition + 1, MSG_CONTAINS_TAB); } else { log(lineNum, tabPosition + 1, MSG_FILE_CONTAINS_TAB); break; } } } }
@Override protected void processFiltered(File file, FileText fileText) { if (getHeaderLines().size() > fileText.size()) { log(1, MSG_MISSING); } else { for (int i = 0; i < getHeaderLines().size(); i++) { if (!isMatch(i, fileText.get(i))) { log(i + 1, MSG_MISMATCH, getHeaderLines().get(i)); break; } } } }
/** * Processes a set of lines looking for matches. * @param fileText {@link FileText} object contains the lines to process. */ public void processLines(FileText fileText) { resetState(); int lineNo = 0; for (int index = 0; index < fileText.size(); index++) { final String line = fileText.get(index); lineNo++; checkLine(lineNo, line, options.getPattern().matcher(line), 0); } finish(); }
/** * Checks if there's one ternary operator per line. * @param questionAST The token to examine. * @return true if ternary is isolated on line. */ private boolean isIsolatedTernaryOnLine(DetailAST questionAST) { final int lineNo = questionAST.getLineNo() - 1; final String line = getFileContents().getText().get(lineNo); return isSingleTernaryLine(line, lineNo); }