From 09128dd331a16f1b5537178cf1031e7e54fd414f Mon Sep 17 00:00:00 2001 From: tjgq Date: Tue, 28 Aug 2018 17:19:12 -0700 Subject: [PATCH] Remove deprecated SourceFile factory methods. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=210636582 --- .../google/javascript/jscomp/SourceFile.java | 25 +---------------- .../javascript/jscomp/SourceFileTest.java | 28 ++++++++----------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/com/google/javascript/jscomp/SourceFile.java b/src/com/google/javascript/jscomp/SourceFile.java index 534ad362f63..b06ef3f73a6 100644 --- a/src/com/google/javascript/jscomp/SourceFile.java +++ b/src/com/google/javascript/jscomp/SourceFile.java @@ -414,20 +414,6 @@ public static SourceFile fromFile(String fileName) { return fromFile(fileName, UTF_8); } - /** @deprecated Use {@link SourceFile#fromPath(Path, Charset)} */ - @Deprecated - @GwtIncompatible("java.io.File") - public static SourceFile fromFile(File file, Charset c) { - return builder().withCharset(c).buildFromFile(file); - } - - /** @deprecated Use {@link #fromPath(Path, Charset)} */ - @Deprecated - @GwtIncompatible("java.io.File") - public static SourceFile fromFile(File file) { - return fromFile(file, UTF_8); - } - @GwtIncompatible("java.io.File") public static SourceFile fromPath(Path path, Charset charset, SourceKind kind) { return builder().withKind(kind).withCharset(charset).buildFromPath(path); @@ -510,16 +496,7 @@ public Builder withOriginalPath(String originalPath) { @GwtIncompatible("java.io.File") public SourceFile buildFromFile(String fileName) { - return buildFromFile(new File(fileName)); - } - - /** - * @deprecated Use {@link #buildFromPath(Path path)} - */ - @GwtIncompatible("java.io.File") - @Deprecated - public SourceFile buildFromFile(File file) { - return buildFromPath(file.toPath()); + return buildFromPath(Paths.get(fileName)); } @GwtIncompatible("java.io.File") diff --git a/test/com/google/javascript/jscomp/SourceFileTest.java b/test/com/google/javascript/jscomp/SourceFileTest.java index b004c5da81d..9aad34df7d5 100644 --- a/test/com/google/javascript/jscomp/SourceFileTest.java +++ b/test/com/google/javascript/jscomp/SourceFileTest.java @@ -71,15 +71,15 @@ public void testCachingFile() throws IOException { // Setup environment. String expectedContent = "// content content content"; String newExpectedContent = "// new content new content new content"; - Path jsFile = Files.createTempFile("test", ".js"); - MoreFiles.asCharSink(jsFile, StandardCharsets.UTF_8).write(expectedContent); - SourceFile sourceFile = SourceFile.fromFile(jsFile.toFile()); + Path jsPath = Files.createTempFile("test", ".js"); + MoreFiles.asCharSink(jsPath, StandardCharsets.UTF_8).write(expectedContent); + SourceFile sourceFile = SourceFile.fromPath(jsPath, StandardCharsets.UTF_8); // Verify initial state. assertEquals(expectedContent, sourceFile.getCode()); // Perform a change. - MoreFiles.asCharSink(jsFile, StandardCharsets.UTF_8).write(newExpectedContent); + MoreFiles.asCharSink(jsPath, StandardCharsets.UTF_8).write(newExpectedContent); sourceFile.clearCachedSource(); // Verify final state. @@ -115,37 +115,33 @@ public void testCachingZipFile() throws IOException { public void testSourceFileResolvesZipEntries() throws IOException { // Setup environment. String expectedContent = "// "; - Path jsZipFile = Files.createTempFile("test", ".js.zip"); - createZipWithContent(jsZipFile, expectedContent); + Path jsZipPath = Files.createTempFile("test", ".js.zip"); + createZipWithContent(jsZipPath, expectedContent); // Test SourceFile#fromZipEntry(String, String, String, Charset) SourceFile sourceFileFromZipEntry = SourceFile.fromZipEntry( - jsZipFile.toString(), - jsZipFile.toAbsolutePath().toString(), + jsZipPath.toString(), + jsZipPath.toAbsolutePath().toString(), "foo.js", StandardCharsets.UTF_8); assertEquals(expectedContent, sourceFileFromZipEntry.getCode()); // Test SourceFile#fromFile(String) - SourceFile sourceFileFromFileString = SourceFile.fromFile(jsZipFile + "!/foo.js"); + SourceFile sourceFileFromFileString = + SourceFile.fromFile(jsZipPath + "!/foo.js", StandardCharsets.UTF_8); assertEquals(expectedContent, sourceFileFromFileString.getCode()); // Test SourceFile#fromFile(String, Charset) SourceFile sourceFileFromFileStringCharset = - SourceFile.fromFile(jsZipFile + "!/foo.js", StandardCharsets.UTF_8); + SourceFile.fromFile(jsZipPath + "!/foo.js", StandardCharsets.UTF_8); assertEquals(expectedContent, sourceFileFromFileStringCharset.getCode()); // Test SourceFile#fromPath(Path, Charset) - Path zipEntryPath = Paths.get(jsZipFile + "!/foo.js"); + Path zipEntryPath = Paths.get(jsZipPath + "!/foo.js"); SourceFile sourceFileFromPathCharset = SourceFile.fromPath(zipEntryPath, StandardCharsets.UTF_8); assertEquals(expectedContent, sourceFileFromPathCharset.getCode()); - - // Test SourceFile#fromFile(File, Charset) - SourceFile sourceFileFromFileCharset = - SourceFile.fromFile(zipEntryPath.toFile(), StandardCharsets.UTF_8); - assertEquals(expectedContent, sourceFileFromFileCharset.getCode()); } private static void createZipWithContent(Path zipFile, String content) throws IOException {