Change Signature: Avoid explicit Unit return type

This commit is contained in:
Alexey Sedunov
2015-07-07 17:36:17 +03:00
parent eb7463ed81
commit a96bd546a1
7 changed files with 27 additions and 2 deletions
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.ChangeSignaturePack
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetChangeInfo;
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo;
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar;
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
import org.jetbrains.kotlin.idea.util.ShortenReferences;
import org.jetbrains.kotlin.idea.util.ShortenReferences.Options;
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken;
@@ -236,7 +237,7 @@ public class JetCallableDefinitionUsage<T extends PsiElement> extends JetUsageIn
String returnTypeText = changeInfo.renderReturnType((JetCallableDefinitionUsage<PsiElement>) this);
//TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready
if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) {
if (!(returnTypeText.equals("Unit") || returnTypeText.equals("kotlin.Unit"))) {
ShortenPackage.addToShorteningWaitSet(
callable.setTypeReference(JetPsiFactory(callable).createType(returnTypeText)),
Options.DEFAULT
@@ -0,0 +1,5 @@
open class X: A() {
override fun foo() {
}
}
@@ -0,0 +1,5 @@
class A {
void <caret>foo() {
}
}
@@ -0,0 +1,5 @@
open class X: A() {
override fun foo() {
}
}
@@ -0,0 +1,5 @@
class A {
void <caret>foo() {
}
}
@@ -1,5 +1,5 @@
open class C: A() {
override fun foo(n: Int, s: String): Unit {
override fun foo(n: Int, s: String) {
}
@@ -1296,6 +1296,10 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
doTest(changeInfo);
}
public void testJavaMethodOverridesOmitUnitType() throws Exception {
doJavaTest(new JavaRefactoringProvider());
}
@NotNull
private LinkedHashSet<PsiMethod> findCallers(@NotNull PsiMethod method) {
KotlinMethodNode rootNode =