delombok in JDK9 now almost works. Some cases of ‘val’ don’t work yet.

This commit is contained in:
Reinier Zwitserloot committed 2017-11-29 04:06:23 +01:00
1 parent 9be8cd4afd
commit af8c2bf8e5
5 files changed
+61 -9

No files matched your search

+1 -1
View File
@@ -223,7 +223,7 @@ public class JavacResolution {
private void attrib(JCTree tree, Env<AttrContext> env) {
if (tree instanceof JCBlock) attr.attribStat(tree, env);
else if (tree instanceof JCMethodDecl) attr.attribStat(((JCMethodDecl)tree).body, env);
else if (tree instanceof JCMethodDecl) attr.attribStat(((JCMethodDecl) tree).body, env);
else if (tree instanceof JCVariableDecl) attr.attribStat(tree, env);
else throw new IllegalStateException("Called with something that isn't a block, method decl, or variable decl");
}
+36 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2015 The Project Lombok Authors.
* Copyright (C) 2009-2017 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -49,6 +49,7 @@ import java.util.Set;
import java.util.regex.Pattern;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import lombok.Lombok;
@@ -59,6 +60,8 @@ import lombok.javac.apt.LombokProcessor;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.comp.Todo;
import com.sun.tools.javac.file.BaseFileManager;
import com.sun.tools.javac.main.Arguments;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
@@ -494,6 +497,29 @@ public class Delombok {
options.setFormatPreferences(new FormatPreferences(formatPrefs));
options.put("compilePolicy", "check");
if (Javac.getJavaCompilerVersion() >= 9) {
Arguments args = Arguments.instance(context);
List<String> argsList = new ArrayList<String>();
if (classpath != null) {
argsList.add("--class-path");
argsList.add(options.get("--class-path"));
}
if (sourcepath != null) {
argsList.add("--source-path");
argsList.add(options.get("--source-path"));
}
if (bootclasspath != null) {
argsList.add("--boot-class-path");
argsList.add(options.get("--boot-class-path"));
}
if (charset != null) {
argsList.add("-encoding");
argsList.add(charset.name());
}
String[] argv = argsList.toArray(new String[0]);
args.init("javac", argv);
}
CommentCatcher catcher = CommentCatcher.create(context);
JavaCompiler compiler = catcher.getCompiler();
@@ -502,6 +528,15 @@ public class Delombok {
Set<LombokProcessor> processors = Collections.singleton(new lombok.javac.apt.LombokProcessor());
if (Javac.getJavaCompilerVersion() >= 9) {
JavaFileManager jfm_ = context.get(JavaFileManager.class);
if (jfm_ instanceof BaseFileManager) {
Arguments args = Arguments.instance(context);
((BaseFileManager) jfm_).setContext(context); // reinit with options
((BaseFileManager) jfm_).handleOptions(args.getDeferredFileManagerOptions());
}
}
if (Javac.getJavaCompilerVersion() < 9) {
compiler.initProcessAnnotations(processors);
} else {
@@ -1433,22 +1433,19 @@ public class PrettyPrinter extends JCTree.Visitor {
if ("JCTypeUnion".equals(simpleName)) {
List<JCExpression> types = readObject(tree, "alternatives", List.<JCExpression>nil());
print(types, " | ");
return;
} else if ("JCTypeIntersection".equals(simpleName)) {
print(readObject(tree, "bounds", List.<JCExpression>nil()), " & ");
return;
} else if ("JCMemberReference".equals(simpleName)) {
printMemberReference0(tree);
return;
} else if ("JCLambda".equals(simpleName)) {
printLambda0(tree);
return;
} else if ("JCAnnotatedType".equals(simpleName)) {
printAnnotatedType0(tree);
return;
} else if ("JCPackageDecl".equals(simpleName)) {
// Starting with JDK9, this is inside the import list, but we've already printed it. Just ignore it.
} else {
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
}
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
}
private void printMemberReference0(JCTree tree) {
@@ -4,8 +4,15 @@
package com.sun.tools.javac.file;
import javax.tools.JavaFileManager;
import com.sun.tools.javac.main.Option;
import com.sun.tools.javac.util.Context;
import java.nio.charset.Charset;
import java.util.Map;
public abstract class BaseFileManager implements JavaFileManager {
protected BaseFileManager(Charset charset) {}
public void setContext(Context context) {}
public boolean handleOptions(Map<Option, String> deferredFileManagerOptions) { return false; }
}
@@ -0,0 +1,13 @@
package com.sun.tools.javac.main;
import java.util.Map;
import com.sun.tools.javac.util.Context;
public class Arguments {
public static final Context.Key<Arguments> argsKey = new Context.Key<Arguments>();
public static Arguments instance(Context context) { return null; }
public void init(String ownName, String... argv) {}
public Map<Option, String> getDeferredFileManagerOptions() { return null; }
public boolean validate() { return false; }
}