eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

[21] Paste action does not preserve Unnamed classes

Open
#1,234 1 comment 0 reactions 0 assignees View on GitHub
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);
}
```

![paste-action-unnamed-class](https://github.com/eclipse-jdt/eclipse.jdt.ui/assets/1417342/ad9b491e-7843-4d0b-bb38-f9c71b4ad770)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.