INRIA / INRIA/spoon

Bug: Printer fails to write generics for superclasses after setting it

Open
#4,057 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

```java
@Test
void test() {
CtType type = Launcher.parseClass("class Foo {}");
CtType foo = type.getReference().getTypeDeclaration();
type.setSuperclass(foo.getReference());
List typeParameters = type.getSuperclass().getTypeDeclaration().getFormalCtTypeParameters(); // has size 1
String printedClass = type.toString(); // drops the generic type on the extended class. output: "class Foo extends Foo {}"
}
```
The example above shows the problem. The expected output is `class Foo extends Foo {}` but currently the printer drops the generic type. After some debugging I found something, that could be the problem:
[ElementPrinterHelper](https://github.com/INRIA/spoon/blob/e8a1596aa29d8d34f84087fb0dbce1d032b2259f/src/main/java/spoon/reflect/visitor/ElementPrinterHelper.java#L250) `final Collection> arguments = ctGenericElementReference.getActualTypeArguments();`returns an empty list.
This looks like not a printer related problem, but more like a problem in setting a generic super class. Did I miss some method for setting a generic superclass explicitly with parameters? The type parameters for the super class are strangely correct in the model.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.