INRIA / INRIA/spoon

Auto-import classes that only are only referenced in Javadoc

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

Description

I have attempted to transform existing code and copy its javadoc, but its javadoc links a class which isn't imported automatically when pretty-printing since it doesn't appear in the source code.
This causes the javadoc to fail compiling.

**To Reproduce**

Input:
```java
import some.package.B;
interface A {
/**
* {@link B}
*/
public String someMethod();
}
```

Processing with Spoon:
```java
Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImport(true);
launcher.addInputResource(somePath);
launcher.setSourceOutputDirectory(someOtherPath);
// My processor which isn't that interesting
launcher.addProcessor(new FuturifyProcessor());
launcher.run()
```

Output:
```java
import java.util.concurrent.Future;
interface AsyncA {
/**
* {@link B}
*/
public Future someMethod();
}
```

How can I get the output to be
```java
import java.util.concurrent.Future;
import some.package.B;
interface AsyncA {
/**
* {@link B}
*/
public Future someMethod();
}
```

I am also fine with simply maintaining the same imports and manually add the one new import I know will be added, which is `import java.util.concurrent.Future`

**Operating system, JDK and Spoon version used**

* OS: Windows 10
* JDK: 1.8
* Spoon version: 8.3.0

Contributor guide

Open the contributing guide

Research direction

Start by tracing Spoon's auto-import handling during pretty-printing with the supplied Java example, focusing on how Javadoc links are represented and resolved. Confirm the fix by producing compilable output that preserves the reference to B while adding both the Javadoc import and the new Future import.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.