Skip to content

Commit

Permalink
Use the default / latest supported language level
Browse files Browse the repository at this point in the history
Previously the shaded javac was defaulting to Java 8, which we needed to
override to support Java 9. Now that we're using stock JDK 11 this is
unnecessary.

Also explicitly support `var`, instead of relying on it getting parsed as
an actual type name.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=302105420
  • Loading branch information
cushon authored and cpovirk committed Mar 21, 2020
1 parent 20e38aa commit d6d0b4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.google.googlejavaformat.Op;
import com.google.googlejavaformat.OpsBuilder;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.parser.JavacParser;
import com.sun.tools.javac.parser.ParserFactory;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
Expand Down Expand Up @@ -116,10 +115,6 @@ static void format(final JavaInput javaInput, JavaOutput javaOutput, JavaFormatt
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
context.put(DiagnosticListener.class, diagnostics);
Options.instance(context).put("allowStringFolding", "false");
// TODO(cushon): this should default to the latest supported source level, remove this after
// backing out
// https://github.com/google/error-prone-javac/commit/c97f34ddd2308302587ce2de6d0c984836ea5b9f
Options.instance(context).put(Option.SOURCE, "9");
JCCompilationUnit unit;
JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3251,7 +3251,9 @@ int declareOne(
visitAndBreakModifiers(
modifiers.get(), annotationsDirection, Optional.of(verticalAnnotationBreak));
}
builder.open(type != null ? plusFour : ZERO);
boolean isVar = builder.peekToken().get().equals("var");
boolean hasType = type != null || isVar;
builder.open(hasType ? plusFour : ZERO);
{
builder.open(ZERO);
{
Expand All @@ -3264,13 +3266,15 @@ int declareOne(
maybeAddDims(dims);
builder.close();
baseDims = totalDims - dims.size();
} else if (isVar) {
token("var");
} else {
scan(type, null);
}
}
builder.close();

if (type != null) {
if (hasType) {
builder.breakOp(Doc.FillMode.INDEPENDENT, " ", ZERO, Optional.of(typeBreak));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.sun.source.util.TreeScanner;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.parser.JavacParser;
import com.sun.tools.javac.parser.ParserFactory;
import com.sun.tools.javac.tree.DCTree;
Expand Down Expand Up @@ -186,8 +185,6 @@ public Void visitIdentifier(IdentifierTree node, Void aVoid) {

public static String removeUnusedImports(final String contents) throws FormatterException {
Context context = new Context();
// TODO(cushon): this should default to the latest supported source level, same as in Formatter
Options.instance(context).put(Option.SOURCE, "9");
JCCompilationUnit unit = parse(context, contents);
if (unit == null) {
// error handling is done during formatting
Expand Down

0 comments on commit d6d0b4d

Please sign in to comment.