Skip to content

Commit

Permalink
Made some elements private as needed in lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbduncan committed Dec 3, 2016
1 parent 81861fb commit 9853fe1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/src/main/java/com/diffplug/spotless/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

/** Formatter which performs the full formatting. */
public final class Formatter {
final LineEnding.Policy lineEndingsPolicy;
final Charset encoding;
final Path rootDir;
final List<FormatterStep> steps;
private final LineEnding.Policy lineEndingsPolicy;
private final Charset encoding;
private final Path rootDir;
private final List<FormatterStep> steps;

private static final Logger logger = Logger.getLogger(Formatter.class.getName());

Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List<FormatterStep> steps) {
private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List<FormatterStep> steps) {
this.lineEndingsPolicy = Objects.requireNonNull(lineEndingsPolicy, "lineEndingsPolicy");
this.encoding = Objects.requireNonNull(encoding, "encoding");
this.rootDir = Objects.requireNonNull(rootDirectory, "rootDir");
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/PaddedCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public List<String> steps() {
*/
public static PaddedCell check(Formatter formatter, File file) {
byte[] rawBytes = ThrowingEx.get(() -> Files.readAllBytes(file.toPath()));
String raw = new String(rawBytes, formatter.encoding);
String raw = new String(rawBytes, formatter.getEncoding());
String original = LineEnding.toUnix(raw);
return check(formatter, file, original, MAX_CYCLE);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/src/main/java/com/diffplug/spotless/PaddedCellBulk.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public static List<File> check(File rootDir, File diagnoseDir, Formatter formatt
// "fake" Formatter which can use the already-computed result of a PaddedCell as
FakeStep paddedCellStep = new FakeStep();
Formatter paddedFormatter = Formatter.builder()
.lineEndingsPolicy(formatter.lineEndingsPolicy)
.encoding(formatter.encoding)
.rootDir(formatter.rootDir)
.lineEndingsPolicy(formatter.getLineEndingsPolicy())
.encoding(formatter.getEncoding())
.rootDir(formatter.getRootDir())
.steps(Collections.singletonList(paddedCellStep))
.build();

Expand All @@ -132,7 +132,7 @@ public static List<File> check(File rootDir, File diagnoseDir, Formatter formatt
Path path = Paths.get(diagnoseFile + "." + padded.type().name().toLowerCase(Locale.ROOT) + i);
Files.createDirectories(path.getParent());
String version = padded.steps().get(i);
Files.write(path, version.getBytes(formatter.encoding));
Files.write(path, version.getBytes(formatter.getEncoding()));
}
// dump the type of the misbehavior to console
logger.finer(" " + relative + " " + padded.userMessage());
Expand Down Expand Up @@ -184,7 +184,7 @@ public String getName() {
/** Performs the typical spotlessApply, but with PaddedCell handling of misbehaving FormatterSteps. */
public static void apply(Formatter formatter, File file) throws IOException {
byte[] rawBytes = Files.readAllBytes(file.toPath());
String raw = new String(rawBytes, formatter.encoding);
String raw = new String(rawBytes, formatter.getEncoding());
String rawUnix = LineEnding.toUnix(raw);

// enforce the format
Expand All @@ -193,7 +193,7 @@ public static void apply(Formatter formatter, File file) throws IOException {
String formatted = formatter.applyLineEndings(formattedUnix, file);

// if F(input) == input, then the formatter is well-behaving and the input is clean
byte[] formattedBytes = formatted.getBytes(formatter.encoding);
byte[] formattedBytes = formatted.getBytes(formatter.getEncoding());
if (Arrays.equals(rawBytes, formattedBytes)) {
return;
}
Expand All @@ -208,15 +208,15 @@ public static void apply(Formatter formatter, File file) throws IOException {
// get the canonical bytes
String canonicalUnix = cell.canonical();
String canonical = formatter.applyLineEndings(canonicalUnix, file);
byte[] canonicalBytes = canonical.getBytes(formatter.encoding);
byte[] canonicalBytes = canonical.getBytes(formatter.getEncoding());
if (!Arrays.equals(rawBytes, canonicalBytes)) {
// and write them to disk if needed
Files.write(file.toPath(), canonicalBytes, StandardOpenOption.TRUNCATE_EXISTING);
}
}

/** Does whatever it takes to turn this path into an empty folder. */
static void cleanDir(Path folder) throws IOException {
private static void cleanDir(Path folder) throws IOException {
if (Files.exists(folder)) {
if (Files.isDirectory(folder)) {
Files.walkFileTree(folder, new SimpleFileVisitor<Path>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.diffplug.spotless.FormatterStep;

// TODO: Consider making this class (and every other class in lib & lib-extra) final
public class EndWithNewlineStep {
/** Creates a FormatterStep which forces lines to end with a newline. */
public static FormatterStep create() {
Expand All @@ -25,7 +26,7 @@ public static FormatterStep create() {
unused -> EndWithNewlineStep::format);
}

static String format(String rawUnix) {
private static String format(String rawUnix) {
// simplifies the logic below if we can assume length > 0
if (rawUnix.isEmpty()) {
return "\n";
Expand Down

0 comments on commit 9853fe1

Please sign in to comment.