[jvm-lang] cleanup

- remove old JvmElementActionsFactory#createAddMethodActions;
- remove implementations of above method;
- remove MemberRequest.Method;
- remove actions.kt#createMethodAction.
This commit is contained in:
Daniil Ovchinnikov
2017-10-09 22:31:58 +03:00
parent cd6a54d4a8
commit 52da364caf
5 changed files with 3 additions and 157 deletions
@@ -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-2017 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.intention.IntentionAction
@@ -35,8 +21,6 @@ abstract class JvmElementActionsFactory {
open fun createAddConstructorActions(targetClass: JvmClass, request: MemberRequest.Constructor): List<IntentionAction> = emptyList()
open fun createAddMethodActions(targetClass: JvmClass, request: MemberRequest.Method): List<IntentionAction> = emptyList()
open fun createAddPropertyActions(targetClass: JvmClass, request: MemberRequest.Property): List<IntentionAction> = emptyList()
open fun createAddFieldActions(targetClass: JvmClass, request: CreateFieldRequest): List<IntentionAction> = emptyList()
@@ -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-2017 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.lang.jvm.JvmAnnotation
@@ -28,38 +14,8 @@ sealed class MemberRequest {
@JvmStatic
fun constructorRequest(parameters: List<JvmParameter>) =
Constructor(parameters = parameters)
@JvmStatic
fun simpleMethodRequest(methodName: String,
annotations: List<JvmAnnotation>,
modifier: List<JvmModifier>,
returnType: JvmType,
parameters: List<JvmParameter>) =
Method(name = methodName,
annotations = annotations,
modifiers = modifier,
returnType = returnType,
parameters = parameters)
@JvmStatic
fun simpleMethodRequest(methodName: String,
modifier: JvmModifier,
returnType: JvmType,
parameters: List<JvmParameter>) =
simpleMethodRequest(methodName, emptyList(), listOf(modifier), returnType, parameters)
}
class Method(
val name: String,
val annotations: List<JvmAnnotation> = emptyList(),
val modifiers: List<JvmModifier> = emptyList(),
val typeParameters: List<JvmTypeParameter> = emptyList(),
val returnType: JvmType,
val parameters: List<JvmParameter> = emptyList()
) : MemberRequest()
class Constructor(
val annotations: List<JvmAnnotation> = emptyList(),
val modifiers: List<JvmModifier> = emptyList(),
@@ -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-2017 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("JvmElementActionFactories")
package com.intellij.lang.jvm.actions
@@ -52,13 +38,6 @@ fun createConstructorActions(target: JvmClass, request: MemberRequest.Constructo
}
}
fun createMethodAction(target: JvmClass, request: MemberRequest.Method): IntentionAction? {
for (factory in EP_NAME.extensions) {
return factory.createAddMethodActions(target, request).firstOrNull() ?: continue
}
return null
}
fun createPropertyActions(target: JvmClass, request: MemberRequest.Property): List<IntentionAction> {
return createActions {
it.createAddPropertyActions(target, request)
@@ -1,10 +1,8 @@
// Copyright 2000-2017 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.codeInsight.intention.impl
import com.intellij.codeInsight.daemon.QuickFixBundle
import com.intellij.codeInsight.daemon.impl.quickfix.AddConstructorFix
import com.intellij.codeInsight.daemon.impl.quickfix.ModifierFix
import com.intellij.codeInsight.intention.AbstractIntentionAction
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.lang.java.JavaLanguage
import com.intellij.lang.java.actions.*
@@ -17,15 +15,9 @@ import com.intellij.lang.jvm.actions.CreateMethodRequest
import com.intellij.lang.jvm.actions.JvmElementActionsFactory
import com.intellij.lang.jvm.actions.MemberRequest
import com.intellij.lang.jvm.types.JvmType
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.*
import com.intellij.psi.codeStyle.JavaCodeStyleManager
import com.intellij.psi.impl.beanProperties.CreateJavaBeanPropertyFix
import com.intellij.psi.util.PsiFormatUtil
import com.intellij.psi.util.PsiFormatUtilBase
class JavaElementActionsFactory(private val renderer: JavaElementRenderer) : JvmElementActionsFactory() {
@@ -46,12 +38,6 @@ class JavaElementActionsFactory(private val renderer: JavaElementRenderer) : Jvm
}))
}
override fun createAddMethodActions(targetClass: JvmClass, request: MemberRequest.Method): List<IntentionAction> =
with(request) {
createAddMethodAction(targetClass, request)
?.let { listOf(it) } ?: emptyList()
}
override fun createAddPropertyActions(targetClass: JvmClass, request: MemberRequest.Property): List<IntentionAction> {
with(request) {
val psiClass = targetClass.toJavaClassOrNull() ?: return emptyList()
@@ -76,47 +62,6 @@ class JavaElementActionsFactory(private val renderer: JavaElementRenderer) : Jvm
}
}
private fun createAddMethodAction(psiClass: JvmClass, request: MemberRequest.Method): IntentionAction? {
with(request) {
val psiClass = psiClass.toJavaClassOrNull() ?: return null
val signatureString = with(renderer) {
val paramsString = parameters.mapIndexed { i, t -> "${render(t.type)} ${t.name ?: "arg$i"}" }.joinToString()
val modifiersString = (annotations.map { render(it) } + modifiers.map { render(it) }).joinToString(" ")
"${modifiersString} ${render(returnType)} $name($paramsString){}"
}
val targetClassPointer = SmartPointerManager.getInstance(psiClass.project).createSmartPsiElementPointer(psiClass)
return object : AbstractIntentionAction() {
private val text = targetClassPointer.element?.let { psiClass ->
QuickFixBundle.message("create.method.from.usage.text",
PsiFormatUtil.formatMethod(createMethod(psiClass), PsiSubstitutor.EMPTY,
PsiFormatUtilBase.SHOW_NAME or
PsiFormatUtilBase.SHOW_TYPE or
PsiFormatUtilBase.SHOW_PARAMETERS or
PsiFormatUtilBase.SHOW_RAW_TYPE,
PsiFormatUtilBase.SHOW_TYPE or PsiFormatUtilBase.SHOW_RAW_TYPE, 2))
} ?: ""
override fun getText(): String = text
override fun invoke(project: Project, editor: Editor?, file: PsiFile) {
val targetClass = targetClassPointer.element ?: return
runWriteAction {
val addedMethod = targetClass.add(createMethod(targetClass))
JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedMethod)
}
}
private fun createMethod(targetClass: PsiClass): PsiMethod {
val elementFactory = JVMElementFactories.getFactory(targetClass.language, targetClass.project) // it could be Groovy
?: JavaPsiFacade.getElementFactory(targetClass.project)
return elementFactory.createMethodFromText(signatureString, targetClass)
}
}
}
}
override fun createAddFieldActions(targetClass: JvmClass, request: CreateFieldRequest): List<IntentionAction> {
val javaClass = targetClass.toJavaClassOrNull() ?: return emptyList()
return listOf(
@@ -46,24 +46,6 @@ class UastJvmElementFactory(val renderer: JavaElementRenderer) : JvmElementActio
}
}
override fun createAddMethodActions(targetClass: JvmClass, request: MemberRequest.Method): List<IntentionAction> {
val project = (targetClass as? PsiElement)?.project ?: return emptyList()
val helper = JvmPsiConversionHelper.getInstance(project)
return with(request) {
getUastFactory(targetClass)?.createAddCallableMemberActions(
UastMethodInsertionInfo.Method(
targetClass.asUast(),
name,
modifiers.map { renderer.render(it) },
typeParameters.map(helper::convertTypeParameter),
helper.convertType(returnType),
parameters.map { it.asUast<UParameter>() },
modifiers.contains(JvmModifier.ABSTRACT)
)
) ?: emptyList()
}
}
override fun createAddMethodActions(targetClass: JvmClass, request: CreateMethodRequest): List<IntentionAction> {
val project = (targetClass as? PsiElement)?.project ?: return emptyList()
val helper = JvmPsiConversionHelper.getInstance(project)