Change Signature: Fix processing of lambda arguments

This commit is contained in:
Alexey Sedunov
2015-03-30 19:08:49 +03:00
parent 61d0bcdf76
commit d65b55e147
17 changed files with 204 additions and 51 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
@@ -65,4 +66,8 @@ public class JetTypeReference extends JetElementImplStub<KotlinPlaceHolderStub<J
}
return answer != null ? answer : Collections.<JetAnnotationEntry>emptyList();
}
public boolean hasParentheses() {
return findChildByType(JetTokens.LPAR) != null && findChildByType(JetTokens.LPAR) != null;
}
}
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.psi.JetPsiFactory
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.PsiErrorElement
import org.jetbrains.kotlin.psi.JetCallableDeclaration
import org.jetbrains.kotlin.psi.JetFunctionType
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
fun getTypeReference(declaration: JetCallableDeclaration): JetTypeReference? {
@@ -56,17 +57,25 @@ fun setTypeReference(declaration: JetCallableDeclaration, addAfter: PsiElement?,
}
fun JetCallableDeclaration.setReceiverTypeReference(typeRef: JetTypeReference?): JetTypeReference? {
val needParentheses = typeRef != null && typeRef.getTypeElement() is JetFunctionType && !typeRef.hasParentheses()
val oldTypeRef = getReceiverTypeReference()
if (typeRef != null) {
if (oldTypeRef != null) {
return oldTypeRef.replace(typeRef) as JetTypeReference
}
else {
val anchor = getNameIdentifier()
val newTypeRef = addBefore(typeRef, anchor) as JetTypeReference
addAfter(JetPsiFactory(getProject()).createDot(), newTypeRef)
return newTypeRef
val newTypeRef =
if (oldTypeRef != null) {
oldTypeRef.replace(typeRef) as JetTypeReference
}
else {
val anchor = getNameIdentifier()
val newTypeRef = addBefore(typeRef, anchor) as JetTypeReference
addAfter(JetPsiFactory(getProject()).createDot(), newTypeRef)
newTypeRef
}
if (needParentheses) {
val argList = JetPsiFactory(getProject()).createCallArguments("()")
newTypeRef.addBefore(argList.getLeftParenthesis()!!, newTypeRef.getFirstChild())
newTypeRef.add(argList.getRightParenthesis()!!)
}
return newTypeRef
}
else {
if (oldTypeRef != null) {
@@ -76,7 +76,7 @@ public fun <C: ResolutionContext<C>> Call.hasUnresolvedArguments(context: Resolu
public fun Call.getValueArgumentsInParentheses(): List<ValueArgument> = getValueArguments().filterArgsInParentheses()
public fun JetCallExpression.getValueArgumentsInParentheses(): List<ValueArgument> = getValueArguments().filterArgsInParentheses()
public fun JetCallElement.getValueArgumentsInParentheses(): List<ValueArgument> = getValueArguments().filterArgsInParentheses()
public fun Call.getValueArgumentListOrElement(): JetElement = getValueArgumentList() ?: getCalleeExpression() ?: getCallElement()