INRIA / INRIA/spoon

[Bug]: `JavaReflectionTreeBuilder` doesn't build annotations on the return type

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

Description

### Describe the bug

`JavaReflectionTreeBuilder` builds usual annotations but not annotations applied to a return type.

I found this while working on #5320 .
`JavaReflectionTreeBuilderTest` fails after the `@Nullable` annotation is applied to the classes under some specific packages. (like `spoon.reflect.code`, `spoon.reflect.declaration`)

### Source code you are trying to analyze/transform

```Java
import org.jspecify.annotations.Nullable;

public class Foo {
public @Nullable String test() {
return null;
}
}
```

### Source code for your Spoon processing

```Java
public static void main(String[] args) {
JavaReflectionTreeBuilder builder = new JavaReflectionTreeBuilder(
new FactoryImpl(new DefaultCoreFactory(), new StandardEnvironment()));

CtType result = builder.scan(Foo.class);
System.out.println(result.toString());
}
```

### Actual output

```Java
public class Foo {
public Foo() {
}

public java.lang.String test() {
}
}
```

### Expected output

```Java
public class Foo {
public Foo() {
}

public @org.jspecify.annotations.Nullable() java.lang.String test() {
}
}
```

### Spoon Version

10.4.2

### JVM Version

penjdk 17.0.7 2023-04-18 OpenJDK Runtime Environment Homebrew (build 17.0.7+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.7+0, mixed mode, sharing)

### What operating system are you using?

macOS Ventura 13.2.1

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.