Skip to content

Commit

Permalink
fix test fieldReferenceWithTypeParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 committed Oct 27, 2023
1 parent 80f1664 commit 7d18400
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1877,17 +1877,7 @@ public J visitCallExpression(KtCallExpression expression, ExecutionContext data)
);
} else if (type == null || type == PsiElementAssociations.ExpressionType.METHOD_INVOCATION) {
J.Identifier name = (J.Identifier) expression.getCalleeExpression().accept(this, data);
JContainer<Expression> typeParams = null;

if (!expression.getTypeArguments().isEmpty()) {
List<JRightPadded<Expression>> parameters = new ArrayList<>(expression.getTypeArguments().size());
for (KtTypeProjection ktTypeProjection : expression.getTypeArguments()) {
parameters.add(padRight(convertToExpression(ktTypeProjection.accept(this, data)), suffix(ktTypeProjection)));
}

typeParams = JContainer.build(prefix(expression.getTypeArgumentList()), parameters, Markers.EMPTY);
}

JContainer<Expression> typeParams = mapTypeArguments(expression.getTypeArgumentList(), data);
JContainer<Expression> args = mapFunctionCallArguments(expression.getValueArgumentList(), expression.getValueArguments(), data);

if (expression.getValueArgumentList() == null) {
Expand All @@ -1906,12 +1896,37 @@ public J visitCallExpression(KtCallExpression expression, ExecutionContext data)
methodType
);
} else if (type == PsiElementAssociations.ExpressionType.QUALIFIER) {
throw new UnsupportedOperationException("Implement name references.");
TypeTree typeTree = (TypeTree) expression.getCalleeExpression().accept(this, data);
JContainer<Expression> typeParams = mapTypeArguments(expression.getTypeArgumentList(), data);

return new J.ParameterizedType(
randomId(),
prefix(expression),
Markers.EMPTY,
typeTree,
typeParams,
type(expression)
);
} else {
throw new UnsupportedOperationException("ExpressionType not found: " + expression.getCalleeExpression().getText());
}
}

@Nullable
JContainer<Expression> mapTypeArguments(@Nullable KtTypeArgumentList ktTypeArgumentList, ExecutionContext data) {
if (ktTypeArgumentList == null) {
return null;
}

List<KtTypeProjection> ktTypeProjections = ktTypeArgumentList.getArguments();
List<JRightPadded<Expression>> parameters = new ArrayList<>(ktTypeProjections.size());
for (KtTypeProjection ktTypeProjection : ktTypeProjections) {
parameters.add(padRight(convertToExpression(ktTypeProjection.accept(this, data)), suffix(ktTypeProjection)));
}

return JContainer.build(prefix(ktTypeArgumentList), parameters, Markers.EMPTY);
}

@Override
public J visitConstantExpression(KtConstantExpression expression, ExecutionContext data) {
IElementType elementType = expression.getElementType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void fieldReferenceWithTypeParameter() {
class Test < T: Number > ( val answer : T )
fun method ( ) {
val l = listOf ( Test ( 42 ) )
l . map { Test < Int > :: answer }
l . map { Test < Int > :: answer }
}
"""
)
Expand Down

0 comments on commit 7d18400

Please sign in to comment.