Skip to content

Commit

Permalink
support wildcard type
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 committed Oct 8, 2023
1 parent d93bbed commit fc1afa9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,15 @@ public J visitTypeParameterList(KtTypeParameterList list, ExecutionContext data)

@Override
public J visitTypeProjection(KtTypeProjection typeProjection, ExecutionContext data) {
return typeProjection.getTypeReference().accept(this, data);
if (typeProjection.getTypeReference() != null) {
return typeProjection.getTypeReference().accept(this, data);
}

if (typeProjection.getProjectionKind() == KtProjectionKind.STAR) {
return new J.Wildcard(randomId(), prefix(typeProjection), Markers.EMPTY, null, null);
}

throw new UnsupportedOperationException("TODO");
}

@Override
Expand Down Expand Up @@ -1872,11 +1880,29 @@ public J visitTypeReference(KtTypeReference typeReference, ExecutionContext data

@Override
public J visitUserType(KtUserType type, ExecutionContext data) {
if (!type.getTypeArguments().isEmpty()) {
throw new UnsupportedOperationException("TODO");

NameTree nameTree = type.getReferenceExpression().accept(this, data).withPrefix(prefix(type));

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

return new J.ParameterizedType(
randomId(),
Space.EMPTY,
Markers.EMPTY,
nameTree,
JContainer.build(prefix(type.getTypeArgumentList()), parameters, Markers.EMPTY),
type(type)
);
}


// TODO: fix NPE.
return type.getReferenceExpression().accept(this, data);
return nameTree;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Test < T >
kotlin(
"""
import org.foo.Test
val a : Test < * > = null
val a : Test < * > = null
"""
)
);
Expand Down

0 comments on commit fc1afa9

Please sign in to comment.