aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/changelog.markdown2
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java19
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java5
-rw-r--r--test/transform/resource/after-delombok/ValWeirdTypes.java6
-rw-r--r--test/transform/resource/after-ecj/ValWeirdTypes.java7
-rw-r--r--test/transform/resource/before/ValWeirdTypes.java8
6 files changed, 43 insertions, 4 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index fee354fe..26ad3dcb 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -2,7 +2,7 @@ Lombok Changelog
----------------
### v1.18.7 "Edgy Guinea Pig"
-* Nothing new yet in the edge release.
+* BUGFIX: var/val on methods that return an intersection type would now work in Eclipse [Issue #1986](https://github.com/rzwitserloot/lombok/issues/1986)
### v1.18.6 (February 12th, 2019)
* FEATURE: Javadoc on fields will now also be copied to the Builders' setters. Thanks for the contribution, Emil Lundberg. [Issue #2008](https://github.com/rzwitserloot/lombok/issues/2008)
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 026c2383..9439caf3 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2018 The Project Lombok Authors.
+ * Copyright (C) 2009-2019 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
@@ -306,10 +306,14 @@ public class EclipseHandlerUtil {
public static final Field STRING_LITERAL__LINE_NUMBER;
public static final Field ANNOTATION__MEMBER_VALUE_PAIR_NAME;
public static final Field TYPE_REFERENCE__ANNOTATIONS;
+ public static final Class<?> INTERSECTION_BINDING;
+ public static final Field INTERSECTION_BINDING_TYPES;
static {
STRING_LITERAL__LINE_NUMBER = getField(StringLiteral.class, "lineNumber");
ANNOTATION__MEMBER_VALUE_PAIR_NAME = getField(Annotation.class, "memberValuePairName");
TYPE_REFERENCE__ANNOTATIONS = getField(TypeReference.class, "annotations");
+ INTERSECTION_BINDING = getClass("org.eclipse.jdt.internal.compiler.lookup.IntersectionTypeBinding18");
+ INTERSECTION_BINDING_TYPES = INTERSECTION_BINDING == null ? null : getField(INTERSECTION_BINDING, "intersectingTypes");
}
public static int reflectInt(Field f, Object o) {
@@ -336,6 +340,14 @@ public class EclipseHandlerUtil {
}
}
+ private static Class<?> getClass(String fqn) {
+ try {
+ return Class.forName(fqn);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
private static Field getField(Class<?> c, String fName) {
try {
return Permit.getField(c, fName);
@@ -791,6 +803,11 @@ public class EclipseHandlerUtil {
}
public static TypeReference makeType(TypeBinding binding, ASTNode pos, boolean allowCompound) {
+
+ if (binding.getClass() == EclipseReflectiveMembers.INTERSECTION_BINDING) {
+ Object[] arr = (Object[]) EclipseReflectiveMembers.reflect(EclipseReflectiveMembers.INTERSECTION_BINDING_TYPES, binding);
+ binding = (TypeBinding) arr[0];
+ }
int dims = binding.dimensions();
binding = binding.leafComponentType();
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 8d581819..12f4ad3d 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2018 The Project Lombok Authors.
+ * Copyright (C) 2010-2019 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
@@ -265,8 +265,9 @@ public class PatchVal {
if (resolved != null) {
try {
replacement = makeType(resolved, local.type, false);
+ if (!decomponent) init.resolvedType = replacement.resolveType(scope);
} catch (Exception e) {
- // Some type thing failed. It might be an IntersectionType
+ // Some type thing failed.
}
}
}
diff --git a/test/transform/resource/after-delombok/ValWeirdTypes.java b/test/transform/resource/after-delombok/ValWeirdTypes.java
index cd6ba538..a6bc9bd4 100644
--- a/test/transform/resource/after-delombok/ValWeirdTypes.java
+++ b/test/transform/resource/after-delombok/ValWeirdTypes.java
@@ -1,3 +1,4 @@
+import java.math.BigDecimal;
import java.util.*;
public class ValWeirdTypes<Z> {
private List<Z> fieldList;
@@ -54,4 +55,9 @@ public class ValWeirdTypes<Z> {
final java.lang.Object[] single = multiDimArray[0];
final int singleInt = copy[0];
}
+ public void arraysAsList() {
+ final java.util.List<java.lang.Class<? extends java.lang.Object>> x = Arrays.asList(String.class, BigDecimal.class);
+ for (final java.lang.Class<?> y : x) {
+ }
+ }
}
diff --git a/test/transform/resource/after-ecj/ValWeirdTypes.java b/test/transform/resource/after-ecj/ValWeirdTypes.java
index 516a3932..9f448db9 100644
--- a/test/transform/resource/after-ecj/ValWeirdTypes.java
+++ b/test/transform/resource/after-ecj/ValWeirdTypes.java
@@ -1,3 +1,4 @@
+import java.math.BigDecimal;
import java.util.*;
import lombok.val;
public class ValWeirdTypes<Z> {
@@ -61,4 +62,10 @@ public class ValWeirdTypes<Z> {
final @val java.lang.Object[] single = multiDimArray[0];
final @val int singleInt = copy[0];
}
+ public void arraysAsList() {
+ final @val java.util.List<java.lang.Class<? extends java.lang.Object>> x = Arrays.asList(String.class, BigDecimal.class);
+ for (final @val java.lang.Class<? extends java.lang.Object> y : x)
+ {
+ }
+ }
} \ No newline at end of file
diff --git a/test/transform/resource/before/ValWeirdTypes.java b/test/transform/resource/before/ValWeirdTypes.java
index 8cba2de5..4ea1b5d4 100644
--- a/test/transform/resource/before/ValWeirdTypes.java
+++ b/test/transform/resource/before/ValWeirdTypes.java
@@ -1,3 +1,4 @@
+import java.math.BigDecimal;
import java.util.*;
import lombok.val;
@@ -64,4 +65,11 @@ public class ValWeirdTypes<Z> {
val single = multiDimArray[0];
val singleInt = copy[0];
}
+
+ public void arraysAsList() {
+ val x = Arrays.asList(String.class, BigDecimal.class);
+ for (val y : x) {
+
+ }
+ }
} \ No newline at end of file