Skip to content

Commit

Permalink
Fix for type arguments of the generic functions in jdt (#327)
Browse files Browse the repository at this point in the history
* fix: add typeArguments subtrees to the receiver of the method invocation for jdt

* add test for typeArguments of the method invocation in jdt
  • Loading branch information
pouryafard75 authored Jan 20, 2024
1 parent c5f4dc5 commit 190aed8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public boolean visit(MethodInvocation i) {
push(i, METHOD_INVOCATION_RECEIVER, "", i.getExpression().getStartPosition(),
i.getExpression().getLength());
i.getExpression().accept(this);
for (Object argument : i.typeArguments()) {
((ASTNode) argument).accept(this);
}
popNode();
}
pushNode(i.getName(), getLabel(i.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,26 @@ public void testIds() throws IOException {
assertEquals(ct.getRoot().getChild("0.3").getMetadata("id"), "Method foo( int String)");
assertEquals(ct.getRoot().getChild("0.4").getMetadata("id"), "Method bar()");
}

@Test
public void testGenericFunctionWithTypeParameter() throws IOException {
String input = "class testStructure { void foo() { Collections.<String>emptyList(); } }";
TreeContext ct = new JdtTreeGenerator().generateFrom().string(input);
String expected = "CompilationUnit [0,71]\n"
+ " TypeDeclaration [0,71]\n"
+ " TYPE_DECLARATION_KIND: class [0,5]\n"
+ " SimpleName: testStructure [6,19]\n"
+ " MethodDeclaration [22,69]\n"
+ " PrimitiveType: void [22,26]\n"
+ " SimpleName: foo [27,30]\n"
+ " Block [33,69]\n"
+ " ExpressionStatement [35,67]\n"
+ " MethodInvocation [35,66]\n"
+ " METHOD_INVOCATION_RECEIVER [35,46]\n"
+ " SimpleName: Collections [35,46]\n"
+ " SimpleType [48,54]\n"
+ " SimpleName: String [48,54]\n"
+ " SimpleName: emptyList [55,64]";
assertEquals(expected, ct.getRoot().toTreeString());
}
}

0 comments on commit 190aed8

Please sign in to comment.