diff options
Diffstat (limited to 'src/delombok')
-rwxr-xr-x | src/delombok/lombok/delombok/Delombok.java | 40 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/DelombokApp.java | 13 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/DocCommentIntegrator.java | 6 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/PrettyPrinter.java | 30 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/ant/DelombokTask.java | 14 |
5 files changed, 51 insertions, 52 deletions
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index a1fd0e56..10ec5015 100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -34,7 +34,6 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.io.Writer; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.net.URLDecoder; @@ -44,6 +43,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.IdentityHashMap; import java.util.LinkedHashMap; import java.util.List; @@ -52,6 +52,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; +import javax.annotation.processing.AbstractProcessor; import javax.tools.DiagnosticListener; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; @@ -98,6 +99,7 @@ public class Delombok { private LinkedHashMap<File, File> fileToBase = new LinkedHashMap<File, File>(); private List<File> filesToParse = new ArrayList<File>(); private Map<String, String> formatPrefs = new HashMap<String, String>(); + private List<AbstractProcessor> additionalAnnotationProcessors = new ArrayList<AbstractProcessor>(); /** If null, output to standard out. */ private File output = null; @@ -166,6 +168,10 @@ public class Delombok { private boolean help; } + static { + LombokProcessor.addOpensForLombok(); + } + private static String indentAndWordbreak(String in, int indent, int maxLen) { StringBuilder out = new StringBuilder(); StringBuilder line = new StringBuilder(); @@ -643,6 +649,10 @@ public class Delombok { fileToBase.put(f, base); } + public void addAdditionalAnnotationProcessor(AbstractProcessor processor) { + additionalAnnotationProcessors.add(processor); + } + private static <T> com.sun.tools.javac.util.List<T> toJavacList(List<T> list) { com.sun.tools.javac.util.List<T> out = com.sun.tools.javac.util.List.nil(); ListIterator<T> li = list.listIterator(list.size()); @@ -701,8 +711,12 @@ public class Delombok { if (!disablePreview && Javac.getJavaCompilerVersion() >= 11) argsList.add("--enable-preview"); - String[] argv = argsList.toArray(new String[0]); - args.init("javac", argv); + if (Javac.getJavaCompilerVersion() < 15) { + String[] argv = argsList.toArray(new String[0]); + args.init("javac", argv); + } else { + args.init("javac", argsList); + } options.put("diags.legacy", "TRUE"); options.put("allowStringFolding", "FALSE"); } else { @@ -715,7 +729,9 @@ public class Delombok { List<JCCompilationUnit> roots = new ArrayList<JCCompilationUnit>(); Map<JCCompilationUnit, File> baseMap = new IdentityHashMap<JCCompilationUnit, File>(); - Set<LombokProcessor> processors = Collections.singleton(new lombok.javac.apt.LombokProcessor()); + Set<AbstractProcessor> processors = new HashSet<AbstractProcessor>(); + processors.add(new lombok.javac.apt.LombokProcessor()); + processors.addAll(additionalAnnotationProcessors); if (Javac.getJavaCompilerVersion() >= 9) { JavaFileManager jfm_ = context.get(JavaFileManager.class); @@ -837,12 +853,8 @@ public class Delombok { } } } - try { - return attributeMethod.invoke(compiler, arg); - } catch (Exception e) { - if (e instanceof InvocationTargetException) throw Lombok.sneakyThrow(e.getCause()); - throw Lombok.sneakyThrow(e); - } + + return Permit.invokeSneaky(attributeMethod, compiler, arg); } private static Method flowMethod; @@ -859,12 +871,8 @@ public class Delombok { } } } - try { - flowMethod.invoke(compiler, arg); - } catch (Exception e) { - if (e instanceof InvocationTargetException) throw Lombok.sneakyThrow(e.getCause()); - throw Lombok.sneakyThrow(e); - } + + Permit.invokeSneaky(flowMethod, compiler, arg); } private static String canonical(File dir) { diff --git a/src/delombok/lombok/delombok/DelombokApp.java b/src/delombok/lombok/delombok/DelombokApp.java index da1975b4..f5a5fc81 100644 --- a/src/delombok/lombok/delombok/DelombokApp.java +++ b/src/delombok/lombok/delombok/DelombokApp.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -37,10 +37,9 @@ import java.util.jar.JarFile; import lombok.core.LombokApp; import lombok.permit.Permit; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(LombokApp.class) +@Provides public class DelombokApp extends LombokApp { @Override public int runApp(List<String> args) throws Exception { try { @@ -53,11 +52,11 @@ public class DelombokApp extends LombokApp { return 1; } try { - Permit.getMethod(loadDelombok(args), "main", String[].class).invoke(null, new Object[] {args.toArray(new String[0])}); + Permit.invoke(Permit.getMethod(loadDelombok(args), "main", String[].class), null, new Object[] {args.toArray(new String[0])}); } catch (InvocationTargetException e1) { Throwable t = e1.getCause(); - if (t instanceof Error) throw (Error)t; - if (t instanceof Exception) throw (Exception)t; + if (t instanceof Error) throw (Error) t; + if (t instanceof Exception) throw (Exception) t; throw e1; } return 0; diff --git a/src/delombok/lombok/delombok/DocCommentIntegrator.java b/src/delombok/lombok/delombok/DocCommentIntegrator.java index bab0abd8..e61968a5 100644 --- a/src/delombok/lombok/delombok/DocCommentIntegrator.java +++ b/src/delombok/lombok/delombok/DocCommentIntegrator.java @@ -89,7 +89,7 @@ public class DocCommentIntegrator { ((Map<JCTree, String>) map_).put(node, docCommentContent); return true; } else if (Javac.instanceOfDocCommentTable(map_)) { - CommentAttacher_8.attach(node, docCommentContent, map_); + CommentAttacher_8.attach(node, docCommentContent, cmt.pos, map_); return true; } @@ -98,7 +98,7 @@ public class DocCommentIntegrator { /* Container for code which will cause class loader exceptions on javac below 8. By being in a separate class, we avoid the problem. */ private static class CommentAttacher_8 { - static void attach(final JCTree node, String docCommentContent, Object map_) { + static void attach(final JCTree node, String docCommentContent, final int pos, Object map_) { final String docCommentContent_ = docCommentContent; ((DocCommentTable) map_).putComment(node, new Comment() { @Override public String getText() { @@ -106,7 +106,7 @@ public class DocCommentIntegrator { } @Override public int getSourcePos(int index) { - return -1; + return pos + index; } @Override public CommentStyle getStyle() { diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 6682b5a3..05904815 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2020 The Project Lombok Authors. + * Copyright (C) 2016-2021 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 @@ -29,7 +29,6 @@ import static lombok.javac.JavacTreeMaker.TypeTag.typeTag; import java.io.IOException; import java.io.Writer; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; @@ -97,7 +96,6 @@ import lombok.javac.PackageName; import lombok.permit.Permit; import lombok.javac.CommentInfo.EndConnection; import lombok.javac.CommentInfo.StartConnection; -import lombok.javac.Java14Flags; import lombok.javac.JavacTreeMaker.TreeTag; import lombok.javac.JavacTreeMaker.TypeTag; @@ -280,7 +278,6 @@ public class PrettyPrinter extends JCTree.Visitor { aligned = false; } - private void println() { try { out.write(LINE_SEP); @@ -517,7 +514,7 @@ public class PrettyPrinter extends JCTree.Visitor { boolean isInterface = (tree.mods.flags & INTERFACE) != 0; boolean isAnnotationInterface = isInterface && (tree.mods.flags & ANNOTATION) != 0; boolean isEnum = (tree.mods.flags & ENUM) != 0; - boolean isRecord = (tree.mods.flags & Java14Flags.RECORD) != 0; + boolean isRecord = (tree.mods.flags & RECORD) != 0; if (isAnnotationInterface) print("@interface "); else if (isInterface) print("interface "); @@ -545,9 +542,7 @@ public class PrettyPrinter extends JCTree.Visitor { print(tree.implementing, ", "); } - if (isRecord) { - printRecordConstructor(tree.defs); - } + if (isRecord) printRecordConstructor(tree.defs); println(" {"); indent++; @@ -564,7 +559,7 @@ public class PrettyPrinter extends JCTree.Visitor { for (JCTree member : members) { if (member instanceof JCVariableDecl) { JCVariableDecl variableDecl = (JCVariableDecl) member; - if ((variableDecl.mods.flags & Java14Flags.GENERATED_MEMBER) != 0) { + if ((variableDecl.mods.flags & GENERATED_MEMBER) != 0) { if (!first) print(", "); first = false; printAnnotations(variableDecl.mods.annotations, false); @@ -574,7 +569,7 @@ public class PrettyPrinter extends JCTree.Visitor { } print(")"); } - + private void printClassMembers(List<JCTree> members, boolean isEnum, boolean isInterface) { Class<?> prefType = null; int typeOfPrevEnumMember = isEnum ? 3 : 0; // 1 = normal, 2 = with body, 3 = no enum field yet. @@ -604,7 +599,7 @@ public class PrettyPrinter extends JCTree.Visitor { JCTree init = ((JCVariableDecl) member).init; typeOfPrevEnumMember = init instanceof JCNewClass && ((JCNewClass) init).def != null ? 2 : 1; } else if (member instanceof JCVariableDecl) { - if ((((JCVariableDecl) member).mods.flags & Java14Flags.GENERATED_MEMBER) != 0) continue; + if ((((JCVariableDecl) member).mods.flags & GENERATED_MEMBER) != 0) continue; if (prefType != null && prefType != JCVariableDecl.class) println(); if (isInterface) flagMod = -1L & ~(PUBLIC | STATIC | FINAL); print(member); @@ -1412,9 +1407,10 @@ public class PrettyPrinter extends JCTree.Visitor { } void printBindingPattern(JCTree tree) { - print((JCExpression) readObject(tree, "vartype", null)); + JCTree var = readObject(tree, "var", tree); + print((JCExpression) readObject(var, "vartype", null)); print(" "); - print((Name) readObject(tree, "name", null)); + print((Name) readObject(var, "name", null)); } @Override public void visitTry(JCTry tree) { @@ -1572,13 +1568,7 @@ public class PrettyPrinter extends JCTree.Visitor { } public static JCTree getExtendsClause(JCClassDecl decl) { - try { - return (JCTree) getExtendsClause.invoke(decl); - } catch (IllegalAccessException e) { - throw sneakyThrow(e); - } catch (InvocationTargetException e) { - throw sneakyThrow(e.getCause()); - } + return (JCTree) Permit.invokeSneaky(getExtendsClause, decl); } static RuntimeException sneakyThrow(Throwable t) { diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java index defd1709..7c585836 100644 --- a/src/delombok/lombok/delombok/ant/DelombokTask.java +++ b/src/delombok/lombok/delombok/ant/DelombokTask.java @@ -177,9 +177,11 @@ class Tasks { } return Class.forName(name, true, shadowLoader); - } catch (Exception e) { - if (e instanceof RuntimeException) throw (RuntimeException) e; - throw new RuntimeException(e); + } catch (Throwable t) { + if (t instanceof InvocationTargetException) t = t.getCause(); + if (t instanceof RuntimeException) throw (RuntimeException) t; + if (t instanceof Error) throw (Error) t; + throw new RuntimeException(t); } } @@ -207,10 +209,10 @@ class Tasks { Method m = instance.getClass().getMethod("execute", Location.class); m.invoke(instance, loc); - } catch (Exception e) { - Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e; - if (t instanceof Error) throw (Error) t; + } catch (Throwable t) { + if (t instanceof InvocationTargetException) t = t.getCause(); if (t instanceof RuntimeException) throw (RuntimeException) t; + if (t instanceof Error) throw (Error) t; throw new RuntimeException(t); } } |