diff --git a/java/java-analysis-impl/src/com/intellij/lang/jvm/actions/commonActionTypes.kt b/java/java-analysis-impl/src/com/intellij/lang/jvm/actions/commonActionTypes.kt new file mode 100644 index 000000000000..7b2056ae5733 --- /dev/null +++ b/java/java-analysis-impl/src/com/intellij/lang/jvm/actions/commonActionTypes.kt @@ -0,0 +1,34 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.lang.jvm.actions + +import com.intellij.codeInsight.daemon.QuickFixBundle.message + +object CreateMethodActionGroup : JvmActionGroup { + override fun getDisplayText(data: JvmActionGroup.RenderData?): String { + return message("create.method.from.usage.text", requireNotNull(data?.entityName)) + } +} + +object CreateAbstractMethodActionGroup : JvmActionGroup { + override fun getDisplayText(data: JvmActionGroup.RenderData?): String { + return message("create.abstract.method.from.usage.text", requireNotNull(data?.entityName)) + } +} + +object CreateFieldActionGroup : JvmActionGroup { + override fun getDisplayText(data: JvmActionGroup.RenderData?): String { + return message("create.field.from.usage.text", requireNotNull(data?.entityName)) + } +} + +object CreateConstantActionGroup : JvmActionGroup { + override fun getDisplayText(data: JvmActionGroup.RenderData?): String { + return message("create.constant.from.usage.text", requireNotNull(data?.entityName)) + } +} + +object CreateEnumConstantActionGroup : JvmActionGroup { + override fun getDisplayText(data: JvmActionGroup.RenderData?): String { + return message("create.enum.constant.from.usage.text", requireNotNull(data?.entityName)) + } +} diff --git a/java/java-impl/src/com/intellij/lang/java/actions/CreateEnumConstantAction.kt b/java/java-impl/src/com/intellij/lang/java/actions/CreateEnumConstantAction.kt index e835284ea9af..68197b748c88 100644 --- a/java/java-impl/src/com/intellij/lang/java/actions/CreateEnumConstantAction.kt +++ b/java/java-impl/src/com/intellij/lang/java/actions/CreateEnumConstantAction.kt @@ -8,8 +8,10 @@ import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageBaseFix.posi import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageBaseFix.startTemplate import com.intellij.codeInsight.daemon.impl.quickfix.EmptyExpression import com.intellij.codeInsight.template.TemplateBuilderImpl +import com.intellij.lang.jvm.actions.CreateEnumConstantActionGroup import com.intellij.lang.jvm.actions.CreateFieldRequest import com.intellij.lang.jvm.actions.ExpectedTypes +import com.intellij.lang.jvm.actions.JvmActionGroup import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.psi.JavaPsiFacade @@ -23,7 +25,7 @@ internal class CreateEnumConstantAction( override val request: CreateFieldRequest ) : CreateFieldActionBase(target, request) { - override fun getFamilyName(): String = QuickFixBundle.message("create.field.from.usage.family") + override fun getActionGroup(): JvmActionGroup = CreateEnumConstantActionGroup override fun getText(): String = QuickFixBundle.message("create.enum.constant.from.usage.text", request.fieldName) diff --git a/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldAction.kt b/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldAction.kt index 0fb49784a511..ecddb0bc7e6e 100644 --- a/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldAction.kt +++ b/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldAction.kt @@ -9,7 +9,7 @@ import com.intellij.codeInsight.template.Template import com.intellij.codeInsight.template.TemplateEditingAdapter import com.intellij.lang.java.request.CreateFieldFromJavaUsageRequest import com.intellij.lang.jvm.JvmModifier -import com.intellij.lang.jvm.actions.CreateFieldRequest +import com.intellij.lang.jvm.actions.* import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project @@ -23,7 +23,9 @@ internal class CreateFieldAction( target: PsiClass, request: CreateFieldRequest, private val constantField: Boolean -) : CreateFieldActionBase(target, request) { +) : CreateFieldActionBase(target, request), JvmGroupIntentionAction { + + override fun getActionGroup(): JvmActionGroup = if (constantField) CreateConstantActionGroup else CreateFieldActionGroup override fun getText(): String { val what = request.fieldName diff --git a/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldActionBase.kt b/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldActionBase.kt index 6e5d8b0ea331..85750a6ec42f 100644 --- a/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldActionBase.kt +++ b/java/java-impl/src/com/intellij/lang/java/actions/CreateFieldActionBase.kt @@ -3,12 +3,16 @@ package com.intellij.lang.java.actions import com.intellij.codeInsight.daemon.QuickFixBundle.message import com.intellij.lang.jvm.actions.CreateFieldRequest +import com.intellij.lang.jvm.actions.JvmActionGroup +import com.intellij.lang.jvm.actions.JvmGroupIntentionAction import com.intellij.psi.PsiClass internal abstract class CreateFieldActionBase( target: PsiClass, override val request: CreateFieldRequest -) : CreateMemberAction(target, request) { +) : CreateMemberAction(target, request), JvmGroupIntentionAction { + + override fun getRenderData() = JvmActionGroup.RenderData { request.fieldName } override fun getFamilyName(): String = message("create.field.from.usage.family") } diff --git a/java/java-impl/src/com/intellij/lang/java/actions/CreateMemberAction.kt b/java/java-impl/src/com/intellij/lang/java/actions/CreateMemberAction.kt index 92879f4c0f54..4347bbea4961 100644 --- a/java/java-impl/src/com/intellij/lang/java/actions/CreateMemberAction.kt +++ b/java/java-impl/src/com/intellij/lang/java/actions/CreateMemberAction.kt @@ -2,6 +2,7 @@ package com.intellij.lang.java.actions import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.lang.jvm.JvmClass import com.intellij.lang.jvm.actions.ActionRequest import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project @@ -26,6 +27,8 @@ internal abstract class CreateMemberAction( "Don't access this property if isAvailable() returned false" } + open fun getTarget(): JvmClass = target + override fun getElementToMakeWritable(currentFile: PsiFile): PsiElement? = target override fun startInWriteAction(): Boolean = true diff --git a/java/java-impl/src/com/intellij/lang/java/actions/CreateMethodAction.kt b/java/java-impl/src/com/intellij/lang/java/actions/CreateMethodAction.kt index b216454b4e46..f51bf6dd6f5a 100644 --- a/java/java-impl/src/com/intellij/lang/java/actions/CreateMethodAction.kt +++ b/java/java-impl/src/com/intellij/lang/java/actions/CreateMethodAction.kt @@ -14,7 +14,7 @@ import com.intellij.codeInsight.template.TemplateBuilderImpl import com.intellij.codeInsight.template.TemplateEditingAdapter import com.intellij.lang.java.request.CreateMethodFromJavaUsageRequest import com.intellij.lang.jvm.JvmModifier -import com.intellij.lang.jvm.actions.CreateMethodRequest +import com.intellij.lang.jvm.actions.* import com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project @@ -30,12 +30,16 @@ internal class CreateMethodAction( targetClass: PsiClass, override val request: CreateMethodRequest, private val abstract: Boolean -) : CreateMemberAction(targetClass, request) { +) : CreateMemberAction(targetClass, request), JvmGroupIntentionAction { + + override fun getActionGroup(): JvmActionGroup = if (abstract) CreateAbstractMethodActionGroup else CreateMethodActionGroup override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean { return super.isAvailable(project, editor, file) && PsiNameHelper.getInstance(project).isIdentifier(request.methodName) } + override fun getRenderData() = JvmActionGroup.RenderData { request.methodName } + override fun getFamilyName(): String = message("create.method.from.usage.family") override fun getText(): String { diff --git a/java/java-impl/src/com/intellij/lang/java/request/createFieldFromUsage.kt b/java/java-impl/src/com/intellij/lang/java/request/createFieldFromUsage.kt index cc2898d1af4b..f72567da35eb 100644 --- a/java/java-impl/src/com/intellij/lang/java/request/createFieldFromUsage.kt +++ b/java/java-impl/src/com/intellij/lang/java/request/createFieldFromUsage.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. @file:JvmName("CreateFieldFromUsage") package com.intellij.lang.java.request @@ -25,6 +11,7 @@ import com.intellij.lang.jvm.JvmClassKind import com.intellij.lang.jvm.JvmModifier import com.intellij.lang.jvm.actions.CreateFieldRequest import com.intellij.lang.jvm.actions.EP_NAME +import com.intellij.lang.jvm.actions.groupActionsByType import com.intellij.psi.* import com.intellij.psi.util.PsiUtil.resolveClassInClassTypeOnly import com.intellij.psi.util.parentOfType @@ -37,7 +24,7 @@ fun generateActions(ref: PsiReferenceExpression): List { extensions.flatMap { ext -> ext.createAddFieldActions(clazz, request) } - } + }.groupActionsByType() } private fun checkReference(ref: PsiReferenceExpression): Boolean { diff --git a/java/java-impl/src/com/intellij/lang/java/request/createMethodFromUsage.kt b/java/java-impl/src/com/intellij/lang/java/request/createMethodFromUsage.kt index 8ecdde8b7731..3608197bfd19 100644 --- a/java/java-impl/src/com/intellij/lang/java/request/createMethodFromUsage.kt +++ b/java/java-impl/src/com/intellij/lang/java/request/createMethodFromUsage.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. @file:JvmName("CreateMethodFromUsage") package com.intellij.lang.java.request @@ -24,6 +10,7 @@ import com.intellij.lang.jvm.JvmClass import com.intellij.lang.jvm.JvmModifier import com.intellij.lang.jvm.actions.CreateMethodRequest import com.intellij.lang.jvm.actions.EP_NAME +import com.intellij.lang.jvm.actions.groupActionsByType import com.intellij.psi.PsiClass import com.intellij.psi.PsiJavaCodeReferenceElement import com.intellij.psi.PsiMethodCallExpression @@ -38,7 +25,7 @@ fun generateActions(call: PsiMethodCallExpression): List { extensions.flatMap { ext -> ext.createAddMethodActions(clazz, request) } - } + }.groupActionsByType() } private fun checkCall(call: PsiMethodCallExpression): Boolean { @@ -90,4 +77,3 @@ private class CreateMethodRequests(val myCall: PsiMethodCallExpression) { myRequests[clazz] = CreateMethodFromJavaUsageRequest(myCall, modifiers) } } - diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/afterMethodTypeParamWithNestedClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/afterMethodTypeParamWithNestedClass.java index 69bd79430c93..84d779f7fc61 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/afterMethodTypeParamWithNestedClass.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/afterMethodTypeParamWithNestedClass.java @@ -1,4 +1,4 @@ -// "Create method 'f' in 'Nested in aMethod() in CreateMethodTest'" "true" +// "Create method 'f'" "true" public class CreateMethodTest { public void aMethod(final T t) { class Nested { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/beforeMethodTypeParamWithNestedClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/beforeMethodTypeParamWithNestedClass.java index 567f85f36ad8..8af01540f705 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/beforeMethodTypeParamWithNestedClass.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage/beforeMethodTypeParamWithNestedClass.java @@ -1,4 +1,4 @@ -// "Create method 'f' in 'Nested in aMethod() in CreateMethodTest'" "true" +// "Create method 'f'" "true" public class CreateMethodTest { public void aMethod(final T t) { class Nested {