mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java-intentions] IDEA-304321 Fix "Create constructor" preview
GitOrigin-RevId: 3a473c492e709a280d8a06e7364a2af05babf37f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6359a7eeb5
commit
a4bcded0bf
@@ -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() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public class Test {
|
||||
public static void main() {
|
||||
new MyCollection(10);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public class Test {
|
||||
public void main2() {
|
||||
new MyCollection(this);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Outer {
|
||||
public Outer(String s) {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test {
|
||||
|
||||
public void t() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test extends A{
|
||||
|
||||
public Test(String a) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test {
|
||||
void foo() throws Ex1 {}
|
||||
void bar() throws Ex2 {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test extends A{
|
||||
|
||||
public Test(String a) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public enum ReportType {
|
||||
AGING("Aging");
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public enum ReportType {
|
||||
AGING("Aging"),
|
||||
;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class MyTest {
|
||||
<T> T id(T t) {
|
||||
return t;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test extends A{
|
||||
|
||||
public Test(String a) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public class Test {
|
||||
public static void main() {
|
||||
new My<caret>Collection(10);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public class Test {
|
||||
public void main2() {
|
||||
new <caret>MyCollection(this);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Outer {
|
||||
public Outer(String s) {
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test {
|
||||
|
||||
public void t() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test extends A{
|
||||
|
||||
public void t() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test {
|
||||
void foo() throws Ex1 {}
|
||||
void bar() throws Ex2 {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test extends A{
|
||||
|
||||
public void t() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public enum ReportType {
|
||||
AGING("Aging")<caret>
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
public enum ReportType {
|
||||
AGING("Aging")<caret>,
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class MyTest {
|
||||
<T> T id(T t) {
|
||||
return t;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Create constructor" "true"
|
||||
// "Create constructor" "true-preview"
|
||||
class Test extends A{
|
||||
|
||||
public void t() {
|
||||
|
||||
Reference in New Issue
Block a user