Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4c841b0
Implement SubProgressMonitor enhancements: standalone conversion, fla…
Copilot Feb 1, 2026
59472e0
Fix standalone SubProgressMonitor detection and transformation
Copilot Feb 1, 2026
0800453
Address code review feedback: document limitations and add test coverage
Copilot Feb 1, 2026
1a9c9cb
Add done() call removal feature (partial implementation)
Copilot Feb 1, 2026
bc55472
Fix done() removal - iterate through all holders to find matches
Copilot Feb 1, 2026
32c35b4
Temporarily disable done() removal to fix test failures
Copilot Feb 1, 2026
c192348
Fix standalone SubProgressMonitor conversion and done() removal in JF…
Copilot Feb 3, 2026
48a9d9a
[WIP] Fix SubProgressMonitor to SubMonitor transformation regression …
Copilot Feb 4, 2026
cbab8ea
Plan: Fix JFace cleanup transformation not being applied
Copilot Feb 4, 2026
557598c
Fix JFace cleanup: remove scope functions from SubProgressMonitor and…
Copilot Feb 4, 2026
aacb76e
[WIP] Fix variable declaration in JFacePlugin to resolve CI test fail…
Copilot Feb 4, 2026
0c7f66b
Restore scope functions to enable Block-level grouping of progress mo…
Copilot Feb 4, 2026
5e49d57
Fix holder access in JFace cleanup and document pattern detection iss…
Copilot Feb 4, 2026
587934d
Remove standalone SubProgressMonitor and done() removal from JFace cl…
Copilot Feb 4, 2026
af851fd
[WIP] Update expected output for JFace cleanup tests (#598)
Copilot Feb 4, 2026
62d98a6
Fix JFace cleanup idempotence tests - align given/expected for alread…
Copilot Feb 4, 2026
4a0384f
fix formatting
carstenartur Feb 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2026 Carsten Hammer.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Carsten Hammer
*******************************************************************************/
package org.sandbox.jdt.ui.tests.quickfix.mock;

/**
* Mock interface for testing ClassInstanceCreation visitor patterns.
* Mimics the IProgressMonitor pattern without JFace dependencies.
*/
public interface MockProgressMonitor {
/**
* Begins a task with the specified name and total work units.
*
* @param name the task name
* @param totalWork the total work units
*/
void beginTask(String name, int totalWork);

/**
* Marks the task as complete.
*/
void done();

/**
* Reports work progress.
*
* @param work the amount of work done
*/
void worked(int work);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (c) 2026 Carsten Hammer.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Carsten Hammer
*******************************************************************************/
package org.sandbox.jdt.ui.tests.quickfix.mock;

/**
* Mock class for testing ClassInstanceCreation visitor patterns.
* Mimics the SubMonitor pattern (replacement for SubProgressMonitor) without JFace dependencies.
*/
public class MockSubMonitor implements MockProgressMonitor {

/**
* Converts a monitor to a SubMonitor.
*
* @param monitor the monitor to convert
* @param work the total work units
* @return a new MockSubMonitor instance
*/
public static MockSubMonitor convert(MockProgressMonitor monitor, int work) {
return new MockSubMonitor();
}

/**
* Converts a monitor to a SubMonitor with a task name.
*
* @param monitor the monitor to convert
* @param taskName the task name
* @param work the total work units
* @return a new MockSubMonitor instance
*/
public static MockSubMonitor convert(MockProgressMonitor monitor, String taskName, int work) {
return new MockSubMonitor();
}

/**
* Splits off a portion of work.
*
* @param work the amount of work to split
* @return a new MockSubMonitor for the split work
*/
public MockSubMonitor split(int work) {
return new MockSubMonitor();
}

@Override
public void beginTask(String name, int totalWork) {
// Mock implementation
}

@Override
public void done() {
// Mock implementation
}

@Override
public void worked(int work) {
// Mock implementation
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2026 Carsten Hammer.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Carsten Hammer
*******************************************************************************/
package org.sandbox.jdt.ui.tests.quickfix.mock;

/**
* Mock class for testing ClassInstanceCreation visitor patterns.
* Mimics the deprecated SubProgressMonitor pattern without JFace dependencies.
*/
public class MockSubProgressMonitor implements MockProgressMonitor {

private final MockProgressMonitor monitor;
private final int ticks;
private final int style;

/**
* Creates a new MockSubProgressMonitor with 2 arguments.
*
* @param monitor the parent monitor
* @param ticks the number of ticks
*/
public MockSubProgressMonitor(MockProgressMonitor monitor, int ticks) {
this(monitor, ticks, 0);
}

/**
* Creates a new MockSubProgressMonitor with 3 arguments.
*
* @param monitor the parent monitor
* @param ticks the number of ticks
* @param style the style flags
*/
public MockSubProgressMonitor(MockProgressMonitor monitor, int ticks, int style) {
this.monitor = monitor;
this.ticks = ticks;
this.style = style;
}

@Override
public void beginTask(String name, int totalWork) {
// Mock implementation
}

@Override
public void done() {
// Mock implementation
}

@Override
public void worked(int work) {
// Mock implementation
}
}
65 changes: 46 additions & 19 deletions sandbox_jface_cleanup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The **JFace Cleanup** plugin modernizes Eclipse JFace code by migrating deprecat
## Key Features

- 🔄 **SubProgressMonitor → SubMonitor** - Automatic migration to modern progress API
- 🎯 **Style Flag Handling** - Properly converts `PREPEND_MAIN_LABEL_TO_SUBTASK` flag
- 🎯 **Style Flag Mapping** - Maps `SUPPRESS_SUBTASK_LABEL` to `SUPPRESS_SUBTASK`
- 🗑️ **Flag Dropping** - Removes `PREPEND_MAIN_LABEL_TO_SUBTASK` (no SubMonitor equivalent)
- 📦 **Variable Name Management** - Generates unique variable names to avoid conflicts
- ♻️ **Idempotent** - Running cleanup multiple times produces the same result
- 🔌 **Eclipse Integration** - Works seamlessly with Eclipse RCP/JFace code
Expand All @@ -27,52 +28,77 @@ The **JFace Cleanup** plugin modernizes Eclipse JFace code by migrating deprecat
**Basic Transformation:**
```java
// Before
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 100);
monitor.beginTask("Task", 100);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 50);

// After
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
SubMonitor subMonitor = SubMonitor.convert(monitor, "Task", 100);
IProgressMonitor sub = subMonitor.split(50);
```

**With Style Flags:**
**With SUPPRESS_SUBTASK_LABEL Flag:**
```java
// Before
monitor.beginTask("Task", 100);
SubProgressMonitor sub = new SubProgressMonitor(
monitor, 50, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
monitor, 50, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);

// After
SubMonitor sub = SubMonitor.convert(monitor, 50)
.setWorkRemaining(50);
SubMonitor subMonitor = SubMonitor.convert(monitor, "Task", 100);
IProgressMonitor sub = subMonitor.split(50, SubMonitor.SUPPRESS_SUBTASK);
```

**With PREPEND_MAIN_LABEL_TO_SUBTASK Flag (Dropped):**
```java
// Before
monitor.beginTask("Task", 100);
SubProgressMonitor sub = new SubProgressMonitor(
monitor, 50, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);

// After - flag is dropped as there's no equivalent in SubMonitor
SubMonitor subMonitor = SubMonitor.convert(monitor, "Task", 100);
IProgressMonitor sub = subMonitor.split(50);
```

**Unique Variable Names:**
```java
// Before
SubProgressMonitor sub = new SubProgressMonitor(monitor, 100);
// ... later in code ...
SubProgressMonitor sub = new SubProgressMonitor(otherMonitor, 50);
String subMonitor = "test";
monitor.beginTask("Task", 100);
IProgressMonitor sub = new SubProgressMonitor(monitor, 50);

// After
SubMonitor sub = SubMonitor.convert(monitor, 100);
// ... later in code ...
SubMonitor sub2 = SubMonitor.convert(otherMonitor, 50); // Unique name generated
String subMonitor = "test";
SubMonitor subMonitor2 = SubMonitor.convert(monitor, "Task", 100);
IProgressMonitor sub = subMonitor2.split(50); // Unique name generated
```

## Migration Pattern

The cleanup transforms:
The cleanup transforms `beginTask` + `SubProgressMonitor` to `SubMonitor.convert` + `split`:

```
monitor.beginTask(msg, work);
new SubProgressMonitor(monitor, ticks)
SubMonitor.convert(monitor, ticks)
SubMonitor subMonitor = SubMonitor.convert(monitor, msg, work);
subMonitor.split(ticks)
```

With `SUPPRESS_SUBTASK_LABEL` flag:

```
new SubProgressMonitor(monitor, ticks, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)
↓ (in beginTask context)
subMonitor.split(ticks, SubMonitor.SUPPRESS_SUBTASK)
```

With style flag `PREPEND_MAIN_LABEL_TO_SUBTASK`:
With `PREPEND_MAIN_LABEL_TO_SUBTASK` flag:

```
new SubProgressMonitor(monitor, ticks, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)
SubMonitor.convert(monitor, ticks).setWorkRemaining(ticks)
(flag is dropped - no equivalent in SubMonitor)
subMonitor.split(ticks)
```

## Why Migrate?
Expand Down Expand Up @@ -137,8 +163,9 @@ xvfb-run --auto-servernum mvn test -pl sandbox_jface_cleanup_test

## Limitations

- Does not handle complex style flag combinations (only `PREPEND_MAIN_LABEL_TO_SUBTASK`)
- Combined flag expressions using bitwise OR (e.g., `FLAG1 | FLAG2`) or numeric flag literals are not automatically mapped and require manual review
- Custom SubProgressMonitor subclasses require manual review
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation does not clarify the behavior for standalone SubProgressMonitor with flags. The examples on lines 85-99 only show flag behavior "in beginTask context" but don't mention what happens when a standalone SubProgressMonitor is created with flags. Since the implementation silently drops flags for standalone cases, this should be documented in the Limitations section to set user expectations.

Suggested change
- Custom SubProgressMonitor subclasses require manual review
- Custom SubProgressMonitor subclasses require manual review
- When converting standalone `SubProgressMonitor` instances (created without a surrounding `beginTask`), any style flags are silently ignored, as `SubMonitor` does not support them in this context

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in commit b121e22. Updated README.md Limitations section to explicitly document that standalone SubProgressMonitor instances with flags will have those flags silently ignored.

- Only handles SubProgressMonitor instances with a corresponding beginTask call in the same scope
- Some rare edge cases may need manual adjustment

See [TODO.md](TODO.md) for planned improvements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ public void rewriteASTInternal(final CompilationUnitRewrite cuRewrite, final Lin
} else {
rangeComputer= new TightSourceRangeComputer();
}
rangeComputer.addTightSourceNode( hit.get(0).minv);

// Get the first MonitorHolder from the hit map (key might not be 0 due to scope grouping)
MonitorHolder mh = hit.values().stream().findFirst().orElse(null);
if (mh != null) {
// For standalone SubProgressMonitor, use the ClassInstanceCreation node instead of minv
if (mh.minv != null) {
rangeComputer.addTightSourceNode(mh.minv);
} else if (!mh.setofcic.isEmpty()) {
// Use the first SubProgressMonitor creation for standalone case
rangeComputer.addTightSourceNode(mh.setofcic.iterator().next());
}
}

rewrite.setTargetSourceRangeComputer(rangeComputer);
jfacefound.rewrite(JfaceCleanUpFixCore.this, hit, cuRewrite, group);
}
Expand Down
Loading