Skip to content

[WIP] Add JFace-free test cases for LambdaASTVisitor#594

Merged
carstenartur merged 2 commits into
copilot/fix-submonitor-transformationfrom
copilot/create-jface-free-test-cases
Feb 4, 2026
Merged

[WIP] Add JFace-free test cases for LambdaASTVisitor#594
carstenartur merged 2 commits into
copilot/fix-submonitor-transformationfrom
copilot/create-jface-free-test-cases

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 4, 2026

Implementation Plan: ClassInstanceCreation Visitor Testing

Goal

Create JFace-free test cases to verify that LambdaASTVisitor correctly finds ALL ClassInstanceCreation nodes in various scenarios.

Checklist

  • Create mock classes in sandbox_common_test

    • Create MockProgressMonitor.java interface
    • Create MockSubProgressMonitor.java class
    • Create MockSubMonitor.java class
  • Create comprehensive test file ClassInstanceCreationVisitorTest.java

    • Test finding all ClassInstanceCreation nodes in a method (basic case)
    • Test ClassInstanceCreation in nested blocks (if, while, for)
    • Test ClassInstanceCreation inside lambdas
    • Test ClassInstanceCreation in anonymous classes
    • Test standalone ClassInstanceCreation without preceding method calls
    • Test scope function behavior and its effect on traversal
    • Test pattern similar to JFace plugin (with chained visitors)
  • Run tests to verify behavior

    • Fix any issues found in LambdaASTVisitor.java or related classes
    • Verify all tests pass
  • Update sandbox_common/TODO.md with findings

Key Insight

The scope function in ASTProcessor controls which subtree is traversed. When a scope function navigates to a specific node (e.g., Block), only ClassInstanceCreation nodes within that subtree will be found. This is important for understanding the JFace plugin behavior.

Files Created

  • sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/mock/MockProgressMonitor.java
  • sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/mock/MockSubProgressMonitor.java
  • sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/mock/MockSubMonitor.java
  • sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/ClassInstanceCreationVisitorTest.java (18+ KB, comprehensive tests)
Original prompt

Problem Statement

PR #593 identified that the LambdaASTVisitor.visit(ClassInstanceCreation) method is only finding 3 out of 14+ SubProgressMonitor instances. Before we can fix the JFace cleanup plugin, we need to verify that the core LambdaASTVisitor implementation works correctly.

Current Situation

  1. PR Restore scope functions for Block-scoped progress monitor grouping #568 - Original SubProgressMonitor → SubMonitor migration PR (14 out of 16 tests failing)
  2. PR [WIP] Fix SubProgressMonitor to SubMonitor transformation regression #593 - Investigation PR targeting Restore scope functions for Block-scoped progress monitor grouping #568, identified root cause in AST visitor

Root Cause from PR #593

The LambdaASTVisitor.visit(ClassInstanceCreation) method compares type names, but only 3 SubProgressMonitor instances are being visited by the AST visitor. This suggests:

  1. AST traversal is incomplete OR
  2. Scope function is limiting visitor scope OR
  3. Type binding resolution is failing for most instances

Task

Create JFace-free test cases in sandbox_common_test that:

  1. Create mock classes that mimic the SubProgressMonitor/SubMonitor pattern without JFace dependencies

    • Create a simple MockProgressMonitor interface
    • Create MockSubProgressMonitor class (old pattern)
    • Create MockSubMonitor class (new pattern with static convert() method)
  2. Write test cases in a new test file sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/ClassInstanceCreationVisitorTest.java that:

    • Tests that LambdaASTVisitor correctly finds ALL ClassInstanceCreation nodes
    • Tests with multiple ClassInstanceCreation nodes in the same method
    • Tests with ClassInstanceCreation in nested blocks (if, while, for loops)
    • Tests with ClassInstanceCreation inside lambdas
    • Tests with ClassInstanceCreation in anonymous classes
    • Tests standalone ClassInstanceCreation without any preceding method calls (like beginTask())
    • Tests the scope function parameter and its effect on visitor traversal
  3. Add tests for the pattern similar to JFace plugin:

    • Test detecting ClassInstanceCreation for a specific type name
    • Test finding related MethodInvocation nodes in the same scope
    • Test the ASTProcessor chained visitor pattern used in JFacePlugin.java
  4. If any tests fail, investigate and fix the issue in:

    • sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java
    • sandbox_common/src/org/sandbox/jdt/internal/common/ASTProcessor.java
    • sandbox_common/src/org/sandbox/jdt/internal/common/HelperVisitor.java

Test Code Pattern Example

// Mock classes to be created in test package
public interface MockProgressMonitor {
    void beginTask(String name, int totalWork);
    void done();
}

public class MockSubProgressMonitor implements MockProgressMonitor {
    public MockSubProgressMonitor(MockProgressMonitor monitor, int ticks) { }
    public MockSubProgressMonitor(MockProgressMonitor monitor, int ticks, int style) { }
    // ...
}

public class MockSubMonitor implements MockProgressMonitor {
    public static MockSubMonitor convert(MockProgressMonitor monitor, int work) { return null; }
    public MockSubMonitor split(int work) { return null; }
    // ...
}
// Test code to be parsed
String code = """
    package test;
    public class Test {
        public void doWork(MockProgressMonitor monitor) {
            monitor.beginTask("Task", 100);
            MockProgressMonitor sub1 = new MockSubProgressMonitor(monitor, 50);
            MockProgressMonitor sub2 = new MockSubProgressMonitor(monitor, 30);
            MockProgressMonitor sub3 = new MockSubProgressMonitor(monitor, 20);
        }
    }
    """;

The test should verify that ALL THREE MockSubProgressMonitor instances are found by the visitor, not just some of them.

Files to Create/Modify

  1. Create: sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/mock/MockProgressMonitor.java
  2. Create: sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/mock/MockSubProgressMonitor.java
  3. Create: sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/mock/MockSubMonitor.java
  4. Create: sandbox_common_test/src/org/sandbox/jdt/ui/tests/quickfix/ClassInstanceCreationVisitorTest.java
  5. Possibly Fix: sandbox_common/src/org/sandbox/jdt/internal/common/LambdaASTVisitor.java
  6. Possibly Fix: sandbox_common/src/org/sandbox/jdt/internal/common/ASTProcessor.java
  7. Update: sandbox_common/TODO.md - add notes about findings

Acceptance Criteria

  1. Mock classes created that don't depend on JFace
  2. Test cases pass when using ASTParser to parse code with mock classes
  3. Tests prove that LambdaASTVisitor finds ALL ClassInstanceCreation nodes
  4. Tests cover nested blocks, lambdas, anonymous classes scenarios
  5. Tests cover the scope function parameter behavior
  6. If bugs found in LambdaASTVisitor, they are fixed
  7. TODO.md updated with findings

Reference

  • Existing test pattern: `sandbox_common_test/src/org...

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ests

Co-authored-by: carstenartur <3164220+carstenartur@users.noreply.github.com>
@carstenartur carstenartur marked this pull request as ready for review February 4, 2026 01:50
@carstenartur carstenartur merged commit 5c64f1a into copilot/fix-submonitor-transformation Feb 4, 2026
@carstenartur carstenartur deleted the copilot/create-jface-free-test-cases branch February 4, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants