From e74aa2d8643178df5b06eb985f7efb9a4a01b55c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 3 Dec 2014 17:23:28 +0100 Subject: [PATCH] extract method: do not suggest primitive type when 'return null;' should be inserted --- .../refactoring/extractMethod/ExtractMethodDialog.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java index 4df8907a2227..70b6536c3cf9 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/extractMethod/ExtractMethodDialog.java @@ -31,6 +31,7 @@ import com.intellij.psi.*; import com.intellij.psi.util.PsiFormatUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.ui.*; import com.intellij.refactoring.util.ConflictsUtil; @@ -241,6 +242,9 @@ public class ExtractMethodDialog extends DialogWrapper implements AbstractExtrac @Nullable private JPanel createReturnTypePanel() { + if (TypeConversionUtil.isPrimitiveWrapper(myReturnType) && myNullness == Nullness.NULLABLE) { + return null; + } mySelector = new TypeSelectorManagerImpl(myProject, myReturnType, findOccurrences(), areTypesDirected()).getTypeSelector(); final JComponent component = mySelector.getComponent(); if (component instanceof JComboBox) { @@ -532,7 +536,7 @@ public class ExtractMethodDialog extends DialogWrapper implements AbstractExtrac buffer.append(myTargetClass.getName()); } else { - buffer.append(PsiFormatUtil.formatType(mySelector.getSelectedType(), 0, PsiSubstitutor.EMPTY)); + buffer.append(PsiFormatUtil.formatType(mySelector != null ? mySelector.getSelectedType() : myReturnType, 0, PsiSubstitutor.EMPTY)); buffer.append(" "); buffer.append(myNameField.getText()); } @@ -602,6 +606,6 @@ public class ExtractMethodDialog extends DialogWrapper implements AbstractExtrac } public PsiType getReturnType() { - return mySelector.getSelectedType(); + return mySelector != null ? mySelector.getSelectedType() : myReturnType; } }