Skip to content

Commit

Permalink
[fixes projectlombok#2648] Remove copy of generic information
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Nov 19, 2020
1 parent e1f82ac commit 80867c3
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
Expand Up @@ -58,7 +58,6 @@
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.Scope;
Expand Down Expand Up @@ -304,15 +303,6 @@ public static Object resolveType(Object resolvedType, MessageSend methodCall, Bl
argumentTypes.add(argumentType);
}

// Copy generic information. This one covers a few simple cases, more complex cases are still broken
int typeVariables = extensionMethod.typeVariables.length;
if (typeVariables > 0 && methodCall.receiver.resolvedType instanceof ParameterizedTypeBinding) {
ParameterizedTypeBinding parameterizedTypeBinding = (ParameterizedTypeBinding) methodCall.receiver.resolvedType;
if (parameterizedTypeBinding.arguments != null && parameterizedTypeBinding.arguments.length == typeVariables) {
methodCall.genericTypeArguments = parameterizedTypeBinding.arguments;
}
}

MethodBinding fixedBinding = scope.getMethod(extensionMethod.declaringClass, methodCall.selector, argumentTypes.toArray(new TypeBinding[0]), methodCall);
if (fixedBinding instanceof ProblemMethodBinding) {
methodCall.arguments = originalArgs;
Expand Down
29 changes: 29 additions & 0 deletions test/transform/resource/after-delombok/ExtensionMethodGeneric.java
@@ -0,0 +1,29 @@
import java.util.List;
import java.util.Map;

class ExtensionMethodGeneric {
public void test() {
List<String> stringList = null;
List<Number> numberList = null;
ExtensionMethodGeneric.Extensions.test(stringList, numberList);
ExtensionMethodGeneric.Extensions.test(stringList);
Integer i = ExtensionMethodGeneric.Extensions.test2(stringList);
Map<String, Integer> map = null;
List<String> l = ExtensionMethodGeneric.Extensions.test(map, stringList, numberList);
}

static class Extensions {
public static <T> List<T> test(List<String> obj, List<T> list) {
return null;
}
public static <K, V> K test(Map<String, Integer> obj, K k, V v) {
return k;
}
public static <T> T test(List<T> list) {
return null;
}
public static <T, U> U test2(List<T> list) {
return null;
}
}
}
34 changes: 34 additions & 0 deletions test/transform/resource/after-ecj/ExtensionMethodGeneric.java
@@ -0,0 +1,34 @@
import java.util.List;
import java.util.Map;
import lombok.experimental.ExtensionMethod;
@ExtensionMethod(ExtensionMethodGeneric.Extensions.class) class ExtensionMethodGeneric {
static class Extensions {
Extensions() {
super();
}
public static <T>List<T> test(List<String> obj, List<T> list) {
return null;
}
public static <K, V>K test(Map<String, Integer> obj, K k, V v) {
return k;
}
public static <T>T test(List<T> list) {
return null;
}
public static <T, U>U test2(List<T> list) {
return null;
}
}
ExtensionMethodGeneric() {
super();
}
public void test() {
List<String> stringList = null;
List<Number> numberList = null;
ExtensionMethodGeneric.Extensions.test(stringList, numberList);
ExtensionMethodGeneric.Extensions.test(stringList);
Integer i = ExtensionMethodGeneric.Extensions.test2(stringList);
Map<String, Integer> map = null;
List<String> l = ExtensionMethodGeneric.Extensions.test(map, stringList, numberList);
}
}
33 changes: 33 additions & 0 deletions test/transform/resource/before/ExtensionMethodGeneric.java
@@ -0,0 +1,33 @@
import java.util.List;
import java.util.Map;

import lombok.experimental.ExtensionMethod;

@ExtensionMethod(ExtensionMethodGeneric.Extensions.class)
class ExtensionMethodGeneric {
public void test() {
List<String> stringList = null;
List<Number> numberList = null;
stringList.test(numberList);
stringList.test();
Integer i = stringList.test2();

Map<String, Integer> map = null;
List<String> l = map.test(stringList, numberList);
}

static class Extensions {
public static <T> List<T> test(List<String> obj, List<T> list) {
return null;
}
public static <K,V> K test(Map<String, Integer> obj, K k, V v) {
return k;
}
public static <T> T test(List<T> list) {
return null;
}
public static <T,U> U test2(List<T> list) {
return null;
}
}
}

0 comments on commit 80867c3

Please sign in to comment.