mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
java: create constructor from usage: ensure parameter type is evaluated before constructor is inserted (IDEA-244902)
otherwise inference may detect overload conflict with existing no-arg constructor GitOrigin-RevId: bade4409a64e31bd0c7c4d79ffa41222b17a7c8f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fab2f3b722
commit
24cb042051
@@ -50,12 +50,15 @@ private class JavaConstructorRenderer(
|
||||
private val factory = JavaPsiFacade.getElementFactory(project)!!
|
||||
|
||||
fun doMagic() {
|
||||
//calculate expected parameter types before constructor is inserted
|
||||
//to avoid possible overload conflicts
|
||||
val parameters = request.expectedParameters
|
||||
var constructor = renderConstructor()
|
||||
constructor = insertConstructor(constructor)
|
||||
constructor = forcePsiPostprocessAndRestoreElement(constructor) ?: return
|
||||
|
||||
val builder = TemplateBuilderImpl(constructor)
|
||||
createTemplateContext(builder).setupParameters(constructor, request.expectedParameters)
|
||||
createTemplateContext(builder).setupParameters(constructor, parameters)
|
||||
val superConstructor = setupSuperCall(targetClass, constructor, builder)
|
||||
|
||||
constructor = forcePsiPostprocessAndRestoreElement(constructor) ?: return
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Create constructor" "true"
|
||||
class MyTest {
|
||||
<T> T id(T t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
{
|
||||
Foo f = new Foo(id("name"));
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
public Foo() {}
|
||||
|
||||
public Foo(String name) {
|
||||
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Create constructor" "true"
|
||||
class MyTest {
|
||||
<T> T id(T t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
{
|
||||
Foo f = new Foo(i<caret>d("name"));
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
public Foo() {}
|
||||
}
|
||||
Reference in New Issue
Block a user