eclipse-jdt / eclipse-jdt/eclipse.jdt.ui
"Organize imports" should never delete comments
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 59
- Forks
- 127
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 37
Description
context: when using JBang, comments are used to declare several directives, like classpath dependencies. Those comments are critical to the proper functioning of JBang.
In certain conditions, calling "organize imports" will delete all comments above removed imports.
eg. with the following code:
///usr/bin/env jbang "$0" "$@" ; exit $?
package foo;
//DESCRIPTION all those comments are JBang Directives. organizing imports should never ever remove them!!!
//DEPS com.github.jamesnetherton:lolcat4j:0.4.0
//DEPS com.github.lalyos:jfiglet:0.0.9
import static java.lang.System.*;
public class OrganizeImportsBug {
public static void main(String[] args) {
System.out.println("Nooope");
}
}
invoking "Organize imports" will delete all comments below the first non-comment line (the package statement), and the now removed import static java.lang.System.*;, producing:
///usr/bin/env jbang "$0" "$@" ; exit $?
package foo;
public class OrganizeImportsBug {
public static void main(String[] args) {
System.out.println("Nooope");
}
}
With JBang Eclipse installed, this would mean the dependencies would be automatically removed from the classpath, causing compilation failures on a file actually using classes from those dependencies. Bad JDT!
Same bug can be observed when running in VS Code with jbang-vscode.
cc @maxandersen @rgrunber @jjohnstn
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the JBang example and the “Organize imports” command in Eclipse JDT UI; compare the source before and after the import is removed. Trace the organize-imports entry point and its handling of comments. Done means comments above removed imports are preserved, including JBang directives, and the regression is covered by a test.
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
- 42/100