aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/SneakyThrows.java4
-rw-r--r--src/core/lombok/eclipse/handlers/HandleLog.java2
-rw-r--r--src/core/lombok/eclipse/handlers/HandleVal.java20
-rw-r--r--src/core/lombok/javac/JavacAST.java2
-rw-r--r--src/core/lombok/javac/JavacResolution.java60
-rw-r--r--src/core/lombok/javac/handlers/HandleLog.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java1
-rw-r--r--src/core/lombok/javac/handlers/HandleVal.java6
8 files changed, 84 insertions, 13 deletions
diff --git a/src/core/lombok/SneakyThrows.java b/src/core/lombok/SneakyThrows.java
index 0506d615..2a8009a3 100644
--- a/src/core/lombok/SneakyThrows.java
+++ b/src/core/lombok/SneakyThrows.java
@@ -39,14 +39,14 @@ import java.lang.annotation.Target;
* Example:
* <pre>
* &#64;SneakyThrows(UnsupportedEncodingException.class)
- * public void utf8ToString(byte[] bytes) {
+ * public String utf8ToString(byte[] bytes) {
* return new String(bytes, "UTF-8");
* }
* </pre>
*
* Becomes:
* <pre>
- * public void utf8ToString(byte[] bytes) {
+ * public String utf8ToString(byte[] bytes) {
* try {
* return new String(bytes, "UTF-8");
* } catch (UnsupportedEncodingException $uniqueName) {
diff --git a/src/core/lombok/eclipse/handlers/HandleLog.java b/src/core/lombok/eclipse/handlers/HandleLog.java
index 525f534a..1cac2de7 100644
--- a/src/core/lombok/eclipse/handlers/HandleLog.java
+++ b/src/core/lombok/eclipse/handlers/HandleLog.java
@@ -302,7 +302,7 @@ public class HandleLog {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_CUSTOM_FLAG_USAGE, "@CustomLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
LogDeclaration logDeclaration = annotationNode.getAst().readConfiguration(ConfigurationKeys.LOG_CUSTOM_DECLARATION);
if (logDeclaration == null) {
- annotationNode.addError("The @CustomLog annotation is not configured; please set log.custom.declaration in lombok.config.");
+ annotationNode.addError("The @CustomLog annotation is not configured; please set lombok.log.custom.declaration in lombok.config.");
return;
}
LoggingFramework framework = new LoggingFramework(lombok.CustomLog.class, logDeclaration);
diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java
index ac53e27e..0f70e66d 100644
--- a/src/core/lombok/eclipse/handlers/HandleVal.java
+++ b/src/core/lombok/eclipse/handlers/HandleVal.java
@@ -22,12 +22,14 @@
package lombok.eclipse.handlers;
import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
-import static lombok.eclipse.handlers.EclipseHandlerUtil.typeMatches;
+import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
+
import lombok.ConfigurationKeys;
import lombok.val;
import lombok.var;
import lombok.core.HandlerPriority;
import lombok.eclipse.DeferUntilPostDiet;
+import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseASTAdapter;
import lombok.eclipse.EclipseASTVisitor;
import lombok.eclipse.EclipseNode;
@@ -39,10 +41,13 @@ import org.eclipse.jdt.internal.compiler.ast.ForStatement;
import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
+import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
/*
- * This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}.
+ * Java 1-9: This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}.
+ * Java 10+: Lombok uses the native 'var' support and transforms 'val' to 'final var'.
*/
@Provides(EclipseASTVisitor.class)
@DeferUntilPostDiet
@@ -96,5 +101,16 @@ public class HandleVal extends EclipseASTAdapter {
localNode.addError("variable initializer is 'null'");
return;
}
+
+ // For Java >= 10 we use native support
+ if (localNode.getSourceVersion() >= 10) {
+ if (isVal) {
+ TypeReference originalType = local.type;
+ local.type = new SingleTypeReference("var".toCharArray(), Eclipse.pos(local.type));
+ local.modifiers |= ClassFileConstants.AccFinal;
+ local.annotations = addAnnotation(local.type, local.annotations, originalType.getTypeName());
+ }
+ return;
+ }
}
}
diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java
index f58de60f..0919c7d4 100644
--- a/src/core/lombok/javac/JavacAST.java
+++ b/src/core/lombok/javac/JavacAST.java
@@ -228,7 +228,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
int underscoreIdx = nm.indexOf('_');
if (underscoreIdx > -1) return Integer.parseInt(nm.substring(underscoreIdx + 1));
// assume java9+
- return Integer.parseInt(nm);
+ return Integer.parseInt(nm.substring(3));
} catch (Exception ignore) {}
return 6;
}
diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java
index e96079e0..f1109f4e 100644
--- a/src/core/lombok/javac/JavacResolution.java
+++ b/src/core/lombok/javac/JavacResolution.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2020 The Project Lombok Authors.
+ * Copyright (C) 2011-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,6 +29,7 @@ import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -45,6 +46,7 @@ import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type.TypeVar;
import com.sun.tools.javac.code.Type.WildcardType;
import com.sun.tools.javac.code.Types;
+import com.sun.tools.javac.comp.ArgumentAttr;
import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Enter;
@@ -68,6 +70,7 @@ import lombok.core.debug.AssertionLogger;
import lombok.permit.Permit;
public class JavacResolution {
+ private final Context context;
private final Attr attr;
private final CompilerMessageSuppressor messageSuppressor;
@@ -82,6 +85,7 @@ public class JavacResolution {
}
public JavacResolution(Context context) {
+ this.context = context;
attr = Attr.instance(context);
messageSuppressor = new CompilerMessageSuppressor(context);
}
@@ -245,10 +249,19 @@ public class JavacResolution {
} catch (Throwable ignore) {
// This addresses issue #1553 which involves JDK9; if it doesn't exist, we probably don't need to set it.
}
- if (tree instanceof JCBlock) attr.attribStat(tree, 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");
+
+ Map<?,?> cache = null;
+ try {
+ cache = ArgumentAttrReflect.enableTempCache(context);
+
+ if (tree instanceof JCBlock) attr.attribStat(tree, 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");
+ } finally {
+ ArgumentAttrReflect.restoreCache(cache, context);
+ }
+
}
public static class TypeNotConvertibleException extends Exception {
@@ -283,6 +296,43 @@ public class JavacResolution {
}
}
+ /**
+ * ArgumentAttr was added in Java 9 and caches some method arguments. Lombok should cleanup its changes after resolution.
+ */
+ private static class ArgumentAttrReflect {
+ private static Field ARGUMENT_TYPE_CACHE;
+
+ static {
+ if (Javac.getJavaCompilerVersion() >= 9) {
+ try {
+ ARGUMENT_TYPE_CACHE = Permit.getField(ArgumentAttr.class, "argumentTypeCache");
+ } catch (Exception ignore) {}
+ }
+ }
+
+ public static Map<?, ?> enableTempCache(Context context) {
+ if (ARGUMENT_TYPE_CACHE == null) return null;
+
+ ArgumentAttr argumentAttr = ArgumentAttr.instance(context);
+ try {
+ Map<?, ?> cache = (Map<?, ?>) Permit.get(ARGUMENT_TYPE_CACHE, argumentAttr);
+ Permit.set(ARGUMENT_TYPE_CACHE, argumentAttr, new LinkedHashMap<Object, Object>(cache));
+ return cache;
+ } catch (Exception ignore) { }
+
+ return null;
+ }
+
+ public static void restoreCache(Map<?, ?> cache, Context context) {
+ if (ARGUMENT_TYPE_CACHE == null) return;
+
+ ArgumentAttr argumentAttr = ArgumentAttr.instance(context);
+ try {
+ Permit.set(ARGUMENT_TYPE_CACHE, argumentAttr, cache);
+ } catch (Exception ignore) { }
+ }
+ }
+
public static Type ifTypeIsIterableToComponent(Type type, JavacAST ast) {
if (type == null) return null;
Types types = Types.instance(ast.getContext());
diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java
index 47c4098f..40f7ff08 100644
--- a/src/core/lombok/javac/handlers/HandleLog.java
+++ b/src/core/lombok/javac/handlers/HandleLog.java
@@ -260,7 +260,7 @@ public class HandleLog {
handleFlagUsage(annotationNode, ConfigurationKeys.LOG_CUSTOM_FLAG_USAGE, "@CustomLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log");
LogDeclaration logDeclaration = annotationNode.getAst().readConfiguration(ConfigurationKeys.LOG_CUSTOM_DECLARATION);
if (logDeclaration == null) {
- annotationNode.addError("The @CustomLog is not configured; please set log.custom.declaration in lombok.config.");
+ annotationNode.addError("The @CustomLog is not configured; please set lombok.log.custom.declaration in lombok.config.");
return;
}
LoggingFramework framework = new LoggingFramework(lombok.CustomLog.class, logDeclaration);
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index a0634494..e5b2c062 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -43,7 +43,6 @@ import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCAssign;
import com.sun.tools.javac.tree.JCTree.JCBlock;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCReturn;
diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java
index 0ed831ab..d4fb1027 100644
--- a/src/core/lombok/javac/handlers/HandleVal.java
+++ b/src/core/lombok/javac/handlers/HandleVal.java
@@ -115,6 +115,12 @@ public class HandleVal extends JavacASTAdapter {
local.mods.annotations = local.mods.annotations == null ? List.of(valAnnotation) : local.mods.annotations.append(valAnnotation);
}
+ if (localNode.getSourceVersion() >= 10) {
+ local.vartype = null;
+ localNode.getAst().setChanged();
+ return;
+ }
+
if (JavacResolution.platformHasTargetTyping()) {
local.vartype = localNode.getAst().getTreeMaker().Ident(localNode.getAst().toName("___Lombok_VAL_Attrib__"));
} else {