mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 00:16:47 +00:00
Merge branch 'jdk8support' of github.com:rzwitserloot/lombok into jdk8support
This commit is contained in:
commit
1eaaf3e276
7 files changed
+21
-14
No files matched your search
@@ -231,7 +231,7 @@ public class HandleConstructor {
|
||||
JCVariableDecl field = (JCVariableDecl) fieldNode.get();
|
||||
List<JCAnnotation> nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN);
|
||||
List<JCAnnotation> nullables = findAnnotations(fieldNode, TransformationsUtil.NULLABLE_PATTERN);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL, nonNulls.appendList(nullables)), field.name, field.vartype, null);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER, nonNulls.appendList(nullables)), field.name, field.vartype, null);
|
||||
params.append(param);
|
||||
JCFieldAccess thisX = maker.Select(maker.Ident(fieldNode.toName("this")), field.name);
|
||||
JCAssign assign = maker.Assign(thisX, maker.Ident(field.name));
|
||||
@@ -292,7 +292,7 @@ public class HandleConstructor {
|
||||
JCExpression pType = cloneType(maker, field.vartype, source);
|
||||
List<JCAnnotation> nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN);
|
||||
List<JCAnnotation> nullables = findAnnotations(fieldNode, TransformationsUtil.NULLABLE_PATTERN);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL, nonNulls.appendList(nullables)), field.name, pType, null);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER, nonNulls.appendList(nullables)), field.name, pType, null);
|
||||
params.append(param);
|
||||
args.append(maker.Ident(field.name));
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> {
|
||||
|
||||
int idx = 0;
|
||||
for (TypeMirror param : sig.type.getParameterTypes()) {
|
||||
JCModifiers paramMods = maker.Modifiers(Flags.FINAL);
|
||||
JCModifiers paramMods = maker.Modifiers(Flags.FINAL | Flags.PARAMETER);
|
||||
String[] paramNames = sig.getParameterNames();
|
||||
Name name = annotation.toName(paramNames[idx++]);
|
||||
params.append(maker.VarDef(paramMods, name, JavacResolution.typeToJCTree((Type) param, annotation.getAst(), true), null));
|
||||
|
||||
@@ -371,7 +371,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
|
||||
|
||||
ListBuffer<JCStatement> statements = ListBuffer.lb();
|
||||
final List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), oName, objectType, null));
|
||||
final List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER), oName, objectType, null));
|
||||
|
||||
/* if (o == this) return true; */ {
|
||||
statements.append(maker.If(maker.Binary(CTC_EQUAL, maker.Ident(oName),
|
||||
@@ -501,7 +501,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
Name canEqualName = typeNode.toName("canEqual");
|
||||
JCExpression objectType = chainDots(typeNode, "java", "lang", "Object");
|
||||
Name otherName = typeNode.toName("other");
|
||||
List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, objectType, null));
|
||||
List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER), otherName, objectType, null));
|
||||
|
||||
JCBlock body = maker.Block(0, List.<JCStatement>of(
|
||||
maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode)))));
|
||||
|
||||
@@ -211,7 +211,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
|
||||
Name methodName = field.toName(setterName);
|
||||
List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
|
||||
|
||||
JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
|
||||
JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL | Flags.PARAMETER, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
|
||||
|
||||
if (nonNulls.isEmpty()) {
|
||||
statements.append(treeMaker.Exec(assign));
|
||||
|
||||
@@ -214,7 +214,7 @@ public class HandleWither extends JavacAnnotationHandler<Wither> {
|
||||
Name methodName = field.toName(witherName);
|
||||
List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
|
||||
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
|
||||
|
||||
JCExpression selfType = cloneSelfType(field);
|
||||
if (selfType == null) return null;
|
||||
|
||||
@@ -97,6 +97,7 @@ public class JavacHandlerUtil {
|
||||
}
|
||||
|
||||
@Override public void scan(JCTree tree) {
|
||||
if (tree == null) return;
|
||||
setGeneratedBy(tree, source);
|
||||
super.scan(tree);
|
||||
}
|
||||
@@ -134,10 +135,12 @@ public class JavacHandlerUtil {
|
||||
}
|
||||
|
||||
public static <T extends JCTree> T setGeneratedBy(T node, JCTree source) {
|
||||
if (node == null) return null;
|
||||
synchronized (generatedNodes) {
|
||||
if (source == null) generatedNodes.remove(node);
|
||||
else generatedNodes.put(node, new WeakReference<JCTree>(source));
|
||||
}
|
||||
if (source != null) node.pos = source.pos;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
@@ -49,6 +50,7 @@ import javax.tools.JavaFileObject;
|
||||
import lombok.Lombok;
|
||||
import lombok.javac.CommentCatcher;
|
||||
import lombok.javac.LombokOptions;
|
||||
import lombok.javac.apt.Processor;
|
||||
|
||||
import com.sun.tools.javac.comp.Todo;
|
||||
import com.sun.tools.javac.main.JavaCompiler;
|
||||
@@ -363,7 +365,7 @@ public class Delombok {
|
||||
if (classpath != null) options.putJavacOption("CLASSPATH", classpath);
|
||||
if (sourcepath != null) options.putJavacOption("SOURCEPATH", sourcepath);
|
||||
if (bootclasspath != null) options.putJavacOption("BOOTCLASSPATH", bootclasspath);
|
||||
options.put("compilePolicy", "attr");
|
||||
options.put("compilePolicy", "check");
|
||||
|
||||
CommentCatcher catcher = CommentCatcher.create(context);
|
||||
JavaCompiler compiler = catcher.getCompiler();
|
||||
@@ -374,10 +376,7 @@ public class Delombok {
|
||||
compiler.initProcessAnnotations(Collections.singleton(new lombok.javac.apt.Processor()));
|
||||
|
||||
for (File fileToParse : filesToParse) {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
JCCompilationUnit unit = compiler.parse(fileToParse.getAbsolutePath());
|
||||
|
||||
@SuppressWarnings("deprecation") JCCompilationUnit unit = compiler.parse(fileToParse.getAbsolutePath());
|
||||
baseMap.put(unit, fileToBase.get(fileToParse));
|
||||
roots.add(unit);
|
||||
}
|
||||
@@ -386,8 +385,13 @@ public class Delombok {
|
||||
return false;
|
||||
}
|
||||
|
||||
JavaCompiler delegate = compiler.processAnnotations(compiler.enterTrees(toJavacList(roots)));
|
||||
callFlowMethodOnJavaCompiler(delegate, callAttributeMethodOnJavaCompiler(delegate, delegate.todo));
|
||||
com.sun.tools.javac.util.List<JCCompilationUnit> trees = compiler.enterTrees(toJavacList(roots));
|
||||
|
||||
JavaCompiler delegate = compiler.processAnnotations(trees);
|
||||
|
||||
Object care = callAttributeMethodOnJavaCompiler(delegate, delegate.todo);
|
||||
|
||||
callFlowMethodOnJavaCompiler(delegate, care);
|
||||
for (JCCompilationUnit unit : roots) {
|
||||
DelombokResult result = new DelombokResult(catcher.getComments(unit), unit, force || options.isChanged(unit));
|
||||
if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged");
|
||||
|
||||
Reference in new issue
Block a user