Restore scope functions for Block-scoped progress monitor grouping#568
Conversation
JUnit Test Overview ReportGenerated on: 21722632369 Overall Statistics
Test Summary by Plugin
Disabled Tests Detailssandbox_functional_converter_test (44 disabled)
sandbox_junit_cleanup_test (34 disabled)
sandbox_platform_helper_test (1 disabled)
This report is automatically generated by the Test Report workflow |
There was a problem hiding this comment.
Pull request overview
This pull request enhances the JFace cleanup plugin to improve the SubProgressMonitor → SubMonitor migration by addressing gaps identified from Eclipse JDT UI PR #2641. The PR is marked as [WIP] (Work in Progress).
Changes:
- Adds support for standalone SubProgressMonitor (without preceding beginTask) conversion to SubMonitor.convert()
- Implements flag mapping from SubProgressMonitor.SUPPRESS_SUBTASK_LABEL to SubMonitor.SUPPRESS_SUBTASK
- Implements flag dropping for SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK (no SubMonitor equivalent)
- Adds test cases for the new transformation patterns
- Updates documentation to reflect the new capabilities
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/helper/JFacePlugin.java | Implements standalone SubProgressMonitor detection, flag mapping logic (SUPPRESS_SUBTASK_LABEL → SUPPRESS_SUBTASK), and flag dropping (PREPEND_MAIN_LABEL_TO_SUBTASK) |
| sandbox_jface_cleanup/src/org/sandbox/jdt/internal/corext/fix/JfaceCleanUpFixCore.java | Adds null-safe handling for standalone SubProgressMonitor cases where minv can be null |
| sandbox_jface_cleanup_test/src/org/sandbox/jdt/ui/tests/quickfix/Java8CleanUpTest.java | Adds three new test cases: StandaloneSubProgressMonitor, SuppressSubtaskLabelFlag, and PrependMainLabelToSubtaskFlag |
| sandbox_jface_cleanup/README.md | Updates documentation with flag mapping examples, clarifies PREPEND_MAIN_LABEL_TO_SUBTASK behavior, and adds standalone conversion feature to key features |
| // Handle flags if present (third arg) | ||
| // Note: SubMonitor.convert() doesn't accept flags, so we ignore them for standalone conversion | ||
| // The flags would only be relevant for split() calls |
There was a problem hiding this comment.
The implementation silently drops flags for standalone SubProgressMonitor instances. When a 3-arg SubProgressMonitor constructor is used without a preceding beginTask (e.g., new SubProgressMonitor(monitor, 50, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)), the flags are ignored and the conversion produces SubMonitor.convert(monitor, 50) without any flags.
This is problematic because SubMonitor.convert() does not accept flags - flags are only applicable to the split() method. However, for standalone SubProgressMonitor cases, there is no split() call being generated, so the flags cannot be preserved.
Consider either:
- Not transforming standalone SubProgressMonitor with flags (skip them with a warning/comment)
- Generating a pattern like
SubMonitor.convert(monitor, work).split(work, mappedFlags)which preserves the flag behavior - Documenting this as a known limitation with explicit test coverage showing the flag-dropping behavior
There was a problem hiding this comment.
Addressed in commit b121e22. Added explicit documentation in code comments and README.md that flags are intentionally dropped for standalone SubProgressMonitor instances since SubMonitor.convert() doesn't accept flags. Also added test case StandaloneSubProgressMonitorWithFlags to demonstrate this behavior.
| StandaloneSubProgressMonitor( | ||
| """ | ||
| package test; | ||
| import org.eclipse.core.runtime.IProgressMonitor; | ||
| import org.eclipse.core.runtime.SubProgressMonitor; | ||
| public class Test { | ||
| public void doWork(IProgressMonitor monitor) { | ||
| IProgressMonitor sub = new SubProgressMonitor(monitor, 50); | ||
| // Use sub monitor | ||
| sub.worked(10); | ||
| } | ||
| } | ||
| """, //$NON-NLS-1$ | ||
| """ | ||
| package test; | ||
| import org.eclipse.core.runtime.IProgressMonitor; | ||
| import org.eclipse.core.runtime.SubMonitor; | ||
| public class Test { | ||
| public void doWork(IProgressMonitor monitor) { | ||
| IProgressMonitor sub = SubMonitor.convert(monitor, 50); | ||
| // Use sub monitor | ||
| sub.worked(10); | ||
| } | ||
| } | ||
| """), //$NON-NLS-1$ |
There was a problem hiding this comment.
Missing test coverage for standalone SubProgressMonitor with flags (3-arg constructor). The current test only covers the 2-arg constructor case. A test case should be added to verify the behavior when flags are present in standalone SubProgressMonitor instances, especially given that the current implementation silently drops these flags.
There was a problem hiding this comment.
Added in commit b121e22. New test case StandaloneSubProgressMonitorWithFlags verifies that flags are dropped when converting standalone SubProgressMonitor with 3-arg constructor.
| private Expression mapSubProgressMonitorFlags(Expression flagExpr, AST ast, CompilationUnitRewrite cuRewrite) { | ||
| // Handle field access: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL | ||
| if (flagExpr instanceof QualifiedName) { | ||
| QualifiedName qn = (QualifiedName) flagExpr; | ||
| String fieldName = qn.getName().getIdentifier(); | ||
|
|
||
| if ("SUPPRESS_SUBTASK_LABEL".equals(fieldName)) { //$NON-NLS-1$ | ||
| // Map to SubMonitor.SUPPRESS_SUBTASK | ||
| QualifiedName newFlag = ast.newQualifiedName( | ||
| ast.newSimpleName(SubMonitor.class.getSimpleName()), | ||
| ast.newSimpleName("SUPPRESS_SUBTASK")); //$NON-NLS-1$ | ||
| return newFlag; | ||
| } else if ("PREPEND_MAIN_LABEL_TO_SUBTASK".equals(fieldName)) { //$NON-NLS-1$ | ||
| // Drop this flag - no equivalent in SubMonitor | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| // Handle field access: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL | ||
| if (flagExpr instanceof FieldAccess) { | ||
| FieldAccess fa = (FieldAccess) flagExpr; | ||
| String fieldName = fa.getName().getIdentifier(); | ||
|
|
||
| if ("SUPPRESS_SUBTASK_LABEL".equals(fieldName)) { //$NON-NLS-1$ | ||
| // Map to SubMonitor.SUPPRESS_SUBTASK | ||
| FieldAccess newFlag = ast.newFieldAccess(); | ||
| newFlag.setExpression(ast.newSimpleName(SubMonitor.class.getSimpleName())); | ||
| newFlag.setName(ast.newSimpleName("SUPPRESS_SUBTASK")); //$NON-NLS-1$ | ||
| return newFlag; | ||
| } else if ("PREPEND_MAIN_LABEL_TO_SUBTASK".equals(fieldName)) { //$NON-NLS-1$ | ||
| // Drop this flag - no equivalent in SubMonitor | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| // For other expressions (constants, variables), pass through unchanged | ||
| return ASTNodes.createMoveTarget(cuRewrite.getASTRewrite(), ASTNodes.getUnparenthesedExpression(flagExpr)); |
There was a problem hiding this comment.
The flag mapping implementation only handles QualifiedName and FieldAccess patterns for individual flag constants. It does not handle combined flag expressions using bitwise OR (e.g., SubProgressMonitor.SUPPRESS_SUBTASK_LABEL | SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK) or numeric literals representing flag values.
If such patterns exist in real code, they will be passed through unchanged (line 516), which could result in incorrect flag values being used with SubMonitor. Consider adding handling for InfixExpression nodes to properly map or drop flags in combined expressions, or documenting this as a known limitation.
There was a problem hiding this comment.
Documented in commit b121e22. Added JavaDoc explaining this limitation in the mapSubProgressMonitorFlags method and added corresponding limitation note in README.md. Combined flag expressions and numeric literals are explicitly called out as requiring manual review.
|
|
||
| - Does not handle complex style flag combinations (only `PREPEND_MAIN_LABEL_TO_SUBTASK`) | ||
| - Does not automatically remove `done()` calls (SubMonitor handles cleanup automatically) | ||
| - Custom SubProgressMonitor subclasses require manual review |
There was a problem hiding this comment.
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.
| - 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 |
There was a problem hiding this comment.
Added in commit b121e22. Updated README.md Limitations section to explicitly document that standalone SubProgressMonitor instances with flags will have those flags silently ignored.
| } | ||
| } | ||
|
|
||
| // Handle field access: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL |
There was a problem hiding this comment.
Duplicate comment. The comment on line 498 is identical to the comment on line 481. The comment should be more specific - perhaps "Handle FieldAccess syntax (e.g., expression.FIELD_NAME)" to distinguish it from the QualifiedName handling above.
| // Handle field access: SubProgressMonitor.SUPPRESS_SUBTASK_LABEL | |
| // Handle FieldAccess syntax (e.g., expression.FIELD_NAME) |
There was a problem hiding this comment.
Fixed in commit b121e22. Changed comment to "Handle FieldAccess syntax (e.g., expression.FIELD_NAME)" to distinguish it from the QualifiedName handling above.
|
@copilot 2026-02-01T14:55:54.2893457Z Tests run: 13, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 5.005 s <<< FAILURE! -- in org.sandbox.jdt.ui.tests.quickfix.Java8CleanUpTest |
|
@copilot Consider Review comments |
Review comments addressed in commit b121e22:
Note: The standalone SubProgressMonitor transformation (test [9]) is still failing as mentioned in the PR description. The infrastructure is in place but requires further debugging of the AST visitor chain to make it functional. |
b121e22 to
f9ffb69
Compare
|
@copilot 2026-02-01T18:12:25.7909806Z Running org.sandbox.jdt.ui.tests.quickfix.Java8CleanUpTest |
The done() removal feature caused widespread test failures (14 out of 16 tests failing). I've temporarily disabled it in commit d2c8a37 to restore the working state of the main SubProgressMonitor transformation. The feature infrastructure remains in place but is commented out. The issue needs further investigation - the done() visitor may have been interfering with the primary transformation or the scope matching was incorrect. The core SubProgressMonitor → SubMonitor conversion, flag mapping, and standalone conversion features should now work correctly again. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
d2c8a37 to
f18b7c5
Compare
Test Results1 145 tests +12 1 109 ✅ +12 1m 57s ⏱️ +8s Results for commit 4a0384f. ± Comparison against base commit aa2250c. This pull request removes 1 and adds 13 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
f18b7c5 to
f740a82
Compare
- Added test case for standalone SubProgressMonitor with flags (shows flags are dropped) - Updated README.md to document flag dropping behavior for standalone cases - Added documentation about bitwise OR limitation in flag mapping - Improved inline comments to clarify flag handling - Fixed duplicate comment in mapSubProgressMonitorFlags method Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
- Added doneInvocations tracking to MonitorHolder - Implemented done() call visitor in find() method - Added removal logic in rewrite() method - Added DoneCallRemoval and MultipleDoneCalls test cases - Updated README: added feature to Key Features, added example, removed limitation - Tests show feature is detected but removal not yet working correctly Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
The previous implementation only checked the last holder, which missed done() calls. Now searches through all MonitorHolders to properly associate done() calls with their corresponding beginTask transformations. Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
The done() removal feature is causing 14 out of 16 tests to fail. Disabling it temporarily to restore functionality while investigating the root cause of the failures. The infrastructure (doneInvocations tracking) remains in place for future re-enablement once the issue is resolved. Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
d398274 to
c192348
Compare
Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
… done() visitors The ClassInstanceCreation and done() method visitors had scope functions that prevented them from accessing the holders created by the beginTask visitor. When multiple visitors use different scope functions, they get separate holder instances and can't share data. Removed the scope functions from: 1. callClassInstanceCreationVisitor for SubProgressMonitor detection 2. callMethodInvocationVisitor for done() call detection This allows these visitors to access the global holder populated by beginTask visitor, enabling proper SubProgressMonitor transformation. Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
…nitor elements The scope functions `s -> ASTNodes.getTypedAncestor(s, Block.class)` are intentional and necessary. They group related progress monitor elements (beginTask, SubProgressMonitor, done) that belong together within the same Block scope. Restored scope functions to: - callClassInstanceCreationVisitor for SubProgressMonitor detection - callMethodInvocationVisitor for done() call detection This ensures all three visitors (beginTask, SubProgressMonitor, done) operate on the same Block-scoped holder, allowing proper matching of related monitor operations. Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
Reverts removal of scope functions from SubProgressMonitor and done() visitors. These functions group related monitor operations (beginTask + SubProgressMonitor + done) within the same Block scope, enabling proper transformation of logically related elements.
Changes
s -> ASTNodes.getTypedAncestor(s, Block.class)scope function tocallClassInstanceCreationVisitorfor SubProgressMonitor detectioncallMethodInvocationVisitorfor done() call detectionTechnical Context
The scope functions navigate to the containing Block, ensuring visitors operate on Block-scoped holder data. This allows:
Without Block scope, visitors would operate on global holder, breaking the logical grouping of related monitor operations within method blocks.
Original prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.