X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=utils%2FMessageBundleChecker.java;fp=utils%2FMessageBundleChecker.java;h=4489a9384a374ff71a51c61e1b7aaebb819cba6d;hb=7d67fb613ec026dc9a265e351e7fab542e3f1d61;hp=9d322dfe5cacdea5a839ad0a7e5b00412d3157b2;hpb=02e38bb826828ab2991584cf4b737c0138cb6c44;p=jalview.git diff --git a/utils/MessageBundleChecker.java b/utils/MessageBundleChecker.java index 9d322df..4489a93 100644 --- a/utils/MessageBundleChecker.java +++ b/utils/MessageBundleChecker.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -20,7 +40,7 @@ import java.util.regex.Pattern; * @author gmcarstairs * */ -public class MessageBundleChecker +public class MessageBundleChecker implements BufferedLineReader.LineCleaner { /* * regex ^"[^"]*"$ @@ -192,64 +212,37 @@ public class MessageBundleChecker return; } - String[] lines = new String[bufferSize]; BufferedReader br = new BufferedReader(new FileReader(f)); - for (int i = 0; i < bufferSize; i++) - { - String readLine = br.readLine(); - lines[i] = stripCommentsAndTrim(readLine); - } + BufferedLineReader blr = new BufferedLineReader(br, bufferSize, this); int lineNo = 0; - - while (lines[bufferSize - 1] != null) + String line = blr.read(); + while (line != null) { lineNo++; - inspectSourceLines(path, lineNo, lines); - - for (int i = 0; i < bufferSize - 1; i++) - { - lines[i] = lines[i + 1]; - } - lines[bufferSize - 1] = stripCommentsAndTrim(br.readLine()); + inspectSourceLines(path, lineNo, line); + line = blr.read(); } br.close(); } - /* - * removes anything after (and including) '//' - */ - private String stripCommentsAndTrim(String line) - { - if (line != null) - { - int pos = line.indexOf("//"); - if (pos != -1) - { - line = line.substring(0, pos); - } - line = line.replace("\t", " ").trim(); - } - return line; - } - /** * Look for calls to MessageManager methods, possibly split over two or more - * lines + * lines that have been concatenated while parsing the file * * @param path * @param lineNo - * @param lines + * @param line */ - private void inspectSourceLines(String path, int lineNo, String[] lines) + private void inspectSourceLines(String path, int lineNo, String line) { - String lineNos = String.format("%d-%d", lineNo, lineNo + lines.length + String lineNos = String + .format("%d-%d", lineNo, lineNo + bufferSize - 1); - String combined = combineLines(lines); for (String method : METHODS) { - int pos = combined.indexOf(method); + int pos = line.indexOf(method); if (pos == -1) { continue; @@ -258,7 +251,7 @@ public class MessageBundleChecker /* * extract what follows the opening bracket of the method call */ - String methodArgs = combined.substring(pos + method.length()).trim(); + String methodArgs = line.substring(pos + method.length()).trim(); if ("".equals(methodArgs)) { /* @@ -285,7 +278,7 @@ public class MessageBundleChecker if (METHOD3 == method) { System.out.println(String.format("Dynamic key at %s line %s %s", - path.substring(sourcePath.length()), lineNos, combined)); + path.substring(sourcePath.length()), lineNos, line)); continue; } @@ -293,14 +286,14 @@ public class MessageBundleChecker if (messageKey == null) { System.out.println(String.format("Trouble parsing %s line %s %s", - path.substring(sourcePath.length()), lineNos, combined)); + path.substring(sourcePath.length()), lineNos, line)); continue; } if (!(STRING_PATTERN.matcher(messageKey).matches())) { System.out.println(String.format("Dynamic key at %s line %s %s", - path.substring(sourcePath.length()), lineNos, combined)); + path.substring(sourcePath.length()), lineNos, line)); continue; } @@ -364,22 +357,6 @@ public class MessageBundleChecker return endPos == -1 ? null : key.substring(0, endPos); } - private String combineLines(String[] lines) - { - String combined = ""; - if (lines != null) - { - for (String line : lines) - { - if (line != null) - { - combined += line; - } - } - } - return combined; - } - /** * Loads properties from Message.properties * @@ -401,4 +378,22 @@ public class MessageBundleChecker } + /** + * Remove any trailing comments, change tabs to space, and trim + */ + @Override + public String cleanLine(String l) + { + if (l != null) + { + int pos = l.indexOf("//"); + if (pos != -1) + { + l = l.substring(0, pos); + } + l = l.replace("\t", " ").trim(); + } + return l; + } + }