diff options
author | Michajlo Matijkiw <michajlo@google.com> | 2015-09-03 17:49:57 +0000 |
---|---|---|
committer | David Chen <dzc@google.com> | 2015-09-03 22:17:14 +0000 |
commit | 2c3b120a26612c5ad4856c043e888468b39a5f46 (patch) | |
tree | 8f0851039f79d60e6213f4ffc660da687db23fe8 | |
parent | 4226be2ddaf265c1eba70f28e0ed1d9578cf6690 (diff) |
Remove unused ParserInputSource method and other minor cleanups
Trying to curb usage of the create method taking a String for efficiency
reasons. Noticed this method was unused + a few places where we could
easily use chars instead of string. Not a major improvement but removes
some temptation.
RELNOTES:
--
MOS_MIGRATED_REVID=102258319
3 files changed, 5 insertions, 59 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java b/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java index 834fcaef36..a479ca9f55 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Preprocessor.java @@ -90,6 +90,8 @@ public interface Preprocessor { * A (result, success) tuple indicating the outcome of preprocessing. */ static class Result { + private static final char[] EMPTY_CHARS = new char[0]; + public final ParserInputSource result; public final boolean preprocessed; public final boolean containsErrors; @@ -103,7 +105,7 @@ public interface Preprocessor { this.containsTransientErrors = containsTransientErrors; } - /** Convenience factory for a {@link Result} wrapping non-preprocessed BUILD file contents. */ + /** Convenience factory for a {@link Result} wrapping non-preprocessed BUILD file contents. */ public static Result noPreprocessing(ParserInputSource buildFileSource) { return new Result(buildFileSource, /*preprocessed=*/false, /*containsErrors=*/false, /*containsTransientErrors=*/false); @@ -120,12 +122,12 @@ public interface Preprocessor { } public static Result invalidSyntax(PathFragment buildFile) { - return new Result(ParserInputSource.create("", buildFile), /*preprocessed=*/true, + return new Result(ParserInputSource.create(EMPTY_CHARS, buildFile), /*preprocessed=*/true, /*containsPersistentErrors=*/true, /*containsTransientErrors=*/false); } public static Result transientError(PathFragment buildFile) { - return new Result(ParserInputSource.create("", buildFile), /*preprocessed=*/false, + return new Result(ParserInputSource.create(EMPTY_CHARS, buildFile), /*preprocessed=*/false, /*containsPersistentErrors=*/false, /*containsTransientErrors=*/true); } } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java b/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java index 6cfdc94b00..82b2a442e0 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ParserInputSource.java @@ -18,7 +18,6 @@ import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import java.io.IOException; -import java.io.InputStream; /** * An abstraction for reading input from a file or taking it as a pre-cooked @@ -84,22 +83,4 @@ public abstract class ParserInputSource { } }; } - - /** - * Create an input source from the given input stream, and associate path - * with this source. 'path' will be used in error messages, etc, but will - * not (in general) be used to to read the content from path. - * - * <p>(The exception is the case in which Python pre-processing is required; the - * path will be used to provide the input to the Python pre-processor. - * Arguably, we should just send the content as input to the subprocess - * instead of using the path, but it's not clear it's worth the effort.) - */ - public static ParserInputSource create(InputStream in, Path path) throws IOException { - try { - return create(new String(FileSystemUtils.readContentAsLatin1(in)), path.asFragment()); - } finally { - in.close(); - } - } } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java index 0cb60798a0..9fe72815c2 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java @@ -26,9 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; /** @@ -67,17 +65,6 @@ public class ParserInputSourceTest { assertEquals(pathName, input.getPath().toString()); } - @Test - public void testCreateFromInputStream() throws IOException { - String content = "Content provided as a string."; - byte[] bytes = content.getBytes("ISO-8859-1"); - ByteArrayInputStream in = new ByteArrayInputStream(bytes); - String pathName = "/the/name/of/the/content.txt"; - Path path = scratch.resolve(pathName); - ParserInputSource input = ParserInputSource.create(in, path); - assertEquals(content, new String(input.getContent())); - assertEquals(pathName, input.getPath().toString()); - } @Test public void testIOExceptionIfInputFileDoesNotExistForSingleArgConstructor() { @@ -102,28 +89,4 @@ public class ParserInputSourceTest { char[] content = "Content provided as char array.".toCharArray(); ParserInputSource.create(content, new PathFragment("/will/not/try/to/read")); } - - @Test - public void testWillCloseStreamWhenReadingFromInputStream() { - final StringBuilder log = new StringBuilder(); - InputStream in = new InputStream() { - @Override - public int read() throws IOException { - throw new IOException("Fault injected."); - } - @Override - public void close() { - log.append("Stream closed."); - } - }; - try { - Path path = scratch.resolve("/will/not/try/to/read"); - ParserInputSource.create(in, path); - fail(); - } catch (IOException e) { - assertThat(e).hasMessage("Fault injected."); - } - assertEquals("Stream closed.", log.toString()); - } - } |