Java: don't suggest name starting with "get" when extract method from expression with void type (IDEA-293740)

GitOrigin-RevId: 9e685871187a33c9327835c466e83df4d9b55402
This commit is contained in:
Bas Leijdekkers
2025-03-20 18:24:49 +00:00
committed by intellij-monorepo-bot
parent 35aab21776
commit 9d6f3cd20a
2 changed files with 4 additions and 4 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.refactoring.extractMethod.newImpl
import com.intellij.codeInsight.Nullability
@@ -230,11 +230,11 @@ object ExtractMethodHelper {
fun guessMethodName(options: ExtractOptions): List<String> {
val project = options.project
val variableNames: MutableSet<String> = LinkedHashSet()
val codeStyleManager = JavaCodeStyleManager.getInstance(project) as JavaCodeStyleManagerImpl
val codeStyleManager = JavaCodeStyleManager.getInstance(project)
val returnType = options.dataOutput.type
val expression = options.elements.singleOrNull() as? PsiExpression
if (expression != null || returnType !is PsiPrimitiveType) {
if (expression != null && PsiTypes.voidType() != expression.type || returnType !is PsiPrimitiveType) {
codeStyleManager.suggestVariableName(VariableKind.FIELD, null, expression, returnType).names
.forEach { name ->
variableNames += codeStyleManager.variableNameToPropertyName(name, VariableKind.FIELD)
@@ -1,6 +1,6 @@
class Test {
private void getTest() {
private void extracted() {
test();
}