KT-4909 Smart completion does not work for named arguments

KT-7668 Named argument completion does not work after vararg

 #KT-4909 Fixed
 #KT-7668 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-05-07 19:48:52 +03:00
parent 58ac497bd7
commit 67cfd9d516
45 changed files with 474 additions and 215 deletions
@@ -69,7 +69,7 @@ public class Concat : IntrinsicMethod() {
codegen: ExpressionCodegen
): StackValue {
return StackValue.operation(returnType) {
val arguments = resolvedCall.getCall().getValueArguments().map { it.getArgumentExpression() }
val arguments = resolvedCall.getCall().getValueArguments().map { it.getArgumentExpression()!! }
val actualType = generateImpl(
codegen, it, returnType,
resolvedCall.getCall().getCallElement(),
@@ -48,7 +48,7 @@ public interface Call {
@ReadOnly
@NotNull
List<JetFunctionLiteralArgument> getFunctionLiteralArguments();
List<? extends FunctionLiteralArgument> getFunctionLiteralArguments();
@ReadOnly
@NotNull
@@ -19,14 +19,14 @@ package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode
import com.intellij.psi.PsiWhiteSpace
public class JetFunctionLiteralArgument(node: ASTNode) : JetValueArgument(node) {
public class JetFunctionLiteralArgument(node: ASTNode) : JetValueArgument(node), FunctionLiteralArgument {
private fun assertFL() = throw AssertionError("Function literal argument doesn't contain function literal expression: " +
"${super.getArgumentExpression()?.getText()} (it should be guaranteed by parser)")
"${super<JetValueArgument>.getArgumentExpression()?.getText()} (it should be guaranteed by parser)")
override fun getArgumentExpression() = super.getArgumentExpression() ?: assertFL()
override fun getArgumentExpression() = super<JetValueArgument>.getArgumentExpression() ?: assertFL()
public fun getFunctionLiteral(): JetFunctionLiteralExpression = unpackFunctionLiteral(getArgumentExpression())
override fun getFunctionLiteral(): JetFunctionLiteralExpression = unpackFunctionLiteral(getArgumentExpression())
private fun unpackFunctionLiteral(expression: JetExpression?): JetFunctionLiteralExpression =
when (expression) {
@@ -14,29 +14,29 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.psi;
package org.jetbrains.kotlin.psi
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.psi.impl.source.tree.LeafPsiElement
public interface ValueArgument {
@Nullable
@IfNotParsed
JetExpression getArgumentExpression();
public trait ValueArgument {
IfNotParsed
public fun getArgumentExpression(): JetExpression?
@Nullable
JetValueArgumentName getArgumentName();
public fun getArgumentName(): JetValueArgumentName?
boolean isNamed();
public fun isNamed(): Boolean
@NotNull
JetElement asElement();
public fun asElement(): JetElement
/* The '*' in something like foo(*arr) i.e. pass an array as a number of vararg arguments */
@Nullable
LeafPsiElement getSpreadElement();
public fun getSpreadElement(): LeafPsiElement?
/* The argument is placed externally to call element, e.g. in 'when' condition with subject: 'when (a) { in c -> }' */
boolean isExternal();
public fun isExternal(): Boolean
}
public trait FunctionLiteralArgument : ValueArgument {
public fun getFunctionLiteral(): JetFunctionLiteralExpression
override fun getArgumentExpression(): JetExpression
}
@@ -229,11 +229,11 @@ public class CallCompleter(
) {
if (valueArgument.isExternal()) return
val expression = valueArgument.getArgumentExpression()
val expression = valueArgument.getArgumentExpression() ?: return
val deparenthesized = ArgumentTypeResolver.getLastElementDeparenthesized(expression, context)
if (deparenthesized == null) return
val recordedType = expression?.let { context.trace.getType(it) }
val recordedType = expression.let { context.trace.getType(it) }
var updatedType: JetType? = recordedType
val results = completeCallForArgument(deparenthesized, context)
@@ -164,7 +164,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
@NotNull
@Override
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
public List<FunctionLiteralArgument> getFunctionLiteralArguments() {
return Collections.emptyList();
}
@@ -213,9 +213,9 @@ import static org.jetbrains.kotlin.resolve.calls.ValueArgumentsToParametersMappe
D candidate = candidateCall.getCandidateDescriptor();
List<ValueParameterDescriptor> valueParameters = candidate.getValueParameters();
List<JetFunctionLiteralArgument> functionLiteralArguments = call.getFunctionLiteralArguments();
List<? extends FunctionLiteralArgument> functionLiteralArguments = call.getFunctionLiteralArguments();
if (!functionLiteralArguments.isEmpty()) {
JetFunctionLiteralArgument functionLiteralArgument = functionLiteralArguments.get(0);
FunctionLiteralArgument functionLiteralArgument = functionLiteralArguments.get(0);
JetExpression possiblyLabeledFunctionLiteral = functionLiteralArgument.getArgumentExpression();
if (valueParameters.isEmpty()) {
@@ -162,7 +162,7 @@ public class CallMaker {
@NotNull
@Override
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
public List<FunctionLiteralArgument> getFunctionLiteralArguments() {
return Collections.emptyList();
}
@NotNull
@@ -301,7 +301,7 @@ public class CallMaker {
@Override
@NotNull
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
public List<? extends FunctionLiteralArgument> getFunctionLiteralArguments() {
return callElement.getFunctionLiteralArguments();
}
@@ -72,7 +72,7 @@ public class DelegatingCall implements Call {
@Override
@NotNull
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
public List<? extends FunctionLiteralArgument> getFunctionLiteralArguments() {
return delegate.getFunctionLiteralArguments();
}
@@ -214,7 +214,7 @@ public class ControlStructureTypingUtils {
@NotNull
@Override
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
public List<FunctionLiteralArgument> getFunctionLiteralArguments() {
return Collections.emptyList();
}