Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support argument widening for extension methods #3478

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -64,7 +64,6 @@
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;

Expand Down Expand Up @@ -346,13 +345,7 @@ public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend meth
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
18 changes: 18 additions & 0 deletions test/transform/resource/after-ecj/ExtensionMethodWidening.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
15 changes: 15 additions & 0 deletions test/transform/resource/before/ExtensionMethodWidening.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Loading