nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: SpoonLabs/gumtree-spoon-ast-diff
Pull request #191 (2021-09-15 21:58:43)

fix: add support for parsing nested types in `RETURN_TYPE`
Reference: #183 

`RETURN_TYPE` couldn't be added to `TreeScanner` give its dependency on `computeTreeOfTypeReferences` which is in `NodeCreator`.

algomaster99: Another PR with a test case that could have been clubbed with other tests for nested type references. It may be a good idea to create a test suite whose sole purpose would be to test nested type references.

Patch:
diff --git a/src/main/java/gumtree/spoon/builder/NodeCreator.java b/src/main/java/gumtree/spoon/builder/NodeCreator.java
index 6870d80..d9eaf20 100644
--- a/src/main/java/gumtree/spoon/builder/NodeCreator.java
+++ b/src/main/java/gumtree/spoon/builder/NodeCreator.java
@@ -124,6 +124,7 @@ public class NodeCreator extends CtInheritanceScanner {
 			ITree returnType = builder.createNode("RETURN_TYPE", type.getQualifiedName());
 			returnType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, type);
 			type.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, returnType);
+			computeTreeOfTypeReferences(type, returnType);
 			builder.addSiblingNode(returnType);
 		}
 


Test patch:
diff --git a/src/test/java/gumtree/spoon/TreeTest.java b/src/test/java/gumtree/spoon/TreeTest.java
index 108eee8..e24c18a 100644
--- a/src/test/java/gumtree/spoon/TreeTest.java
+++ b/src/test/java/gumtree/spoon/TreeTest.java
@@ -568,4 +568,17 @@ public class TreeTest {
 
 		assertEquals(3, superInterfaces.getDescendants().size());
 	}
+
+	@Test
+	public void test_nestedReturnTypeOfMethodShouldGetParsed() throws Exception {
+		File file = new File("src/test/resources/examples/NestedReturnType.java");
+		AstComparator comparator = new AstComparator();
+		SpoonGumTreeBuilder scanner = new SpoonGumTreeBuilder();
+		ITree root = scanner.getTree(comparator.getCtType(file));
+		ITree method = root.getDescendants().stream().filter(iTree -> iTree.getLabel().equals("getIntegers")).findFirst().get();
+
+		ITree returnType = method.getChild(0);
+		assertEquals(1, returnType.getDescendants().size());
+		assertEquals("java.lang.Integer", returnType.getChild(0).getLabel());
+	}
 }
diff --git a/src/test/resources/examples/NestedReturnType.java b/src/test/resources/examples/NestedReturnType.java
new file mode 100644
index 0000000..19bbccf
--- /dev/null
+++ b/src/test/resources/examples/NestedReturnType.java
@@ -0,0 +1,8 @@
+import java.util.ArrayList;
+import java.util.List;
+
+class NestedReturnType {
+    List<Integer> getIntegers() {
+        return new ArrayList<Integer>();
+    }
+}