/** * Returns the Javadoc comment before the specified line. * A return value of {@code null} means there is no such comment. * @param lineNoBefore the line number to check before * @return the Javadoc comment, or {@code null} if none **/ public TextBlock getJavadocBefore(int lineNoBefore) { // Lines start at 1 to the callers perspective, so need to take off 2 int lineNo = lineNoBefore - 2; // skip blank lines while (lineNo > 0 && (lineIsBlank(lineNo) || lineIsComment(lineNo))) { lineNo--; } return javadocComments.get(lineNo); }
/** * Returns length of code only without comments and blank lines. * @param openingBrace block opening brace * @param closingBrace block closing brace * @return number of lines with code for current block */ private int getLengthOfBlock(DetailAST openingBrace, DetailAST closingBrace) { int length = closingBrace.getLineNo() - openingBrace.getLineNo() + 1; if (!countEmpty) { final FileContents contents = getFileContents(); final int lastLine = closingBrace.getLineNo(); // lastLine - 1 is actual last line index. Last line is line with curly brace, // which is always not empty. So, we make it lastLine - 2 to cover last line that // actually may be empty. for (int i = openingBrace.getLineNo() - 1; i <= lastLine - 2; i++) { if (contents.lineIsBlank(i) || contents.lineIsComment(i)) { length--; } } } return length; }
/** * Returns the Javadoc comment before the specified line. * A return value of {@code null} means there is no such comment. * @param lineNoBefore the line number to check before * @return the Javadoc comment, or {@code null} if none **/ public TextBlock getJavadocBefore(int lineNoBefore) { // Lines start at 1 to the callers perspective, so need to take off 2 int lineNo = lineNoBefore - 2; // skip blank lines while (lineNo > 0 && (lineIsBlank(lineNo) || lineIsComment(lineNo))) { lineNo--; } return javadocComments.get(lineNo); }
/** * Determines the number semicolons in a method excluding those in * comments. * @param method Method to count * @return The number of semicolons in the method as an int */ private int countSemiColons(final DetailAST method) { final DetailAST openingbrace = method.findFirstToken(TokenTypes.SLIST); int count = 0; if (openingbrace != null) { final DetailAST closingbrace = openingbrace.findFirstToken(TokenTypes.RCURLY); final int lastline = closingbrace.getLineNo(); final int firstline = openingbrace.getLineNo(); final FileContents contents = this.getFileContents(); for (int line = firstline - 1; line < lastline; line += 1) { if (!contents.lineIsBlank(line) && !contents.lineIsComment(line) && contents.getLine(line).contains(";")) { count += 1; } } } return count; } }
/** * Determines the number semicolons in a method excluding those in * comments. * @param method Method to count * @return The number of semicolons in the method as an int */ private int countSemiColons(final DetailAST method) { final DetailAST openingbrace = method.findFirstToken(TokenTypes.SLIST); int count = 0; if (openingbrace != null) { final DetailAST closingbrace = openingbrace.findFirstToken(TokenTypes.RCURLY); final int lastline = closingbrace.getLineNo(); final int firstline = openingbrace.getLineNo(); final FileContents contents = this.getFileContents(); for (int line = firstline - 1; line < lastline; line += 1) { if (!contents.lineIsBlank(line) && !contents.lineIsComment(line) && contents.getLine(line).contains(";")) { count += 1; } } } return count; } }
/** * Returns length of code only without comments and blank lines. * @param openingBrace block opening brace * @param closingBrace block closing brace * @return number of lines with code for current block */ private int getLengthOfBlock(DetailAST openingBrace, DetailAST closingBrace) { int length = closingBrace.getLineNo() - openingBrace.getLineNo() + 1; if (!countEmpty) { final FileContents contents = getFileContents(); final int lastLine = closingBrace.getLineNo(); // lastLine - 1 is actual last line index. Last line is line with curly brace, // which is always not empty. So, we make it lastLine - 2 to cover last line that // actually may be empty. for (int i = openingBrace.getLineNo() - 1; i <= lastLine - 2; i++) { if (contents.lineIsBlank(i) || contents.lineIsComment(i)) { length--; } } } return length; }