INRIA / spoon

Spoon is a metaprogramming library to analyze and transform Java source code. :spoon: is made with :heart:, :beers: and :sparkles:. It parses source files to build a well-designed AST with powerful analysis and transformation API.

Home Page:http://spoon.gforge.inria.fr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

tenax66 opened this issue · comments

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

import org.jspecify.annotations.Nullable;

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

Source code for your Spoon processing

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

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

Actual output

public class Foo {
    public Foo() {
    }

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

Expected output

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