[Japi-cvs] SF.net SVN: japi:[958] tools/archStat/trunk/src/prj/net/sf/japi/archstat
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2009-02-18 05:37:28
|
Revision: 958 http://japi.svn.sourceforge.net/japi/?rev=958&view=rev Author: christianhujer Date: 2009-02-18 05:37:26 +0000 (Wed, 18 Feb 2009) Log Message: ----------- Fixed checkstyle issues. Modified Paths: -------------- tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java Modified: tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java 2009-02-18 05:15:34 UTC (rev 957) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/ArchStat.java 2009-02-18 05:37:26 UTC (rev 958) @@ -63,7 +63,7 @@ private boolean printSummaries; /** {@inheritDoc} */ - @SuppressWarnings({"InstanceMethodNamingConvention"}) + @SuppressWarnings({"InstanceMethodNamingConvention", "ProhibitedExceptionDeclared"}) public int run(@NotNull final List<String> args) throws Exception { if (args.size() == 0) { System.err.println("Error: No arguments given."); @@ -85,7 +85,7 @@ System.gc(); System.err.println("Memory free (end, after GC): " + Runtime.getRuntime().freeMemory()); } - return fileStat.warnings > 0 ? 1 : 0; + return fileStat.getWarnings() > 0 ? 1 : 0; } /** The default depth. */ @@ -140,7 +140,8 @@ final BufferedReader in = new BufferedReader(new FileReader(file)); try { final char[] buf = new char[BUF_SIZE]; - for (int charsRead; (charsRead = in.read(buf)) != -1; ) { + //noinspection NestedAssignment + for (int charsRead; (charsRead = in.read(buf)) != -1;) { sb.append(buf, 0, charsRead); } } finally { @@ -150,18 +151,24 @@ } /** The Pattern for splitting lines. */ - // TODO: This is somehow bogus. Replace this by something else. - private static final Pattern lineSplitPattern = Pattern.compile("(?<=\\r\\n|\\r|\\n)"); + // TODO:2009-02-18:christianhujer:This is somehow bogus. Replace this by something else. + private static final Pattern LINE_SPLIT_PATTERN = Pattern.compile("(?<=\\r\\n|\\r|\\n)"); /** The Pattern for counting lines. */ - private static final Pattern lineCountPattern = Pattern.compile("$", Pattern.MULTILINE); + private static final Pattern LINE_COUNT_PATTERN = Pattern.compile("$", Pattern.MULTILINE); + /** Pattern that matches comments. */ + private static final Pattern COMMENT_PATTERN = Pattern.compile("/(/.*?$|\\*.*?\\*/(\\s*?\\n)?)", Pattern.MULTILINE | Pattern.DOTALL); + + /** Pattern that matches source lines. */ + private static final Pattern SOURCE_LINE_PATTERN = Pattern.compile("^.*\\S.*\\S.*\\S.*$", Pattern.MULTILINE); + /** Returns the number of lines in the specified string. * @param string String of which to count lines. * @return The number of lines in <var>string</var> */ static int countLines(final CharSequence string) { - return count(lineCountPattern, string) - 1; + return count(LINE_COUNT_PATTERN, string) - 1; } /** Returns a split array of lines for the specified string. @@ -169,19 +176,30 @@ * @return Array with lines. */ static String[] getLines(final CharSequence string) { - return lineSplitPattern.split(string); + return LINE_SPLIT_PATTERN.split(string); } - private static final Pattern commentPattern = Pattern.compile("/(/.*?$|\\*.*?\\*/(\\s*?\\n)?)", Pattern.MULTILINE | Pattern.DOTALL); + /** Returns a String that is the input String with all comments removed. + * @param string String from which to remove the comments. + * @return Copy of <var>string</var> with all comments removed. + */ static CharSequence removeCComments(final CharSequence string) { - return commentPattern.matcher(string).replaceAll(""); + return COMMENT_PATTERN.matcher(string).replaceAll(""); } - private static final Pattern sourceLinePattern = Pattern.compile("^.*\\S.*\\S.*\\S.*$", Pattern.MULTILINE); + /** Returns the number of source lines of <var>string</var>. + * @param string String of which to count the number of source lines. + * @return The number of source lines of <var>string</var>. + */ static int countSourceLines(final CharSequence string) { - return count(sourceLinePattern, string); + return count(SOURCE_LINE_PATTERN, string); } + /** Returns the number of matches of <var>pattern</var> on <var>string</var>. + * @param pattern Pattern of which to count the matches. + * @param string String in which to count the matches. + * @return The number of matches of <var>pattern</var> on <var>string</var>. + */ private static int count(final Pattern pattern, final CharSequence string) { int count = 0; final Matcher m = pattern.matcher(string); @@ -191,6 +209,10 @@ return count; } + /** Reads the default checkers. + * @throws SAXException In case of XML issues when reading the default checkers. + * @throws IOException In case of I/O problems when reading the default checkers. + */ private void readDefaultCheckers() throws SAXException, IOException { final Enumeration<URL> checkers = ArchStat.class.getClassLoader().getResources("net/sf/japi/archstat/Checker.xml"); while (checkers.hasMoreElements()) { @@ -198,12 +220,16 @@ readCheckers(url); } } + + /** Parses the checkers. + * @param doc Document from which to parse the checkers. + */ private void readCheckers(final Document doc) { final NodeList nl = doc.getElementsByTagName("pattern"); for (int i = 0; i < nl.getLength(); i++) { final LineCheck check = new LineCheck((Element) nl.item(i)); if (checkers.contains(check)) { - // TODO improve + // TODO:2009-02-18:christianhujer:Improve. throw new RuntimeException("Duplicate Checker " + check.getName()); } checkers.add(new LineCheck((Element) nl.item(i))); Modified: tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java 2009-02-18 05:15:34 UTC (rev 957) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/FileStat.java 2009-02-18 05:37:26 UTC (rev 958) @@ -50,17 +50,23 @@ /** The file (regular file or directory) of this statistic. */ @Nullable private final File file; + /** Number of raw lines. */ private int linesRaw; + /** Number of lines which are not a comment. */ private int linesNoComment; + /** Number of true source lines. */ private int sourceLines; + /** Number of lines which are a comment. */ private int commentLines; + /** The text of the file to which this FileStat applies. */ private CharSequence fileText; - int warnings; + /** Number of warnings that occurred. */ + private int warnings; @SuppressWarnings({"AssignmentToCollectionOrArrayFieldFromParameter"}) FileStat(final List<LineCheck> checkers) { @@ -110,8 +116,8 @@ System.err.println(file + ": " + lineCheck.getMessageType() + ": " + i + " " + lineCheck.getPlural()); } } - if (warnings > 0) { - System.err.println(file + ": " + "warning: " + warnings + " warnings."); + if (getWarnings() > 0) { + System.err.println(file + ": " + "warning: " + getWarnings() + " warnings."); } } void checkLine(final String line, final int lineNumber) { @@ -122,7 +128,7 @@ } } public void incWarning(final LineCheck lineCheck) { - warnings++; + warnings = getWarnings() + 1; final Integer i = checkWarnings.get(lineCheck); checkWarnings.put(lineCheck, i != null ? i + 1 : 1); } @@ -149,7 +155,7 @@ */ public boolean isIgnored(@NotNull final File file) { final String filename = file.getName(); - // TODO:christianhujer:This should be configurable. + // TODO:2009-02-18:christianhujer:This should be configurable. return ".svn".equals(filename); } @@ -162,7 +168,7 @@ linesNoComment += child.linesNoComment; sourceLines += child.sourceLines; commentLines += child.commentLines; - warnings += child.warnings; + warnings = getWarnings() + child.getWarnings(); for (final LineCheck lineCheck : checkers) { final Integer childI = child.checkWarnings.get(lineCheck); if (childI != null) { @@ -204,4 +210,8 @@ } } } + + public int getWarnings() { + return warnings; + } } Modified: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java 2009-02-18 05:15:34 UTC (rev 957) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/LineCheck.java 2009-02-18 05:37:26 UTC (rev 958) @@ -98,7 +98,7 @@ * @return The plural name of this check. */ @NotNull public String getPlural() { - return name; // TODO + return name; // TODO:2009-02-18:christianhujer:Implement proper plural support. } /** {@inheritDoc} */ Modified: tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java =================================================================== --- tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java 2009-02-18 05:15:34 UTC (rev 957) +++ tools/archStat/trunk/src/prj/net/sf/japi/archstat/LogSystem.java 2009-02-18 05:37:26 UTC (rev 958) @@ -22,16 +22,20 @@ /** Static access to logging. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class LogSystem { +public final class LogSystem { /** The loggers. */ - private static final Logger[] loggers = { new StreamLogger(System.err) }; + private static final Logger[] LOGGERS = { new StreamLogger(System.err) }; + /** Utility class - do not instanciate. */ + private LogSystem() { + } + /** Logs a single log entry. * @param logEntry LogEntry to log. */ public static void log(@NotNull final LogEntry logEntry) { - for (final Logger logger : loggers) { + for (final Logger logger : LOGGERS) { logger.log(logEntry); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |