Skip to content

Commit 57eb2b7

Browse files
sormurascushon
authored andcommitted
Set supported Java source level to "9" (#182)
Fixes #181
1 parent 386244c commit 57eb2b7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

core/src/main/java/com/google/googlejavaformat/java/RemoveUnusedImports.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.openjdk.source.util.TreeScanner;
5454
import org.openjdk.tools.javac.api.JavacTrees;
5555
import org.openjdk.tools.javac.file.JavacFileManager;
56+
import org.openjdk.tools.javac.main.Option;
5657
import org.openjdk.tools.javac.parser.JavacParser;
5758
import org.openjdk.tools.javac.parser.ParserFactory;
5859
import org.openjdk.tools.javac.tree.DCTree;
@@ -195,6 +196,8 @@ public Void visitIdentifier(IdentifierTree node, Void aVoid) {
195196
public static String removeUnusedImports(
196197
final String contents, JavadocOnlyImports javadocOnlyImports) {
197198
Context context = new Context();
199+
// TODO(cushon): this should default to the latest supported source level, same as in Formatter
200+
Options.instance(context).put(Option.SOURCE, "9");
198201
JCCompilationUnit unit = parse(context, contents);
199202
if (unit == null) {
200203
// error handling is done during formatting

core/src/test/java/com/google/googlejavaformat/java/RemoveUnusedImportsTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ public static Collection<Object[]> parameters() {
329329
"public class Test implements Foo, Bar, Baz, Bork {}",
330330
},
331331
},
332+
{
333+
{
334+
"import java.lang.Foo;", //
335+
"interface Test { private static void foo() {} }",
336+
},
337+
{
338+
"interface Test { private static void foo() {} }",
339+
},
340+
{
341+
"interface Test { private static void foo() {} }",
342+
},
343+
},
332344
};
333345
ImmutableList.Builder<Object[]> builder = ImmutableList.builder();
334346
for (String[][] inputAndOutput : inputsOutputs) {

0 commit comments

Comments
 (0)