[java-intentions] IDEA-304321 Fix "Create constructor" preview

GitOrigin-RevId: 3a473c492e709a280d8a06e7364a2af05babf37f
This commit is contained in:
Bart van Helvert
2022-10-31 11:40:45 +01:00
committed by intellij-monorepo-bot
parent 6359a7eeb5
commit a4bcded0bf
23 changed files with 28 additions and 27 deletions

View File

@@ -9,14 +9,13 @@ import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils
import com.intellij.codeInsight.daemon.impl.quickfix.GuessTypeParameters
import com.intellij.codeInsight.generation.OverrideImplementUtil
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo
import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils
import com.intellij.codeInsight.template.Template
import com.intellij.codeInsight.template.TemplateBuilder
import com.intellij.codeInsight.template.TemplateBuilderImpl
import com.intellij.codeInsight.template.TemplateEditingAdapter
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.lang.java.request.CreateConstructorFromJavaUsageRequest
import com.intellij.lang.jvm.actions.CreateConstructorRequest
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.*
@@ -41,8 +40,10 @@ internal class CreateConstructorAction(
private fun constructorRenderer(project: Project) = JavaConstructorRenderer(project, target, request)
override fun generatePreview(project: Project, editor: Editor, file: PsiFile): IntentionPreviewInfo {
val constructor = constructorRenderer(project).renderConstructor()
return IntentionPreviewInfo.CustomDiff(JavaFileType.INSTANCE, "", constructor.text)
val copyClass = PsiTreeUtil.findSameElementInCopy(target, file)
val javaFieldRenderer = JavaConstructorRenderer(project, copyClass, request)
javaFieldRenderer.doMagic()
return IntentionPreviewInfo.DIFF
}
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
@@ -107,7 +108,7 @@ private class JavaConstructorRenderer(
override fun templateFinished(template: Template, brokenOff: Boolean) {
if (brokenOff) return
WriteCommandAction.runWriteCommandAction(project) { setupBody() }
IntentionPreviewUtils.write<Throwable> { setupBody() }
}
private fun setupBody() {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public class Test {
public static void main() {
new MyCollection(10);

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public class Test {
public void main2() {
new MyCollection(this);

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Outer {
public Outer(String s) {
}

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test {
public void t() {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test extends A{
public Test(String a) {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test {
void foo() throws Ex1 {}
void bar() throws Ex2 {}

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test extends A{
public Test(String a) {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public enum ReportType {
AGING("Aging");

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public enum ReportType {
AGING("Aging"),
;

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class MyTest {
<T> T id(T t) {
return t;

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test extends A{
public Test(String a) {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public class Test {
public static void main() {
new My<caret>Collection(10);

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public class Test {
public void main2() {
new <caret>MyCollection(this);

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Outer {
public Outer(String s) {
}

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test {
public void t() {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test extends A{
public void t() {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test {
void foo() throws Ex1 {}
void bar() throws Ex2 {}

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test extends A{
public void t() {

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public enum ReportType {
AGING("Aging")<caret>
}

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
public enum ReportType {
AGING("Aging")<caret>,
}

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class MyTest {
<T> T id(T t) {
return t;

View File

@@ -1,4 +1,4 @@
// "Create constructor" "true"
// "Create constructor" "true-preview"
class Test extends A{
public void t() {