From e35e6f7f52362777ea5ed7620ba1430630761c2a Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 21 Sep 2015 16:49:42 +0300 Subject: [PATCH] JetTypeCodeFragment: Remove usage of KotlinBuiltIns.getInstance() --- .../kotlin/psi/JetTypeCodeFragment.java | 12 ++---------- .../ui/JetChangeSignatureDialog.kt | 18 +++++++++--------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeCodeFragment.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeCodeFragment.java index b21a96eb44d..0537c2d0234 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeCodeFragment.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetTypeCodeFragment.java @@ -20,22 +20,14 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.JetNodeTypes; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; -import org.jetbrains.kotlin.types.JetType; public class JetTypeCodeFragment extends JetCodeFragment { public JetTypeCodeFragment(Project project, String name, CharSequence text, PsiElement context) { super(project, name, text, null, JetNodeTypes.TYPE_CODE_FRAGMENT, context); } - @Nullable - public JetType getType() { - JetElement typeReference = getContentElement(); - if (typeReference instanceof JetTypeReference) { - //TODO return the actual type - return KotlinBuiltIns.getInstance().getAnyType(); - } - return null; + public boolean hasTypeReference() { + return getContentElement() instanceof JetTypeReference; } @Nullable diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/JetChangeSignatureDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/JetChangeSignatureDialog.kt index 17bdca71e47..aa61451270b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/JetChangeSignatureDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/ui/JetChangeSignatureDialog.kt @@ -51,13 +51,13 @@ import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetMethodDescriptor import org.jetbrains.kotlin.psi.JetExpressionCodeFragment import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetTypeCodeFragment -import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import java.awt.BorderLayout import java.awt.Font import java.awt.Toolkit import java.awt.event.ItemEvent import java.awt.event.ItemListener -import java.util.ArrayList +import java.util.* import javax.swing.* public class JetChangeSignatureDialog( @@ -78,8 +78,6 @@ public class JetChangeSignatureDialog( override fun createReturnTypeCodeFragment() = createReturnTypeCodeFragment(myProject, myMethod) - public fun getReturnType(): JetType? = getType(myReturnTypeCodeFragment as JetTypeCodeFragment?) - private val parametersTableModel: JetCallableParameterTableModel get() = super.myParametersTableModel override fun getRowPresentation(item: ParameterTableModelItemBase, selected: Boolean, focused: Boolean): JComponent? { @@ -337,7 +335,7 @@ public class JetChangeSignatureDialog( throw ConfigurationException(JetRefactoringBundle.message("function.name.is.invalid")) } - if (myMethod.canChangeReturnType() === MethodDescriptor.ReadWriteOption.ReadWrite && getReturnType() == null) { + if (myMethod.canChangeReturnType() === MethodDescriptor.ReadWriteOption.ReadWrite && !hasTypeReference(myReturnTypeCodeFragment)) { throw ConfigurationException(JetRefactoringBundle.message("return.type.is.invalid")) } @@ -351,7 +349,7 @@ public class JetChangeSignatureDialog( throw ConfigurationException(JetRefactoringBundle.message("parameter.name.is.invalid", parameterName)) } - if (getType(item.typeCodeFragment as JetTypeCodeFragment) == null) { + if (!hasTypeReference(item.typeCodeFragment)) { throw ConfigurationException(JetRefactoringBundle.message("parameter.type.is.invalid", item.typeCodeFragment.getText())) } } @@ -387,8 +385,6 @@ public class JetChangeSignatureDialog( private fun createReturnTypeCodeFragment(project: Project, method: JetMethodDescriptor) = JetPsiFactory(project).createTypeCodeFragment(method.renderOriginalReturnType(), method.baseDeclaration) - private fun getType(typeCodeFragment: JetTypeCodeFragment?) = typeCodeFragment?.getType() - public fun createRefactoringProcessorForSilentChangeSignature(project: Project, commandName: String, method: JetMethodDescriptor, @@ -424,7 +420,8 @@ public class JetChangeSignatureDialog( } val returnTypeText = if (returnTypeCodeFragment != null) returnTypeCodeFragment.getText().trim() else "" - val returnType = getType(returnTypeCodeFragment as JetTypeCodeFragment?) + //TODO return the actual type + val returnType = if (hasTypeReference(returnTypeCodeFragment)) methodDescriptor.baseDescriptor.builtIns.anyType else null return JetChangeInfo(methodDescriptor.original, methodName, returnType, @@ -434,5 +431,8 @@ public class JetChangeSignatureDialog( parametersModel.getReceiver(), defaultValueContext) } + + private fun hasTypeReference(codeFragment: PsiCodeFragment?): Boolean + = (codeFragment as? JetTypeCodeFragment)?.hasTypeReference() ?: false } }