Skip to content

Commit

Permalink
Remove deprecated SourceFile factory methods.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=210636582
  • Loading branch information
tjgq authored and blickly committed Aug 30, 2018
1 parent 47cc7c5 commit 09128dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 40 deletions.
25 changes: 1 addition & 24 deletions src/com/google/javascript/jscomp/SourceFile.java
Expand Up @@ -414,20 +414,6 @@ public static SourceFile fromFile(String fileName) {
return fromFile(fileName, UTF_8); 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") @GwtIncompatible("java.io.File")
public static SourceFile fromPath(Path path, Charset charset, SourceKind kind) { public static SourceFile fromPath(Path path, Charset charset, SourceKind kind) {
return builder().withKind(kind).withCharset(charset).buildFromPath(path); return builder().withKind(kind).withCharset(charset).buildFromPath(path);
Expand Down Expand Up @@ -510,16 +496,7 @@ public Builder withOriginalPath(String originalPath) {


@GwtIncompatible("java.io.File") @GwtIncompatible("java.io.File")
public SourceFile buildFromFile(String fileName) { public SourceFile buildFromFile(String fileName) {
return buildFromFile(new File(fileName)); return buildFromPath(Paths.get(fileName));
}

/**
* @deprecated Use {@link #buildFromPath(Path path)}
*/
@GwtIncompatible("java.io.File")
@Deprecated
public SourceFile buildFromFile(File file) {
return buildFromPath(file.toPath());
} }


@GwtIncompatible("java.io.File") @GwtIncompatible("java.io.File")
Expand Down
28 changes: 12 additions & 16 deletions test/com/google/javascript/jscomp/SourceFileTest.java
Expand Up @@ -71,15 +71,15 @@ public void testCachingFile() throws IOException {
// Setup environment. // Setup environment.
String expectedContent = "// content content content"; String expectedContent = "// content content content";
String newExpectedContent = "// new content new content new content"; String newExpectedContent = "// new content new content new content";
Path jsFile = Files.createTempFile("test", ".js"); Path jsPath = Files.createTempFile("test", ".js");
MoreFiles.asCharSink(jsFile, StandardCharsets.UTF_8).write(expectedContent); MoreFiles.asCharSink(jsPath, StandardCharsets.UTF_8).write(expectedContent);
SourceFile sourceFile = SourceFile.fromFile(jsFile.toFile()); SourceFile sourceFile = SourceFile.fromPath(jsPath, StandardCharsets.UTF_8);


// Verify initial state. // Verify initial state.
assertEquals(expectedContent, sourceFile.getCode()); assertEquals(expectedContent, sourceFile.getCode());


// Perform a change. // Perform a change.
MoreFiles.asCharSink(jsFile, StandardCharsets.UTF_8).write(newExpectedContent); MoreFiles.asCharSink(jsPath, StandardCharsets.UTF_8).write(newExpectedContent);
sourceFile.clearCachedSource(); sourceFile.clearCachedSource();


// Verify final state. // Verify final state.
Expand Down Expand Up @@ -115,37 +115,33 @@ public void testCachingZipFile() throws IOException {
public void testSourceFileResolvesZipEntries() throws IOException { public void testSourceFileResolvesZipEntries() throws IOException {
// Setup environment. // Setup environment.
String expectedContent = "// <program goes here>"; String expectedContent = "// <program goes here>";
Path jsZipFile = Files.createTempFile("test", ".js.zip"); Path jsZipPath = Files.createTempFile("test", ".js.zip");
createZipWithContent(jsZipFile, expectedContent); createZipWithContent(jsZipPath, expectedContent);


// Test SourceFile#fromZipEntry(String, String, String, Charset) // Test SourceFile#fromZipEntry(String, String, String, Charset)
SourceFile sourceFileFromZipEntry = SourceFile sourceFileFromZipEntry =
SourceFile.fromZipEntry( SourceFile.fromZipEntry(
jsZipFile.toString(), jsZipPath.toString(),
jsZipFile.toAbsolutePath().toString(), jsZipPath.toAbsolutePath().toString(),
"foo.js", "foo.js",
StandardCharsets.UTF_8); StandardCharsets.UTF_8);
assertEquals(expectedContent, sourceFileFromZipEntry.getCode()); assertEquals(expectedContent, sourceFileFromZipEntry.getCode());


// Test SourceFile#fromFile(String) // 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()); assertEquals(expectedContent, sourceFileFromFileString.getCode());


// Test SourceFile#fromFile(String, Charset) // Test SourceFile#fromFile(String, Charset)
SourceFile sourceFileFromFileStringCharset = SourceFile sourceFileFromFileStringCharset =
SourceFile.fromFile(jsZipFile + "!/foo.js", StandardCharsets.UTF_8); SourceFile.fromFile(jsZipPath + "!/foo.js", StandardCharsets.UTF_8);
assertEquals(expectedContent, sourceFileFromFileStringCharset.getCode()); assertEquals(expectedContent, sourceFileFromFileStringCharset.getCode());


// Test SourceFile#fromPath(Path, Charset) // Test SourceFile#fromPath(Path, Charset)
Path zipEntryPath = Paths.get(jsZipFile + "!/foo.js"); Path zipEntryPath = Paths.get(jsZipPath + "!/foo.js");
SourceFile sourceFileFromPathCharset = SourceFile sourceFileFromPathCharset =
SourceFile.fromPath(zipEntryPath, StandardCharsets.UTF_8); SourceFile.fromPath(zipEntryPath, StandardCharsets.UTF_8);
assertEquals(expectedContent, sourceFileFromPathCharset.getCode()); 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 { private static void createZipWithContent(Path zipFile, String content) throws IOException {
Expand Down

0 comments on commit 09128dd

Please sign in to comment.