eclipse-jdt / eclipse-jdt/eclipse.jdt.ui
[21] Paste action does not preserve Unnamed classes
- Dominant language
- Java
- Stars
- 59
- Forks
- 127
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 35
Description
This is probably a lower priority issue as it mostly works. Also, detecting that Java 21 should apply there seems ambiguous where no project exists.
**Copied Text**
```
String greeting = "Hello, World!";
void main() {
System.out.println(greeting);
}
```

The `Snippet` class was probably a great idea for pasting statements with no parent but now certain kinds of code blocks with no parent class will be valid.
If we want to fix it, the logic at https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/508ab962aacc6408588d3f78ab71bf74a43c4468/org.eclipse.jdt.ui/ui%20refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/PasteAction.java#L818-L830 probably needs some improvement or maybe there's more information at https://github.com/eclipse-jdt/eclipse.jdt.ui/blob/508ab962aacc6408588d3f78ab71bf74a43c4468/org.eclipse.jdt.ui/ui%20refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/PasteAction.java#L767 about an unnamed class being valid for the pasted text.
Contributor guide
Research direction
Start in org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/reorg/PasteAction.java, especially the logic around lines 767 and 818-830, and reproduce the pasted Java 21 unnamed-class example from the issue. Trace how pasted text is classified when no parent class exists; done means valid unnamed-class code retains its structure instead of being treated only as a Snippet.
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
- 38/100