Skip to content

Commit

Permalink
Issue #62: fixed checkstyle violations in injectable resources
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Aug 7, 2017
1 parent d0d8de2 commit 24a5d63
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2017 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle;

import java.io.File;
Expand Down Expand Up @@ -33,7 +52,7 @@ public void generateExtractInfoFile() throws IOException {
for (Class<?> module : modules) {
moduleJsonArray.add(createJsonObjectFromModuleClass(module));
}
String jsonString = moduleJsonArray.toString();
final String jsonString = moduleJsonArray.toString();
final File output = new File("checkstyle_modules.json");
Files.write(output.toPath(), jsonString.getBytes(Charset.forName("UTF-8")),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2017 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle;

import java.util.Arrays;
Expand All @@ -10,15 +29,21 @@
* @author LuoLiangchen
*/
class JsonUtil {
/** Delimiter starting and ending a string. */
private static final String STRING_DELIMITER = "\"";

/** Newline string. */
private static final String NEWLINE = "\n";

/**
* Adds indent of the given text.
* @param text the text to add indent
* @return the result text with indent
*/
private static String addIndent(String text) {
return Arrays.stream(text.split("\n"))
return Arrays.stream(text.split(NEWLINE))
.map(line -> " " + line)
.collect(Collectors.joining("\n"));
.collect(Collectors.joining(NEWLINE));
}

/**
Expand All @@ -27,11 +52,16 @@ private static String addIndent(String text) {
* @return the format result
*/
private static String format(Object object) {
final String result;

if (object instanceof String) {
return "\"" + object + "\"";
} else {
return object.toString();
result = STRING_DELIMITER + object + STRING_DELIMITER;
}
else {
result = object.toString();
}

return result;
}

/** Represents an object type in Json. */
Expand Down Expand Up @@ -61,8 +91,8 @@ void add(String key, Object value) {
public String toString() {
final String keyValueLines = members.stream()
.map(Object::toString)
.collect(Collectors.joining(",\n"));
return "{\n" + addIndent(keyValueLines) + "\n}";
.collect(Collectors.joining("," + NEWLINE));
return "{" + NEWLINE + addIndent(keyValueLines) + NEWLINE + "}";
}
}

Expand All @@ -84,7 +114,7 @@ public String toString() {
final String membersLines = members.stream()
.map(JsonUtil::format)
.collect(Collectors.joining(",\n"));
return "[\n" + addIndent(membersLines) + "\n]";
return "[" + NEWLINE + addIndent(membersLines) + NEWLINE + "]";
}
}

Expand All @@ -108,7 +138,7 @@ private static final class KeyValue {

@Override
public String toString() {
return "\"" + key + "\": " + format(value);
return STRING_DELIMITER + key + STRING_DELIMITER + ": " + format(value);
}
}
}

0 comments on commit 24a5d63

Please sign in to comment.