mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 06:17:44 +00:00
[fixes #3463] Support argument widening for extension methods
This commit is contained in:
1 parent
000ce6d19a
commit
519a482a15
4 files changed
+48
-9
No files matched your search
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2022 The Project Lombok Authors.
|
||||
* Copyright (C) 2012-2023 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
|
||||
@@ -64,7 +64,6 @@ import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.Scope;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
|
||||
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
|
||||
import org.eclipse.jdt.internal.core.search.matching.MethodPattern;
|
||||
|
||||
@@ -346,13 +345,7 @@ public class PatchExtensionMethod {
|
||||
arg.resolveType(scope);
|
||||
}
|
||||
if (arg.resolvedType != null) {
|
||||
if (!param.isBaseType() && arg.resolvedType.isBaseType()) {
|
||||
int id = arg.resolvedType.id;
|
||||
arg.implicitConversion = TypeIds.BOXING | (id + (id << 4)); // magic see TypeIds
|
||||
} else if (param.isBaseType() && !arg.resolvedType.isBaseType()) {
|
||||
int id = parameters[i].id;
|
||||
arg.implicitConversion = TypeIds.UNBOXING | (id + (id << 4)); // magic see TypeIds
|
||||
}
|
||||
arg.computeConversion(scope, param, arg.resolvedType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class ExtensionMethodWidening {
|
||||
public void test() {
|
||||
String string = "test";
|
||||
ExtensionMethodWidening.Extensions.widening(string, 1);
|
||||
}
|
||||
|
||||
|
||||
static class Extensions {
|
||||
public static String widening(String string, long a) {
|
||||
return string + " " + a;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import lombok.experimental.ExtensionMethod;
|
||||
@ExtensionMethod({ExtensionMethodWidening.Extensions.class}) class ExtensionMethodWidening {
|
||||
static class Extensions {
|
||||
Extensions() {
|
||||
super();
|
||||
}
|
||||
public static String widening(String string, long a) {
|
||||
return ((string + " ") + a);
|
||||
}
|
||||
}
|
||||
ExtensionMethodWidening() {
|
||||
super();
|
||||
}
|
||||
public void test() {
|
||||
String string = "test";
|
||||
ExtensionMethodWidening.Extensions.widening(string, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import lombok.experimental.ExtensionMethod;
|
||||
|
||||
@ExtensionMethod({ExtensionMethodWidening.Extensions.class})
|
||||
class ExtensionMethodWidening {
|
||||
public void test() {
|
||||
String string = "test";
|
||||
string.widening(1);
|
||||
}
|
||||
|
||||
static class Extensions {
|
||||
public static String widening(String string, long a) {
|
||||
return string + " " + a;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user