Skip to content

carstenartur/sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

891 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Sandbox Project

A collection of experimental Eclipse JDT (Java Development Tools) cleanup plugins and tools. This repository demonstrates how to build custom JDT cleanups, quick fixes, and related tooling for Eclipse-based Java development.

Main Technologies: Eclipse JDT, Java 21, Maven/Tycho 5.0.1

Status: Work in Progress – All plugins are experimental and intended for testing purposes.

Overview

This project provides:

  • Custom JDT Cleanup Plugins: Automated code transformations for encoding, JUnit migration, functional programming patterns, and more
  • Eclipse Product Build: A complete Eclipse product with bundled features
  • P2 Update Site: Installable plugins via Eclipse update mechanism
  • Test Infrastructure: JUnit 5-based tests for all cleanup implementations
  • GitHub Actions Integration: Automated code cleanup for pull requests (See GITHUB_ACTIONS.md)

All plugins are work-in-progress and intended for experimentation and learning.

πŸš€ Installation

Update Site URLs

Add one of the following update sites to your Eclipse installation:

Stable Releases (Recommended)

https://carstenartur.github.io/sandbox/releases/

Use this for stable, tested versions suitable for production use.

Latest Snapshot (Development)

https://carstenartur.github.io/sandbox/snapshots/latest/

Use this to test the latest features. Updated automatically on every commit to main. May be unstable.

Installation Steps

  1. Open Eclipse IDE
  2. Go to Help β†’ Install New Software...
  3. Click Add... button
  4. Enter:
    • Name: Sandbox (or any name you prefer)
    • Location: One of the update site URLs above
  5. Select the features you want to install from the available list
  6. Click Next and follow the installation wizard
  7. Restart Eclipse when prompted

⚠️ Warning: These plugins are experimental. Test them in a development environment before using in production.

Eclipse Marketplace

The Sandbox plugins are also available on the Eclipse Marketplace.

πŸ“¦ Release Process

The Sandbox project uses an automated release workflow:

  1. Navigate to Actions β†’ Release Workflow β†’ Run workflow
  2. Enter the release version (e.g., 1.2.2)
  3. Enter the next SNAPSHOT version (e.g., 1.2.3-SNAPSHOT)
  4. Click Run workflow

The workflow automatically:

  • Updates all version files using tycho-versions-plugin (except sandbox-functional-converter-core)
  • Builds and verifies the release
  • Creates git tag and maintenance branch
  • Deploys to GitHub Pages
  • Generates release notes from closed issues
  • Creates GitHub release
  • Bumps to next SNAPSHOT version

The new release will be available at https://carstenartur.github.io/sandbox/releases/X.Y.Z/ within a few minutes.

Table of Contents

GitHub Actions Integration

This repository includes a Docker-based GitHub Action for automated code cleanup on pull requests. The action uses the sandbox cleanup application to apply Eclipse JDT cleanups directly in your GitHub workflows.

Quick Start

  • Automatic PR Cleanup: Already configured! Opens/updates to PRs with Java files trigger cleanup automatically
  • Manual Cleanup: Go to Actions β†’ Manual Cleanup β†’ Run workflow
  • Custom Integration: Use ./.github/actions/cleanup-action in your workflows

Features

βœ… Automated cleanup on pull requests
βœ… Configurable profiles (minimal/standard/aggressive)
βœ… All sandbox + Eclipse JDT cleanups included
βœ… Auto-commit changes to PR branch
βœ… Manual trigger with customizable options

πŸ“– Full Documentation | Workflows Guide | Action Details

Build Instructions

Prerequisites

IMPORTANT: This project (main branch, targeting Eclipse 2025-09) requires Java 21 or later.

The project uses Tycho 5.0.1 which requires Java 21. Building with Java 17 or earlier will fail with:

UnsupportedClassVersionError: ... has been compiled by a more recent version of the Java Runtime (class file version 65.0)

Verify your Java version:

java -version  # Should show Java 21 or later

Building

Build Profiles

The project supports Maven profiles to optimize build speed:

Profile Modules Built Use Case
dev (default) All bundles, features, tests Fast local development
product + Eclipse Product (sandbox_product) Building distributable product
repo + P2 Update Site (sandbox_updatesite) Building update site
jacoco + Coverage reports CI/Coverage builds
reports + HTML test reports CI/Test report builds

Build Commands

Command Description
mvn -T 1C verify Quick dev build (fastest)
mvn -Pproduct -T 1C verify Build with Eclipse product
mvn -Prepo -T 1C verify Build with P2 update site
mvn -Pproduct,repo -T 1C verify Full release build
mvn -Pjacoco,product,repo -T 1C verify Full CI build with coverage
mvn -T 1C -DskipTests verify Skip tests for local iteration

The project supports different build profiles for different purposes. Choose the appropriate command based on your needs:

Quick Development Build (Fastest)

For rapid iteration during development, use the default build which excludes heavy product materialization and p2 repository assembly:

mvn -T 1C verify
  • Builds: All bundles, features, and tests
  • Skips: Product materialization (sandbox_product) and p2 repository assembly (sandbox_updatesite)
  • Use case: Fast feedback during development, testing code changes
  • Time: Significantly faster than full build

You can skip tests for even faster iteration:

mvn -T 1C -DskipTests verify

Build with Eclipse Product

To build the Eclipse product with p2-director materialization (creates installable Eclipse distributions):

mvn -Pproduct -T 1C verify
  • Builds: Everything in default build + Eclipse product
  • Output: sandbox_product/target/products/
  • Use case: Testing the Eclipse product locally

Build with P2 Update Site Repository

To build the p2 update site repository (for plugin distribution):

mvn -Prepo -T 1C verify
  • Builds: Everything in default build + p2 update site
  • Output: sandbox_updatesite/target/repository/
  • Use case: Creating update site for plugin distribution

Full Release Build

For complete builds including product, repository, and code coverage:

mvn -Pproduct,repo,jacoco -T 1C verify
  • Builds: Everything (bundles, features, tests, product, repository, coverage)
  • Output: Complete release artifacts in respective module target/ directories
  • Coverage Report: sandbox_coverage/target/site/jacoco-aggregate/
  • Use case: Release builds, CI main branch builds

Build with WAR File (Legacy)

To build a WAR file that contains the update site:

mvn -Dinclude=web -Pproduct,jacoco -T 1C verify
  • The WAR file will be located in sandbox_web/target

Using Make (Convenience)

A Makefile is provided for easier build commands:

make dev       # Fast development build (skips tests)
make product   # Build with product (requires xvfb for tests)
make repo      # Build with repository (requires xvfb for tests)
make release   # Full release build with coverage (requires xvfb for tests)
make test      # Run tests with coverage (requires xvfb)
make clean     # Clean all build artifacts
make help      # Show all available targets

Build Flags

  • -T 1C: Enables parallel builds with 1 thread per CPU core (faster builds)
  • -DskipTests: Skips test execution (faster iteration)
  • -Pjacoco: Enables JaCoCo code coverage
  • -Pproduct: Includes Eclipse product build
  • -Prepo: Includes p2 repository build

Understanding the Profiles

  • Default (no profiles): Fast development build - bundles, features, and tests only
  • product: Adds Eclipse product materialization (heavy step, takes time)
  • repo: Adds p2 update site repository assembly (heavy step, takes time)
  • jacoco: Adds code coverage reporting (includes sandbox_coverage module)
  • reports: Adds HTML test report generation (use without -T 1C to avoid thread-safety warning)
  • web: Adds WAR file with update site (requires -Dinclude=web property, also builds sandbox_product)

Backward Compatibility: The command mvn -Pproduct,repo verify produces the same result as the previous full build behavior.

Troubleshooting

Build fails with UnsupportedClassVersionError or TypeNotPresentException

This error occurs when building with Java 17 or earlier:

TypeNotPresentException: Type P2ArtifactRepositoryLayout not present
...class file version 65.0, this version only recognizes class file versions up to 61.0

Solution: Upgrade to Java 21 or later. Verify with java -version.

Build fails with Unable to provision errors

This usually indicates a Java version mismatch. Check that:

  1. JAVA_HOME is set to Java 21+
  2. java -version shows Java 21+
  3. Maven is using the correct Java version: mvn -version

Eclipse Version Configuration

The Eclipse version (SimRel release) used by this project is not centrally configured. When updating to a new Eclipse release, you must update the version reference in multiple files throughout the repository.

Files to Update

When migrating to a new Eclipse version, update the following files:

  1. pom.xml (root)

    • Repository URLs in the <repositories> section
    • Example: https://download.eclipse.org/releases/2025-09/
    • Also update Orbit repository URL: https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2025-09/
  2. sandbox_target/eclipse.target

    • Primary Eclipse release repository URL in first <location> block
    • Example: <repository location="https://download.eclipse.org/releases/2025-09/"/>
    • Also update Orbit repository URL
  3. sandbox_product/category.xml

    • Repository reference location
    • Example: <repository-reference location="https://download.eclipse.org/releases/2025-09/" .../>
  4. sandbox_product/sandbox.product

    • Repository locations in <repositories> section
    • Example: <repository location="https://download.eclipse.org/releases/2025-09/" .../>
  5. sandbox_oomph/sandbox.setup

    • P2 repository URL in the version-specific <setupTask> block
    • Example: <repository url="https://download.eclipse.org/releases/2025-09"/>

Version Consistency Guidelines

  • Use HTTPS: All Eclipse download URLs should use https:// (not http://)
  • Use explicit versions: Prefer explicit version URLs (e.g., 2025-09) over latest for reproducible builds
  • Keep versions aligned: All files should reference the same Eclipse SimRel version
  • Git URLs: Use HTTPS for git clone URLs (e.g., https://github.com/..., not git://)
  • Main branch: All Oomph setup files should reference the main branch, not master

Current Configuration

  • Eclipse Version: 2025-09
  • Java Version: 21
  • Tycho Version: 5.0.1
  • Default Branch: main

Quickstart

Using the Eclipse Product

After building the project, you can run the Eclipse product with the bundled cleanup plugins:

# Navigate to the product directory
cd sandbox_product/target/products/org.sandbox.product/

# Launch Eclipse
./eclipse

Using Cleanup Plugins via Command Line

You can apply cleanup transformations using the Eclipse JDT formatter application pattern:

eclipse -nosplash -consolelog -debug \
  -application org.eclipse.jdt.core.JavaCodeFormatter \
  -verbose -config MyCleanupSettings.ini MyClassToCleanup.java

Note: Replace MyCleanupSettings.ini with your cleanup configuration file and MyClassToCleanup.java with the Java file you want to process.

Installing as Eclipse Plugins

You can install the cleanup plugins into your existing Eclipse installation using the P2 update site.

See the Installation section above for detailed instructions and update site URLs.

The update sites provide:

  • Stable Releases: https://carstenartur.github.io/sandbox/releases/ - Tested, stable versions
  • Latest Snapshots: https://carstenartur.github.io/sandbox/snapshots/latest/ - Latest development builds

⚠️ Warning: These plugins are experimental. Test them in a development environment before using in production.


CI Status

main (2025-09)

Java CI with Maven
CodeQL

Code Coverage Reports: Available at https://carstenartur.github.io/sandbox/coverage/ (updated daily via scheduled build when there are commits to main, or on manual trigger)

Test Results: Available at https://carstenartur.github.io/sandbox/tests/ (updated on every push to main)

Report Details

Coverage Reports

The JaCoCo coverage reports show code coverage statistics for the entire codebase:

  • Location: https://carstenartur.github.io/sandbox/coverage/
  • Content: Line, branch, and method coverage for all modules
  • Update Frequency: Daily via scheduled build (only when there are commits in the last 24 hours) or manual trigger
  • Build Profile: Generated with full release build using -Pjacoco,product,repo profiles
  • Local Generation: Run mvn -Pjacoco verify to generate locally in sandbox_coverage/target/site/jacoco-aggregate/
  • Note: Coverage reports are NOT generated on normal push/PR builds to keep CI fast. They require the scheduled or manual coverage workflow.

Test Results

HTML test reports for all test modules, showing detailed test execution results:

  • Location: https://carstenartur.github.io/sandbox/tests/
  • Content:
    • Individual test module reports (e.g., sandbox_encoding_quickfix_test, sandbox_functional_converter_test)
    • Test success/failure statistics
    • Disabled tests (JUnit 5 @Disabled annotations)
    • Detailed test execution information
  • Update Frequency:
    • Primary: Updated on every push to main branch (via normal CI build)
    • Secondary: Also updated during scheduled coverage builds (includes full release build with all profiles)
  • Build Profile:
    • Normal builds (push/PR): No special profiles, fast build for quick feedback
    • Scheduled builds: Uses -Pjacoco,product,repo profiles (full release build)
  • Local Generation: Run the full reactor build (mvn verify), and test reports will be automatically generated in each test module's target/site/surefire-report.html directory
  • Structure:
    • Main index: Lists all test modules with links to their individual reports
    • Module reports: Detailed test results for each module

CI Workflow Structure

The project uses two distinct CI workflows for efficient publishing:

1. Normal Build Workflow (maven.yml)

Triggers: On push/PR to main branch

Purpose: Fast feedback and test result publishing

Build Command: mvn verify (no jacoco, product, or repo profiles)

What it does:

  • Runs standard Maven/Tycho build
  • Executes all tests
  • Generates Surefire/JUnit HTML reports automatically (via maven-surefire-report-plugin)
  • Collects test reports from all test modules
  • Deploys test reports to GitHub Pages at /tests

What it does NOT do:

  • Does NOT generate code coverage (jacoco profile not active)
  • Does NOT build Eclipse product or P2 repository (kept lean for speed)

Update guarantee: Test results are always current with the latest main branch commit

2. Scheduled Coverage Build Workflow (coverage.yml)

Triggers:

  • Daily at midnight UTC (only if there were commits in the last 24 hours)
  • Manual workflow dispatch

Purpose: Full release build with comprehensive coverage metrics

Build Command: mvn -Pjacoco,product,repo verify

What it does:

  • Runs full release build with all profiles
  • Generates JaCoCo code coverage reports
  • Builds Eclipse product and P2 repository
  • Deploys coverage reports to GitHub Pages at /coverage
  • Deploys test reports to GitHub Pages at /tests (as backup)

Update guarantee: Coverage reports are updated daily when there are new commits, but may be up to 24 hours behind the latest commit

Why This Structure?

Performance: Normal builds complete faster without heavy jacoco/product/repo profiles, providing quick feedback on PRs and commits

Separation of Concerns:

  • Test results = Always current (every commit)
  • Coverage metrics = Updated daily (comprehensive but not blocking fast feedback)

Resource Efficiency: Full release builds with coverage are expensive; running them daily (instead of on every commit) reduces CI resource usage while still maintaining up-to-date coverage metrics

2022-09

Java CI with Maven
CodeQL

2022-06

Java CI with Maven
CodeQL


What's Included

Java Version by Branch

Branch Java Version Tycho Version
main (2025-09) Java 21 5.0.1
2024-06+ Java 21 5.0.x
2022-12+ Java 17 4.x
Up to 2022-06 Java 11 3.x

Note: Tycho 5.x requires Java 21+ at build time. Attempting to build with Java 17 will result in UnsupportedClassVersionError.

Topics Covered

  • Building for different Eclipse versions via GitHub Actions
  • Creating custom JDT cleanups
  • Setting up the SpotBugs Maven plugin to fail the build on issues
  • Writing JUnit 5-based tests for JDT cleanups
  • Configuring JaCoCo for test coverage
  • Building an Eclipse product including new features
  • Automatically building a WAR file including a P2 update site

Projects

All projects are considered work in progress unless otherwise noted.

1. sandbox_cleanup_application

Placeholder for a CLI-based cleanup application, similar to the Java code formatting tool:

eclipse -nosplash -consolelog -debug -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config MyCodingStandards.ini MyClassToBeFormatted.java

See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=75333

2. sandbox_encoding_quickfix

Replaces platform-dependent or implicit encoding usage with explicit, safe alternatives using StandardCharsets.UTF_8 or equivalent constants. Improves code portability and prevents encoding-related bugs across different platforms.

Key Features:

  • Three cleanup strategies: Prefer UTF-8, Keep Behavior, or Aggregate UTF-8
  • Java version-aware transformations (Java 7-21+)
  • Supports FileReader, FileWriter, Files methods, Scanner, PrintWriter, and more
  • Automatically adds imports and removes unnecessary exceptions

Quick Example:

// Before
Reader r = new FileReader(file);
List<String> lines = Files.readAllLines(path);

// After
Reader r = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);

πŸ“– Full Documentation: Plugin README | Architecture | TODO

3. sandbox_extra_search

Experimental search tool for identifying critical classes when upgrading Eclipse or Java versions.

4. sandbox_usage_view

Provides a table view of code objects, sorted by name, to detect inconsistent naming that could confuse developers.

5. sandbox_platform_helper

Simplifies Eclipse Platform Status object creation by replacing verbose new Status(...) constructor calls with cleaner factory methods (Java 11+ / Eclipse 4.20+) or StatusHelper pattern (Java 8).

Key Features:

  • Java version-aware transformations
  • Reduces boilerplate in Status object creation
  • Automatic selection between StatusHelper or factory methods
  • Cleaner, more readable code

Quick Example:

// Before
IStatus status = new Status(IStatus.ERROR, "plugin.id", "Error message", exception);

// After (Java 11+ / Eclipse 4.20+)
IStatus status = Status.error("Error message", exception);

πŸ“– Full Documentation: Plugin README | Architecture | TODO

6. sandbox_tools

While-to-For loop converter β€” already merged into Eclipse JDT.

7. sandbox_jface_cleanup

Automates migration from deprecated SubProgressMonitor to modern SubMonitor API. The cleanup is idempotent and handles variable name collisions.

Key Features:

  • Transforms beginTask() + SubProgressMonitor to SubMonitor.convert() + split()
  • Handles style flags and multiple monitor instances
  • Idempotent - safe to run multiple times
  • Automatic variable name conflict resolution

Quick Example:

// Before
monitor.beginTask("Task", 100);
IProgressMonitor sub = new SubProgressMonitor(monitor, 60);

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

πŸ“– Full Documentation: Plugin README | Architecture | TODO

8. sandbox_functional_converter

Functional Converter Cleanup – Transform Imperative Loops into Functional Java 8 Streams

This cleanup modernizes imperative Java loop constructs by transforming them into functional-style equivalents using Java 8 Streams, map, filter, reduce, and forEach.

πŸ“ Architecture Documentation: See ARCHITECTURE.md for detailed implementation details, design patterns, and internal components.


Source and Test Basis

This cleanup is fully tested in:

  • sandbox_functional_converter_test/src/org/sandbox/jdt/ui/tests/quickfix/Java8CleanUpTest.java

The test class defines:

  • 25 enabled test cases covering fully supported loop transformation patterns
  • A list of @Disabled scenarios representing future features and unsupported patterns
  • A set of @ValueSource cases where no transformation should be applied (edge cases)

Supported Transformations

The cleanup currently supports the following patterns:

Pattern Transformed To
Simple enhanced for-loops list.forEach(...) or list.stream().forEach(...)
Mapping inside loops .stream().map(...)
Filtering via if or continue .stream().filter(...)
Null safety checks .filter(l -> l != null).map(...)
Reductions (sum/counter) .stream().map(...).reduce(...)
MAX/MIN reductions .reduce(init, Math::max) or .reduce(init, Math::min)
String concatenation in loops .reduce(..., String::concat)
Conditional early return true .anyMatch(...)
Conditional early return false .noneMatch(...)
Conditional check all valid .allMatch(...)
Method calls inside mapping/filtering map(x -> method(x)), filter(...)
Combined filter, map, forEach Chained stream transformations
Nested conditionals Multiple .filter(...) operations
Increment/decrement reducers .map(_item -> 1).reduce(0, Integer::sum)
Compound assignment reducers .map(expr).reduce(init, operator)

Enabled Test Cases (25 total):

  • SIMPLECONVERT, CHAININGMAP, ChainingFilterMapForEachConvert
  • SmoothLongerChaining, MergingOperations, BeautificationWorks, BeautificationWorks2
  • NonFilteringIfChaining, ContinuingIfFilterSingleStatement
  • SimpleReducer, ChainedReducer, IncrementReducer, AccumulatingMapReduce
  • DOUBLEINCREMENTREDUCER, DecrementingReducer, ChainedReducerWithMerging, StringConcat
  • ChainedAnyMatch, ChainedNoneMatch
  • NoNeededVariablesMerging, SomeChainingWithNoNeededVar
  • MaxReducer, MinReducer, MaxWithExpression, MinWithExpression
  • FilteredMaxReduction, ChainedMapWithMinReduction, ComplexFilterMapMaxReduction
  • ContinueWithMapAndForEach
  • SimpleAllMatch, AllMatchWithNullCheck, ChainedAllMatch
  • NestedFilterCombination

Examples

Simple forEach Conversion

Before:

for (Integer l : list) {
    System.out.println(l);
}

After:

list.forEach(l -> System.out.println(l));

Filter + Map + forEach Chain

Before:

for (Integer l : list) {
    if (l != null) {
        String s = l.toString();
        System.out.println(s);
    }
}

After:

list.stream()
    .filter(l -> (l != null))
    .map(l -> l.toString())
    .forEachOrdered(s -> {
        System.out.println(s);
    });

Null Safety with Objects::nonNull

Before:

for (Integer l : list) {
    if (l == null) {
        continue;
    }
    String s = l.toString();
    System.out.println(s);
}

After:

list.stream()
    .filter(l -> !(l == null))
    .map(l -> l.toString())
    .forEachOrdered(s -> {
        System.out.println(s);
    });

AnyMatch Pattern (Early Return)

Before:

for (Integer l : list) {
    String s = l.toString();
    Object o = foo(s);
    if (o == null)
        return true;
}
return false;

After:

if (list.stream()
        .map(l -> l.toString())
        .map(s -> foo(s))
        .anyMatch(o -> (o == null))) {
    return true;
}
return false;

AllMatch Pattern (Check All Valid)

Before:

for (String item : items) {
    if (!item.startsWith("valid")) {
        return false;
    }
}
return true;

After:

if (!items.stream().allMatch(item -> item.startsWith("valid"))) {
    return false;
}
return true;

MAX/MIN Reduction

Before:

int max = Integer.MIN_VALUE;
for (Integer num : numbers) {
    max = Math.max(max, num);
}

After:

int max = Integer.MIN_VALUE;
max = numbers.stream().reduce(max, Math::max);

Similarly for Math.min() β†’ .reduce(min, Math::min)


MAX/MIN with Expression Mapping

Before:

int maxLen = 0;
for (String str : strings) {
    maxLen = Math.max(maxLen, str.length());
}

After:

int maxLen = 0;
maxLen = strings.stream()
    .map(str -> str.length())
    .reduce(maxLen, Math::max);

Nested Conditional Filters

Before:

for (String item : items) {
    if (item != null) {
        if (item.length() > 5) {
            System.out.println(item);
        }
    }
}

After:

items.stream()
    .filter(item -> (item != null))
    .filter(item -> (item.length() > 5))
    .forEachOrdered(item -> {
        System.out.println(item);
    });

Reductions (Accumulators)

Increment Counter

Before:

int count = 0;
for (String s : list) {
    count += 1;
}

After:

int count = list.stream()
    .map(_item -> 1)
    .reduce(0, Integer::sum);

Mapped Reduction

Before:

int sum = 0;
for (Integer l : list) {
    sum += foo(l);
}

After:

int sum = list.stream()
    .map(l -> foo(l))
    .reduce(0, Integer::sum);

Also supported:

  • Decrementing: i -= 1 β†’ .reduce(i, (a, b) -> a - b)
  • Type-aware literals: 1 for int, 1L for long, 1.0 for double, 1.0f for float
  • String concatenation: .reduce("", String::concat)

Not Yet Supported (Disabled Tests)

The following patterns are currently not supported and are marked @Disabled in the test suite:

Pattern Description Reason / Required Feature
Map.put(...) inside loop Needs Collectors.toMap(...) support
Early break inside loop body Requires stream short-circuit modeling (findFirst())
Labeled continue or break (label:) Not expressible via Stream API
Complex if-else-return branches Requires flow graph and branching preservation
throw inside loop Non-convertible – not compatible with Stream flow
Multiple accumulators in one loop State mutation not easily transferable

These patterns are intentionally excluded from transformation to maintain semantic correctness and safety.


Ignored Cases – No Cleanup Triggered

The cleanup does not modify code in the following edge cases (validated by @ValueSource tests):

  • Non-loop constructs
  • Loops over arrays instead of List or Iterable
  • Loops with early return, throw, or labeled continue
  • Loops mixing multiple mutable accumulators
  • Loops with side effects that cannot be safely preserved

Java Version Compatibility

API Used Requires Java
Stream, map, filter Java 8+
forEach, forEachOrdered Java 8+
anyMatch, noneMatch Java 8+
reduce Java 8+
Collectors.toList() Java 8+

This cleanup is designed for Java 8+ projects and uses only APIs available since Java 8.


Cleanup Name & Activation

Eclipse Cleanup ID Value
MYCleanUpConstants.USEFUNCTIONALLOOP_CLEANUP true (enable this feature)

Usage:

  • Via Eclipse Clean Up... under the appropriate cleanup category
  • Via JDT Batch tooling or Save Actions

Limitations

  • Does not preserve external loop-scoped variables (e.g., index tracking, multiple accumulators)
  • Cannot convert control structures with return, break, continue label, or throw
  • Does not support loops producing Map<K,V> outputs or grouping patterns (future feature)
  • Does not merge consecutive filters/maps (could be optimized in future versions)

Summary

The Functional Converter Cleanup:

  • Applies safe and proven transformations across 21 tested patterns
  • Targets common loop structures found in legacy codebases
  • Modernizes Java 5/6/7-style loops to Java 8 stream-based idioms
  • Uses an extensive test suite for coverage and correctness
  • Maintains semantic safety by excluding complex patterns

Further Reading:

  • Implementation Details: ARCHITECTURE.md – In-depth architecture documentation
  • Test Coverage: Java8CleanUpTest.java in the sandbox_functional_converter_test module
  • Wiki: Functional Converter – Converts Iterator loops to functional loops

9. sandbox_junit

Automates migration of legacy tests from JUnit 3 and JUnit 4 to JUnit 5 (Jupiter). Transforms test classes, methods, annotations, assertions, and lifecycle hooks to use the modern JUnit 5 API.

Key Features:

  • JUnit 3 β†’ 5: Remove extends TestCase, convert naming conventions to annotations
  • JUnit 4 β†’ 5: Update annotations (@Before β†’ @BeforeEach, @Ignore β†’ @Disabled)
  • Assertion parameter reordering (message-last pattern)
  • Lifecycle method transformations
  • Rule migration (@Rule β†’ @RegisterExtension)
  • Test suite conversion

Quick Example:

// Before (JUnit 3)
public class MyTest extends TestCase {
    protected void setUp() throws Exception {
        super.setUp();
    }
    
    public void testSomething() {
        assertEquals("message", expected, actual);
    }
}

// After (JUnit 5)
public class MyTest {
    @BeforeEach
    void setUp() {
    }
    
    @Test
    void testSomething() {
        assertEquals(expected, actual, "message");
    }
}

πŸ“– Full Documentation: Plugin README | Architecture | TODO | Testing Guide


10. sandbox_method_reuse

Method Reusability Finder – Code Duplication Detection

The Method Reusability Finder is an Eclipse JDT cleanup plugin that analyzes selected methods to identify potentially reusable code patterns across the codebase. It helps developers discover duplicate or similar code that could be refactored to improve code quality and maintainability.


Purpose

  • Code Duplication Detection: Identify similar code patterns using both token-based and AST-based analysis
  • Intelligent Matching: Recognize code similarity even when variable names differ
  • Eclipse Integration: Seamlessly integrate as a cleanup action in Eclipse JDT
  • Performance: Efficient analysis that scales to large codebases

Key Features

Similarity Analysis
  • Token-based similarity: Compares normalized token sequences
  • AST-based similarity: Compares abstract syntax tree structures
  • Variable name normalization: Ignores variable name differences
  • Control flow analysis: Matches similar control structures
Inline Code Detection
  • Searches method bodies for inline code sequences
  • Finds code that matches a target method's body
  • Identifies refactoring opportunities within methods
Safety Analysis
  • Analyzes semantic safety of replacements
  • Detects field modifications and side effects
  • Checks for complex control flow

Components

Component Purpose
MethodReuseFinder Searches project for similar methods
MethodSignatureAnalyzer Analyzes and compares method signatures
CodePatternMatcher AST-based pattern matching
InlineCodeSequenceFinder Finds inline code sequences
CodeSequenceMatcher Matches statement sequences with normalization
VariableMapping Tracks variable name mappings
MethodCallReplacer Generates method invocation replacement code
SideEffectAnalyzer Analyzes safety of replacements

Configuration

Cleanup options are defined in MYCleanUpConstants:

  • METHOD_REUSE_CLEANUP - Enable/disable the cleanup
  • METHOD_REUSE_INLINE_SEQUENCES - Enable inline code sequence detection

Usage

This cleanup is available as part of the JDT Clean Up framework:

  • Eclipse UI β†’ Source β†’ Clean Up
  • Automated build tools using Eclipse JDT APIs

Implementation Status

This is a new plugin currently under development. The initial implementation focuses on:

  • Basic method similarity detection
  • AST-based pattern matching
  • Integration with Eclipse cleanup framework

See sandbox_method_reuse/TODO.md for pending features and improvements.


11. sandbox_xml_cleanup

XML Cleanup – PDE File Optimization

The XML Cleanup plugin provides automated refactoring and optimization for PDE-relevant XML files in Eclipse projects. It focuses on reducing file size while maintaining semantic integrity through XSLT transformation, whitespace normalization, and optional indentation.


Purpose

  • Optimize PDE XML configuration files for size and consistency
  • Apply secure XSLT transformations with whitespace normalization
  • Convert leading spaces to tabs (4 spaces β†’ 1 tab)
  • Provide optional indentation control (default: OFF for size reduction)
  • Integrate with Eclipse workspace APIs for safe file updates

Supported XML Types (PDE Files Only)

The plugin only processes PDE-relevant XML files:

Supported File Names:

  • plugin.xml - Eclipse plugin manifests
  • feature.xml - Eclipse feature definitions
  • fragment.xml - Eclipse fragment manifests

Supported File Extensions:

  • *.exsd - Extension point schema definitions
  • *.xsd - XML schema definitions

Supported Locations: Files must be in one of these locations:

  • Project root - Files directly in project folder
  • OSGI-INF - OSGi declarative services directory
  • META-INF - Manifest and metadata directory

Note: All other XML files (e.g., pom.xml, build.xml) are ignored to avoid unintended transformations.


Transformation Process

1. XSLT Transformation
  • Uses secure XML processing (external DTD/entities disabled)
  • Preserves XML structure, comments, and content
  • Default: indent="no" - Produces compact output for size reduction
  • Optional: indent="yes" - Enabled via XML_CLEANUP_INDENT preference
2. Whitespace Normalization
  • Reduce excessive empty lines - Maximum 2 consecutive empty lines
  • Leading space to tab conversion - Only at line start (not inline text)
    • Converts groups of 4 leading spaces to 1 tab
    • Preserves remainder spaces (e.g., 5 spaces β†’ 1 tab + 1 space)
    • Does NOT touch inline text or content nodes
3. Change Detection
  • Only writes file if content actually changed
  • Uses Eclipse workspace APIs (IFile.setContents())
  • Maintains file history (IResource.KEEP_HISTORY)
  • Refreshes resource after update

Configuration

Default Behavior (when XML_CLEANUP is enabled):

  • indent="no" - Compact output, no extra whitespace
  • Reduces file size by removing unnecessary whitespace
  • Converts leading spaces to tabs
  • Preserves semantic content

Optional Behavior (when XML_CLEANUP_INDENT is enabled):

  • indent="yes" - Minimal indentation applied
  • Still converts leading spaces to tabs
  • Slightly larger file size but more readable

Constants (defined in MYCleanUpConstants):

  • XML_CLEANUP - Enable XML cleanup (default: OFF)
  • XML_CLEANUP_INDENT - Enable indentation (default: OFF)

Security Features

The plugin implements secure XML processing:

  • External DTD access disabled
  • External entity resolution disabled
  • DOCTYPE declarations disallowed
  • Secure processing mode enabled

Tab Conversion Rule

Tab conversion is only applied to leading whitespace:

βœ… Converted:

    <element>  <!-- 4 leading spaces β†’ 1 tab -->

❌ Not Converted:

<element attr="value    with    spaces"/>  <!-- Inline spaces preserved -->

This ensures that:

  • Indentation is normalized to tabs
  • XML attribute values are not modified
  • Text content spacing is preserved
  • Only structural whitespace is affected

Usage

This cleanup is available as part of the JDT Clean Up framework:

  • Eclipse UI β†’ Source β†’ Clean Up
  • Configure via cleanup preferences: XML_CLEANUP and XML_CLEANUP_INDENT

Limitations

  1. PDE Files Only: Only processes plugin.xml, feature.xml, fragment.xml, *.exsd, *.xsd
  2. Location Restricted: Files must be in project root, OSGI-INF, or META-INF
  3. Leading Tabs Only: Tab conversion only applies to leading whitespace, not inline content
  4. No Schema Validation: Doesn't validate against XML schemas (relies on Eclipse PDE validation)

Test Coverage

The sandbox_xml_cleanup_test module contains comprehensive test cases for:

  • Size reduction verification
  • Semantic equality (using XMLUnit, ignoring whitespace)
  • Idempotency (second run produces no change)
  • Leading-indent-only tab conversion
  • PDE file filtering accuracy

Installation

You can use the P2 update site:

https://github.com/carstenartur/sandbox/raw/main

Warning:
Use only with a fresh Eclipse installation that can be discarded after testing.
It may break your setup. Don’t say you weren’t warned...


Documentation

This repository contains extensive documentation organized at multiple levels to help you understand, use, and contribute to the project.

πŸ“š Documentation Index

Getting Started

  • README.md (this file) - Project overview, build instructions, and plugin descriptions
  • Build Instructions - How to build the project with Maven/Tycho
  • Quickstart - Quick introduction to using the plugins
  • Installation - How to install plugins in Eclipse

Plugin-Specific Documentation

Each plugin has dedicated documentation in its module directory:

Plugin README Architecture TODO Test Docs
Cleanup Application README.md ARCHITECTURE.md TODO.md -
Common Infrastructure README.md ARCHITECTURE.md TODO.md TESTING.md
Coverage README.md ARCHITECTURE.md TODO.md -
Encoding Quickfix README.md ARCHITECTURE.md TODO.md -
Extra Search README.md ARCHITECTURE.md TODO.md -
Functional Converter README.md ARCHITECTURE.md TODO.md -
JFace Cleanup README.md ARCHITECTURE.md TODO.md -
JUnit Cleanup README.md ARCHITECTURE.md TODO.md TESTING.md
Method Reuse README.md ARCHITECTURE.md TODO.md -
Oomph Setup README.md ARCHITECTURE.md TODO.md -
Platform Helper README.md ARCHITECTURE.md TODO.md -
Product README.md ARCHITECTURE.md TODO.md -
Target Platform README.md ARCHITECTURE.md TODO.md -
Test Commons README.md ARCHITECTURE.md TODO.md -
Tools README.md ARCHITECTURE.md TODO.md -
Trigger Pattern README.md ARCHITECTURE.md TODO.md -
Usage View README.md ARCHITECTURE.md TODO.md -
Web (P2 Update Site) README.md ARCHITECTURE.md TODO.md -
XML Cleanup README.md ARCHITECTURE.md TODO.md -

Documentation Structure per Plugin:

  • README.md - Quick start guide, features overview, and usage examples
  • ARCHITECTURE.md - Design overview, implementation details, patterns used
  • TODO.md - Pending features, known issues, future enhancements
  • TESTING.md (where applicable) - Test organization, coverage, and running instructions

Test Infrastructure Documentation

Project Governance

Additional Resources

πŸ“– Documentation Guidelines for Contributors

When contributing to this project, please maintain documentation quality:

  1. Plugin Requirements: All plugin directories SHOULD contain:

    • README.md - Quick start guide with features and usage examples
    • ARCHITECTURE.md - Design and implementation overview
    • TODO.md - Open tasks and future work
  2. Navigation Headers: All plugin documentation files include navigation headers linking to:

    • Main README (this file)
    • Plugin's own README (for ARCHITECTURE and TODO files)
    • Sibling documentation files (README ↔ ARCHITECTURE ↔ TODO)
  3. Update Documentation: When making code changes:

    • Update README.md if features or usage changes
    • Update ARCHITECTURE.md if design changes
    • Update TODO.md when completing tasks or identifying new ones
    • Update main README if adding/removing plugins
  4. Test Documentation: Test modules with substantial test organization should include:

    • TESTING.md - Test structure and organization
    • TODO_TESTING.md (if applicable) - Implementation tracking for features being tested

πŸ” Finding Documentation

By Topic:

By File Location:

  • Root level: Project-wide documentation (this README, CODE_OF_CONDUCT, SECURITY)
  • Plugin directories (sandbox_*/): Plugin-specific ARCHITECTURE.md and TODO.md
  • Test directories (sandbox_*_test/): Test-specific TESTING.md and TODO_TESTING.md

Contributing

Contributions are welcome! This is an experimental sandbox project for testing Eclipse JDT cleanup implementations.

How to Contribute

  1. Fork the repository on GitHub
  2. Create a feature branch from main (the default branch):
    git checkout -b feature/my-new-cleanup
  3. Make your changes following the existing code structure and conventions
  4. Test your changes thoroughly:
    mvn -Pjacoco verify
  5. Commit your changes with clear commit messages:
    git commit -m "feat: add new cleanup for XYZ pattern"
  6. Push to your fork and create a Pull Request targeting the main branch

Guidelines

  • Follow existing code patterns and cleanup structures
  • Add comprehensive test cases for new cleanups
  • Update documentation (README, architecture.md, todo.md) as needed
  • Ensure SpotBugs, CodeQL, and all tests pass
  • Keep changes focused and minimal

Reporting Issues

Found a bug or have a feature request? Please open an issue on GitHub with:

  • Clear description of the problem or suggestion
  • Steps to reproduce (for bugs)
  • Expected vs. actual behavior
  • Eclipse and Java version information

Note: This project primarily serves as an experimental playground. Features that prove stable and useful may be contributed upstream to Eclipse JDT.


Release Process

This section describes how to create and publish a new release of the Sandbox project using the automated release workflow.

Prerequisites

  • Write access to the repository
  • All tests passing on the main branch
  • Decide on the release version number (e.g., 1.2.2)
  • Decide on the next SNAPSHOT version (e.g., 1.2.3-SNAPSHOT)

Automated Release Workflow

The release process is fully automated through GitHub Actions. To create a release:

1. Trigger the Release Workflow

  1. Go to the GitHub Actions tab
  2. Select "Release Workflow" from the workflows list
  3. Click "Run workflow" button
  4. Fill in the required inputs:
    • Release version: The version to release (e.g., 1.2.2)
    • Next SNAPSHOT version: The next development version (e.g., 1.2.3-SNAPSHOT)
  5. Click "Run workflow" to start the automated release process

2. What the Workflow Does Automatically

The workflow performs all release steps automatically:

  1. βœ… Validates inputs to ensure release_version has no -SNAPSHOT suffix and next_snapshot_version includes it
  2. βœ… Updates version in all pom.xml, MANIFEST.MF, feature.xml, and *.product files using tycho-versions-plugin for all modules except sandbox-functional-converter-core, which maintains independent versioning
  3. βœ… Verifies that no SNAPSHOT references remain (except in sandbox-functional-converter-core)
  4. βœ… Commits the release version changes
  5. βœ… Builds and verifies the release
  6. βœ… Creates and pushes git tag (vX.Y.Z) immediately
  7. βœ… Creates and pushes maintenance branch (maintenance/X.Y.x) immediately for potential backports
  8. βœ… Generates release notes from closed issues since the last release
  9. βœ… Creates GitHub release with auto-generated notes
  10. βœ… Deploys the P2 update site to GitHub Pages at https://carstenartur.github.io/sandbox/releases/X.Y.Z/
  11. βœ… Updates composite metadata to include the new release
  12. βœ… Bumps version to the next SNAPSHOT version
  13. βœ… Commits and pushes the SNAPSHOT version back to main
  14. βœ… Reminds to update Eclipse Marketplace listing

3. Post-Release Steps

After the workflow completes successfully:

  1. Verify the release:

    • Check the Releases page for the new release
    • Verify the update site is available at https://carstenartur.github.io/sandbox/releases/X.Y.Z/
  2. Update Eclipse Marketplace (if applicable):

  3. Test the release:

    • Install the plugins from the new update site in a clean Eclipse installation
    • Verify core functionality works as expected

Workflow Inputs

The automated workflow requires two inputs:

  • release_version (required):

    • The version number to release (e.g., 1.2.2)
    • Must NOT include -SNAPSHOT suffix
    • Should follow Semantic Versioning
  • next_snapshot_version (required):

    • The next development version (e.g., 1.2.3-SNAPSHOT)
    • MUST include -SNAPSHOT suffix
    • Typically the next patch, minor, or major version

Example Release

To release version 1.2.2 and prepare for 1.2.3-SNAPSHOT:

  1. Navigate to Actions β†’ Release Workflow β†’ Run workflow
  2. Enter release_version: 1.2.2
  3. Enter next_snapshot_version: 1.2.3-SNAPSHOT
  4. Click "Run workflow"
  5. Monitor the workflow progress in the Actions tab
  6. Once complete, the main branch will be at 1.2.3-SNAPSHOT, ready for development

Version Numbering

This project follows Semantic Versioning:

  • MAJOR version (X.0.0): Incompatible API changes
  • MINOR version (0.X.0): New functionality in a backward-compatible manner
  • PATCH version (0.0.X): Backward-compatible bug fixes

Release Artifacts

Each release produces:

  • Eclipse Product: Installable Eclipse IDE with bundled plugins (sandbox_product/target)
  • P2 Update Site: For installing plugins into existing Eclipse (sandbox_web/target)
  • WAR File: Web-deployable update site
  • Maven Artifacts: Published to GitHub Packages

Troubleshooting

Build fails during release:

  • Ensure all tests pass locally: mvn clean verify -Pjacoco
  • Check Java version: java -version (must be 21+)
  • Verify Maven version: mvn -version (3.9.x recommended)

GitHub Actions workflow fails:

  • Check workflow run logs in the Actions tab
  • Ensure the tag was pushed correctly: git ls-remote --tags origin
  • Verify permissions for GitHub Packages publishing

License

This project is licensed under the Eclipse Public License 2.0 (EPL-2.0).

See the LICENSE.txt file for the full license text.

Eclipse Public License 2.0

The Eclipse Public License (EPL) is a free and open-source software license maintained by the Eclipse Foundation. Key points:

  • βœ… Commercial use allowed
  • βœ… Modification allowed
  • βœ… Distribution allowed
  • βœ… Patent grant included
  • ⚠️ Disclose source for modifications
  • ⚠️ License and copyright notice required

For more information, visit: https://www.eclipse.org/legal/epl-2.0/


Copyright Β© 2021-2025 Carsten Hammer and contributors

About

Sample implementation of Product based on Eclipse.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors 5

Languages