mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: fix input parameters in dialog
GitOrigin-RevId: acbbcc10070531b1ca1427c6e44c23cc6f5a5adc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
aac4abdfff
commit
c8decba90a
+3
-4
@@ -36,6 +36,9 @@ object ExtractMethodPipeline {
|
||||
): ExtractOptions {
|
||||
val analyzer = CodeFragmentAnalyzer(extractOptions.elements)
|
||||
var options = withMappedName(extractOptions, methodName)
|
||||
if (isStatic && ! options.isStatic) {
|
||||
options = withForcedStatic(analyzer, options) ?: options
|
||||
}
|
||||
options = withMappedParametersInput(options, variableData.toList())
|
||||
val targetClass = extractOptions.anchor.containingClass!!
|
||||
options = if (targetClass.isInterface) {
|
||||
@@ -44,10 +47,6 @@ object ExtractMethodPipeline {
|
||||
options.copy(visibility = visibility)
|
||||
}
|
||||
|
||||
if (isStatic && ! options.isStatic) {
|
||||
options = withForcedStatic(analyzer, options) ?: options
|
||||
}
|
||||
|
||||
if (isConstructor) {
|
||||
options = asConstructor(analyzer, options) ?: options
|
||||
} else {
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
package com.intellij.refactoring.extractMethod.newImpl
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtil
|
||||
import com.intellij.codeInsight.Nullability
|
||||
import com.intellij.codeInsight.generation.GenerateMembersUtil
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager
|
||||
import com.intellij.psi.codeStyle.VariableKind
|
||||
import com.intellij.psi.impl.source.codeStyle.JavaCodeStyleManagerImpl
|
||||
import com.intellij.psi.search.LocalSearchScope
|
||||
import com.intellij.refactoring.HelpID
|
||||
import com.intellij.refactoring.extractMethod.ExtractMethodDialog
|
||||
import com.intellij.refactoring.extractMethod.InputVariables
|
||||
import com.intellij.refactoring.extractMethod.newImpl.structures.DataOutput
|
||||
@@ -39,17 +37,22 @@ object MapFromDialog {
|
||||
val elements = extractOptions.elements.toTypedArray()
|
||||
val nullability = extractOptions.dataOutput.nullability
|
||||
val analyzer = CodeFragmentAnalyzer(extractOptions.elements)
|
||||
val staticOptions = ExtractMethodPipeline.withForcedStatic(analyzer, extractOptions)
|
||||
val canBeStatic = ExtractMethodPipeline.withForcedStatic(analyzer, extractOptions) != null
|
||||
val canBeChainedConstructor = ExtractMethodPipeline.canBeConstructor(analyzer)
|
||||
val factory = PsiElementFactory.getInstance(project)
|
||||
val variables = extractOptions.inputParameters
|
||||
.map { it.references.first() as? PsiReferenceExpression }
|
||||
.map { it?.resolve() as? PsiVariable }
|
||||
.map { factory.createVariableDeclarationStatement(it.name, it.type, null, it.references.first().context) }
|
||||
.map { declaration -> declaration.declaredElements[0] as PsiVariable }
|
||||
val parameterNames = extractOptions.inputParameters.map { it.name }.toSet()
|
||||
val fields = staticOptions?.inputParameters.orEmpty()
|
||||
.filterNot { it.name in parameterNames }.map { factory.createField(it.name, it.type) }.toSet()
|
||||
val inputVariables = InputVariables(
|
||||
variables,
|
||||
extractOptions.project,
|
||||
LocalSearchScope(extractOptions.elements.toTypedArray()),
|
||||
false,
|
||||
emptySet()
|
||||
fields
|
||||
)
|
||||
val typeParameterList = PsiElementFactory.getInstance(extractOptions.project).createTypeParameterList()
|
||||
typeParameters.forEach { typeParameterList.add(it) }
|
||||
|
||||
Reference in New Issue
Block a user