diff --git a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt index 0907cc40cfdc..0905af3cea5f 100644 --- a/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt +++ b/java/java-impl-refactorings/src/com/intellij/refactoring/extractMethod/newImpl/ExtractMethodHelper.kt @@ -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 { val project = options.project val variableNames: MutableSet = 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) diff --git a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/ExtractMethodFromClassContext_after.java b/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/ExtractMethodFromClassContext_after.java index 9b33b310e6cf..469abf973479 100644 --- a/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/ExtractMethodFromClassContext_after.java +++ b/java/java-tests/testData/refactoring/extractMethodAndDuplicatesInplace/ExtractMethodFromClassContext_after.java @@ -1,6 +1,6 @@ class Test { - private void getTest() { + private void extracted() { test(); }