[Japi-cvs] SF.net SVN: japi:[934] tools/replacer/trunk/src
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2009-02-17 20:45:50
|
Revision: 934
http://japi.svn.sourceforge.net/japi/?rev=934&view=rev
Author: christianhujer
Date: 2009-02-17 20:45:44 +0000 (Tue, 17 Feb 2009)
Log Message:
-----------
Fixed checkstyle issues.
Modified Paths:
--------------
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java
tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableDefaultTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableLineIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterablePatternListTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableSplitIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithSplitIteratorTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithStringSplitTest.java
tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/SubstitutionTest.java
Modified: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterable.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -88,6 +88,8 @@
return new LineIterator(text);
case SPLIT_ITERATOR:
return new SplitIterator(text, LINE_SPLIT_PATTERN);
+ default:
+ assert false;
}
throw new Error("Compile time error. IteratorImplementation missing.");
}
Modified: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/LineIterator.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -114,13 +114,13 @@
private boolean isCharBeforeEndALineTerminator() {
final char c = text.charAt(end - 1);
return
- c == LINE_FEED ||
+ c == LINE_FEED
// CARRIAGE_RETURN only already terminates a line if it is standalone.
// If it is immediately followed by a LINE_FEED, that line feed will terminate the line in the next invocation.
- c == CARRIAGE_RETURN && (end == text.length() || text.charAt(end) != LINE_FEED) ||
- c == NEXT_LINE ||
- c == LINE_SEPARATOR ||
- c == PARAGRAPH_SEPARATOR;
+ || c == CARRIAGE_RETURN && (end == text.length() || text.charAt(end) != LINE_FEED)
+ || c == NEXT_LINE
+ || c == LINE_SEPARATOR
+ || c == PARAGRAPH_SEPARATOR;
}
/** {@inheritDoc}
Modified: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Replacer.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -52,16 +52,16 @@
* Files will only be written if at least one of the substitution steps caused a change.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-// TODO Add interactive mode.
+// TODO:2009-02-17:christianhujer:Add interactive mode.
// The interactive mode for each match should show the context of the substitution.
// It should replace only after user confirmation.
-// TODO Add ranges mode.
+// TODO:2009-02-17:christianhujer:Add ranges mode.
// The ranges mode specifies a range before an s command.
// The default range is % - all lines of the file.
// Ranges could also be 3,5 - lines 3 to 5 in the file.
-// TODO Add option for user-definable command, e.g. for checking out files from a VCS.
-// TODO Add pretend option to just pretend changing files but do not actually change them.
-// TODO Support comment lines, e.g. with #
+// TODO:2009-02-17:christianhujer:Add option for user-definable command, e.g. for checking out files from a VCS.
+// TODO:2009-02-17:christianhujer:Add pretend option to just pretend changing files but do not actually change them.
+// TODO:2009-02-17:christianhujer:Support comment lines, e.g. with #
public class Replacer extends BasicCommand {
/** The default file ending for backup files. */
@@ -431,7 +431,7 @@
final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding));
try {
//noinspection NestedAssignment
- for (String line; (line = in.readLine()) != null; ) {
+ for (String line; (line = in.readLine()) != null;) {
addSubstitution(line);
}
} finally {
Modified: tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java
===================================================================
--- tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/prj/net/sf/japi/tools/replacer/Substitution.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -91,20 +91,20 @@
*
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
-// TODO: Add support for /e and a way for specifying the expression language (e.g. Java, ECMAScript, Groovy) for /e.
+// TODO:2009-02-17:christianhujer:Add support for /e and a way for specifying the expression language (e.g. Java, ECMAScript, Groovy) for /e.
public class Substitution {
/** The regular expression used to parse an sed / perl / vi like substitution command.
* The syntax is "s/pattern/replacement/flags".
* If "/" appears in the pattern or the replacement, it needs to be escaped.
*/
- private static final Pattern rePattern = Pattern.compile("^s/((?:\\\\/|[^/])*+)/((?:\\\\|\\\\/|[^/])*+)/(.*+)$");
+ private static final Pattern RE_PATTERN = Pattern.compile("^s/((?:\\\\/|[^/])*+)/((?:\\\\|\\\\/|[^/])*+)/(.*+)$");
/** The unmodifiable map with the flags.
* Key: Flag character.
* Value: integer flag value for {@link Pattern#compile(String, int)} resp. returned by {@link Pattern#flags()}.
*/
- private static final Map<Character, Integer> flagMap = createFlagMap();
+ private static final Map<Character, Integer> FLAG_MAP = createFlagMap();
/** The pattern used for this substitution. */
private final String patternString;
@@ -255,8 +255,8 @@
if (flagString != null) {
StringBuilder bogusFlags = null;
for (final char c : flagString.toCharArray()) {
- if (flagMap.containsKey(c)) {
- final Integer flag = flagMap.get(c);
+ if (FLAG_MAP.containsKey(c)) {
+ final Integer flag = FLAG_MAP.get(c);
if (flag != null) {
flags |= flag;
}
@@ -295,7 +295,7 @@
* @return The three subcomponents pattern, replacement and flags.
*/
public static String[] parseRegex(@NotNull final CharSequence regex) {
- final Matcher matcher = rePattern.matcher(regex);
+ final Matcher matcher = RE_PATTERN.matcher(regex);
if (!matcher.matches()) {
throw new IllegalArgumentException("Malformed substitution command.");
}
@@ -370,6 +370,6 @@
public static Map<Character, Integer> getFlagMap() {
//The collection already is unmodifiable.
//noinspection ReturnOfCollectionOrArrayField
- return flagMap;
+ return FLAG_MAP;
}
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableDefaultTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableDefaultTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableDefaultTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -39,5 +39,5 @@
*/
@SuppressWarnings({"JUnitTestMethodWithNoAssertions"})
@Test
- public void dummyForIntelliJIDEA() {}
+ public void dummyForIntelliJIDEA() { }
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableLineIteratorTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableLineIteratorTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableLineIteratorTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -39,5 +39,5 @@
*/
@SuppressWarnings({"JUnitTestMethodWithNoAssertions"})
@Test
- public void dummyForIntelliJIDEA() {}
+ public void dummyForIntelliJIDEA() { }
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterablePatternListTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterablePatternListTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterablePatternListTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -39,5 +39,5 @@
*/
@SuppressWarnings({"JUnitTestMethodWithNoAssertions"})
@Test
- public void dummyForIntelliJIDEA() {}
+ public void dummyForIntelliJIDEA() { }
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableSplitIteratorTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableSplitIteratorTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIterableSplitIteratorTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -39,5 +39,5 @@
*/
@SuppressWarnings({"JUnitTestMethodWithNoAssertions"})
@Test
- public void dummyForIntelliJIDEA() {}
+ public void dummyForIntelliJIDEA() { }
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIteratorTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIteratorTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithLineIteratorTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -39,5 +39,5 @@
*/
@SuppressWarnings({"JUnitTestMethodWithNoAssertions"})
@Test
- public void dummyForIntelliJIDEA() {}
+ public void dummyForIntelliJIDEA() { }
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithSplitIteratorTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithSplitIteratorTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithSplitIteratorTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -38,5 +38,5 @@
*/
@SuppressWarnings({"JUnitTestMethodWithNoAssertions"})
@Test
- public void dummyForIntelliJIDEA() {}
+ public void dummyForIntelliJIDEA() { }
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithStringSplitTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithStringSplitTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/LineIterationWithStringSplitTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -36,9 +36,9 @@
// The contract of these line iterators is that an empty text will return zero lines.
// The split operation will still return at least 1 element.
// Because of that an empty text needs special treatment to return zero lines instead of 1 empty line.
- return text.length() == 0 ?
- Collections.<CharSequence>emptySet().iterator() :
- Arrays.<CharSequence>asList(Pattern.compile("(?<=\\n|\u0085|\u2028|\u2029|\\r(?!\\n))").split(text)).iterator();
+ return text.length() == 0
+ ? Collections.<CharSequence>emptySet().iterator()
+ : Arrays.<CharSequence>asList(Pattern.compile("(?<=\\n|\u0085|\u2028|\u2029|\\r(?!\\n))").split(text)).iterator();
}
/** Dummy test for working aroud a bug in IntelliJ IDEA.
@@ -46,5 +46,5 @@
*/
@SuppressWarnings({"JUnitTestMethodWithNoAssertions"})
@Test
- public void dummyForIntelliJIDEA() {}
+ public void dummyForIntelliJIDEA() { }
}
Modified: tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/SubstitutionTest.java
===================================================================
--- tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/SubstitutionTest.java 2009-02-17 19:57:05 UTC (rev 933)
+++ tools/replacer/trunk/src/tst/test/net/sf/japi/tools/replacer/SubstitutionTest.java 2009-02-17 20:45:44 UTC (rev 934)
@@ -72,70 +72,70 @@
/** Tests that {@link Substitution#parseFlags(String)} works with null flags. */
@Test
- public void testParseFlag_null() {
+ public void testParseFlagNull() {
final int flags = Substitution.parseFlags(null);
Assert.assertEquals("Expecting null flags to be zero.", 0, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with empty flags. */
@Test
- public void testParseFlag_empty() {
+ public void testParseFlagEmpty() {
final int flags = Substitution.parseFlags("");
Assert.assertEquals("Expecting null flags to be zero.", 0, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "d" flag. */
@Test
- public void testParseFlag_d() {
+ public void testParseFlagD() {
final int flags = Substitution.parseFlags("d");
Assert.assertEquals("Expecting d flag to be UNIX LINES.", Pattern.UNIX_LINES, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "i" flag. */
@Test
- public void testParseFlag_i() {
+ public void testParseFlagI() {
final int flags = Substitution.parseFlags("i");
Assert.assertEquals("Expecting i flag to be CASE INSENSITIVE.", Pattern.CASE_INSENSITIVE, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "x" flag. */
@Test
- public void testParseFlag_x() {
+ public void testParseFlagX() {
final int flags = Substitution.parseFlags("x");
Assert.assertEquals("Expecting x flag to be COMMENTS.", Pattern.COMMENTS, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "m" flag. */
@Test
- public void testParseFlag_m() {
+ public void testParseFlagM() {
final int flags = Substitution.parseFlags("m");
Assert.assertEquals("Expecting m flag to be MULTI_LINE.", Pattern.MULTILINE, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "l" flag. */
@Test
- public void testParseFlag_l() {
+ public void testParseFlagL() {
final int flags = Substitution.parseFlags("l");
Assert.assertEquals("Expecting l flag to be LITERAL.", Pattern.LITERAL, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "s" flag. */
@Test
- public void testParseFlag_s() {
+ public void testParseFlagS() {
final int flags = Substitution.parseFlags("s");
Assert.assertEquals("Expecting s flag to be DOTALL.", Pattern.DOTALL, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "u" flag. */
@Test
- public void testParseFlag_u() {
+ public void testParseFlagU() {
final int flags = Substitution.parseFlags("u");
Assert.assertEquals("Expecting u flag to be UNICODE CASE.", Pattern.UNICODE_CASE, flags);
}
/** Tests that {@link Substitution#parseFlags(String)} works with "c" flag. */
@Test
- public void testParseFlag_c() {
+ public void testParseFlagC() {
final int flags = Substitution.parseFlags("c");
Assert.assertEquals("Expecting c flag to be CANON EQ.", Pattern.CANON_EQ, flags);
}
@@ -155,7 +155,7 @@
/** Tests that {@link Substitution#Substitution(CharSequence)} interprets the d flag. */
@Test
- public void testConstructFlag_d() {
+ public void testConstructFlagD() {
final Substitution subst = new Substitution("s/foo/bar/d");
Assert.assertEquals("Expecting d flag to activate UNIX_LINES,", Pattern.UNIX_LINES, subst.getFlags());
Assert.assertFalse("Expecting d flag to not set file mode.", subst.isFile());
@@ -164,14 +164,14 @@
/** Tests that {@link Substitution#Substitution(CharSequence)} interprets the i flag. */
@Test
- public void testConstructFlag_i() {
+ public void testConstructFlagI() {
final Substitution subst = new Substitution("s/foo/bar/i");
Assert.assertEquals("Expecting d flag to activate CASE_INSENSITIVE,", Pattern.CASE_INSENSITIVE, subst.getFlags());
}
/** Tests that {@link Substitution#Substitution(CharSequence)} interprets the x flag. */
@Test
- public void testConstructFlag_x() {
+ public void testConstructFlagX() {
final Substitution subst = new Substitution("s/foo/bar/x");
Assert.assertEquals("Expecting d flag to activate COMMENTS,", Pattern.COMMENTS, subst.getFlags());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|