From 9ed14b8cbf8beb209f0d63e69e472bf81efe1d35 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 6 Aug 2013 21:22:24 +0200 Subject: added Flags.PARAMETER to all the parameters we generate in javac. --- src/core/lombok/javac/handlers/HandleConstructor.java | 4 ++-- src/core/lombok/javac/handlers/HandleDelegate.java | 2 +- src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java | 4 ++-- src/core/lombok/javac/handlers/HandleSetter.java | 2 +- src/core/lombok/javac/handlers/HandleWither.java | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index 1134c45c..99c426de 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -231,7 +231,7 @@ public class HandleConstructor { JCVariableDecl field = (JCVariableDecl) fieldNode.get(); List nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN); List 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 nonNulls = findAnnotations(fieldNode, TransformationsUtil.NON_NULL_PATTERN); List 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)); } diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java index 33627072..6af34f20 100644 --- a/src/core/lombok/javac/handlers/HandleDelegate.java +++ b/src/core/lombok/javac/handlers/HandleDelegate.java @@ -305,7 +305,7 @@ public class HandleDelegate extends JavacAnnotationHandler { 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)); diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index 88ab3871..9e871b4e 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -371,7 +371,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler statements = ListBuffer.lb(); - final List params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), oName, objectType, null)); + final List 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 params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL), otherName, objectType, null)); + List params = List.of(maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER), otherName, objectType, null)); JCBlock body = maker.Block(0, List.of( maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode))))); diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 1f8caa9b..6f345418 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -211,7 +211,7 @@ public class HandleSetter extends JavacAnnotationHandler { Name methodName = field.toName(setterName); List 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)); diff --git a/src/core/lombok/javac/handlers/HandleWither.java b/src/core/lombok/javac/handlers/HandleWither.java index 9397caa0..4bda5464 100644 --- a/src/core/lombok/javac/handlers/HandleWither.java +++ b/src/core/lombok/javac/handlers/HandleWither.java @@ -214,7 +214,7 @@ public class HandleWither extends JavacAnnotationHandler { Name methodName = field.toName(witherName); List 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; -- cgit From df69425550d55da3de07f922fced3872432cd9d3 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 6 Aug 2013 21:22:48 +0200 Subject: position now set for all code generated by javac handlers; this also solves the AssertionError in the Bits class on javac8-ea. --- src/core/lombok/javac/handlers/JavacHandlerUtil.java | 3 +++ src/delombok/lombok/delombok/Delombok.java | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index c245d506..65997f9a 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -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 setGeneratedBy(T node, JCTree source) { + if (node == null) return null; synchronized (generatedNodes) { if (source == null) generatedNodes.remove(node); else generatedNodes.put(node, new WeakReference(source)); } + if (source != null) node.pos = source.pos; return node; } diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 7291ac29..473afb5c 100644 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -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 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"); -- cgit