Skip to content

Commit

Permalink
Expose GwtIncompatibleStripper public API for processing one file at …
Browse files Browse the repository at this point in the history
…a time.

Closes #105

Fixes #98

PiperOrigin-RevId: 323115911
  • Loading branch information
tbroyer authored and copybara-github committed Jul 25, 2020
1 parent 3eca22c commit bcf27bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static com.google.common.base.Preconditions.checkState;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.MoreFiles;
Expand Down Expand Up @@ -44,7 +43,7 @@
* A helper to comment out source code elements annotated with @GwtIncompatible so that they are
* ignored by tools taking that source as input such as the java compile or the j2cl transpile.
*/
final class GwtIncompatibleStripper {
public final class GwtIncompatibleStripper {

static Problems strip(List<String> files, String outputPath) {
try {
Expand Down Expand Up @@ -74,7 +73,7 @@ private static void preprocessFiles(List<FileInfo> fileInfos, Path output, Probl
try {
String fileContent =
MoreFiles.asCharSource(Paths.get(fileInfo.sourcePath()), StandardCharsets.UTF_8).read();
processedFileContent = processFile(fileContent);
processedFileContent = strip(fileContent);
} catch (IOException e) {
problems.fatal(FatalError.CANNOT_OPEN_FILE, e.toString());
return;
Expand All @@ -86,8 +85,7 @@ private static void preprocessFiles(List<FileInfo> fileInfos, Path output, Probl
}
}

@VisibleForTesting
static String processFile(String fileContent) {
public static String strip(String fileContent) {
// Avoid parsing if there are no textual references to GwtIncompatible.
if (!fileContent.contains("GwtIncompatible")) {
return fileContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class GwtIncompatibleStripperTest {
@Test
public void testNoProcess() {
String content = "public class Foo {}";
assertEquals(content, GwtIncompatibleStripper.processFile(content));
assertEquals(content, GwtIncompatibleStripper.strip(content));
}

@Test
public void testNoProcessString() {
String content = "public class Foo {String a = \"@GwtIncompatible\");}";
assertEquals(content, GwtIncompatibleStripper.processFile(content));
assertEquals(content, GwtIncompatibleStripper.strip(content));
}

@Test
Expand All @@ -57,7 +57,7 @@ public void testProcessClass() {
Strings.repeat(" ", "public class Foo {".length()),
Strings.repeat(" ", " public X m() {return null;}".length()),
Strings.repeat(" ", "}".length()));
assertEquals(after, GwtIncompatibleStripper.processFile(before));
assertEquals(after, GwtIncompatibleStripper.strip(before));
}

@Test
Expand All @@ -84,7 +84,7 @@ public void testProcessMethod() {
Strings.repeat(" ", " @GwtIncompatible".length()),
Strings.repeat(" ", " public D n() {}".length()),
"}");
assertEquals(after, GwtIncompatibleStripper.processFile(before));
assertEquals(after, GwtIncompatibleStripper.strip(before));
}

@Test
Expand All @@ -107,7 +107,7 @@ public void testProcessField() {
Strings.repeat(" ", " public String b;".length()),
" public String c;",
"}");
assertEquals(after, GwtIncompatibleStripper.processFile(before));
assertEquals(after, GwtIncompatibleStripper.strip(before));
}

@Test
Expand Down Expand Up @@ -148,7 +148,7 @@ public void testProcessMultiple() {
Strings.repeat(" ", " }".length()),
" String s;",
"}");
assertEquals(after, GwtIncompatibleStripper.processFile(before));
assertEquals(after, GwtIncompatibleStripper.strip(before));
}

@Test
Expand All @@ -169,7 +169,7 @@ public void testNestedComment() {
Strings.repeat(" ", " @GwtIncompatible".length()),
Strings.repeat(" ", " public void n() {foo(x /* the value of x */);}".length()),
"}");
assertEquals(after, GwtIncompatibleStripper.processFile(before));
assertEquals(after, GwtIncompatibleStripper.strip(before));
}

@Test
Expand All @@ -190,7 +190,7 @@ public void testTabs() {
Strings.repeat(" ", " @GwtIncompatible".length()),
" \t" + Strings.repeat(" ", "public B n() {}".length()),
"}");
assertEquals(after, GwtIncompatibleStripper.processFile(before));
assertEquals(after, GwtIncompatibleStripper.strip(before));
}

@Test
Expand All @@ -213,6 +213,6 @@ public void testMultibyteChars() {
Strings.repeat(" ", " //மெ.பை.".length()),
Strings.repeat(" ", " public B n() {}".length()),
"}");
assertEquals(after, GwtIncompatibleStripper.processFile(before));
assertEquals(after, GwtIncompatibleStripper.strip(before));
}
}

0 comments on commit bcf27bc

Please # to comment.