fix: cross-module refactorings, error handling, JDT API migration #47

Merged
fred merged 19 commits from fix/43-refactoring-errors into main 2026-03-08 18:24:30 +00:00
Collaborator

Summary

  • #43 Cross-Modul-Refactorings: move_type, change_method_signature, rename, inline method fixes
  • #45 Testergebnis-Bugs: Maven Dependencies, Build-Trigger, runtime classpath, diverse Fixes
  • #46 Test-scope Dependencies + JDT API Migration für Refactorings
  • #33 findElement bevorzugt Source-Projekt statt Binary-Classpath
  • #34 Leaf-Change-Count für rename WARNING-Detection
  • #32 Einheitliches Error-Handling mit ToolErrors utility (-129 Zeilen)
  • #30 God-Class-Auflösung: RefactoringTools → RefactoringSupport, RenameRefactoring, ExtractInterfaceRefactoring, ConvertToLambdaRefactoring, ImportOrganizer
  • #35 ExtractInterface: StringBuilder → ExtractInterfaceProcessor
  • #36 ConvertToLambda: StringBuilder → ASTRewrite + LambdaExpression
  • #37 OrganizeImports: manueller AST-Visitor → OrganizeImportsOperation
  • Test-Fixtures für alle 52 MCP-Tools (TEST-PLAN.md, TESTING-INSTRUCTIONS.md)

Closes

Closes #30, #32, #33, #34, #35, #36, #37, #43

Test plan

  • mvn clean package erfolgreich
  • Smoke-Tests (tests/smoke-test.sh) bestehen
  • Test-Fixtures importieren und Gruppen A-K durchlaufen
  • Cross-Modul-Refactorings (rename, move_type, change_method_signature) verifizieren
  • ExtractInterface mit Generics/mehreren Interfaces testen
  • ConvertToLambda mit komplexen Bodies testen
  • OrganizeImports mit Star-Imports und Static-Imports testen

🤖 Generated with Claude Code

## Summary - **#43** Cross-Modul-Refactorings: move_type, change_method_signature, rename, inline method fixes - **#45** Testergebnis-Bugs: Maven Dependencies, Build-Trigger, runtime classpath, diverse Fixes - **#46** Test-scope Dependencies + JDT API Migration für Refactorings - **#33** findElement bevorzugt Source-Projekt statt Binary-Classpath - **#34** Leaf-Change-Count für rename WARNING-Detection - **#32** Einheitliches Error-Handling mit `ToolErrors` utility (-129 Zeilen) - **#30** God-Class-Auflösung: RefactoringTools → RefactoringSupport, RenameRefactoring, ExtractInterfaceRefactoring, ConvertToLambdaRefactoring, ImportOrganizer - **#35** ExtractInterface: StringBuilder → `ExtractInterfaceProcessor` - **#36** ConvertToLambda: StringBuilder → `ASTRewrite` + `LambdaExpression` - **#37** OrganizeImports: manueller AST-Visitor → `OrganizeImportsOperation` - Test-Fixtures für alle 52 MCP-Tools (TEST-PLAN.md, TESTING-INSTRUCTIONS.md) ## Closes Closes #30, #32, #33, #34, #35, #36, #37, #43 ## Test plan - [ ] `mvn clean package` erfolgreich - [ ] Smoke-Tests (`tests/smoke-test.sh`) bestehen - [ ] Test-Fixtures importieren und Gruppen A-K durchlaufen - [ ] Cross-Modul-Refactorings (rename, move_type, change_method_signature) verifizieren - [ ] ExtractInterface mit Generics/mehreren Interfaces testen - [ ] ConvertToLambda mit komplexen Bodies testen - [ ] OrganizeImports mit Star-Imports und Static-Imports testen 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- change_method_signature: use getRealErrors() to filter "potential match" warnings (same fix as rename_element)
- jdt_reload_workspace: track all imported root directories and re-import all of them on reload (not just user.dir)
- inline: catch NPE in checkInitialConditions with descriptive error message for unsupported method types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Without setProject(), JDT resolves no bindings and InlineMethodRefactoring
crashes with NPE on VariableDeclaration.getParent() for static factory methods.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
InlineMethodRefactoring.create() can throw NPE for static factory methods.
Now catches the exception and retries with the exact method name range
resolved via IMethod.getNameRange() from the Java Model API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When InlineMethodRefactoring.checkInitialConditions() throws NPE due to
null bindings in SourceAnalyzer (cross-module case), fall back to parsing
the declaring CU with full bindings and create the refactoring from the
method declaration side.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The NPE from SourceAnalyzer was escaping through checkAllConditions()
(called via checkFinalConditions) which was not wrapped in try-catch.
Now provides a descriptive error message instead of a raw stack trace.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- ProjectImporter: parse pom.xml <dependencies> to find workspace projects
  when JARs are not installed in ~/.m2 (Strategy 2 for dependency resolution)
- ProjectInfoTools: strip <dependencies> blocks before matching groupId,
  inherit groupId from parent POM when not declared directly
- CodeGenerationTools: use .exists() instead of null-check on method handles
  (IType.getMethod() always returns a handle, never null)
- RefactoringTools: add leading space before extends/implements in
  extract_interface to prevent "ClassNameextends" formatting
- DocumentationTools: add force parameter to generate_javadoc to allow
  replacing existing incomplete Javadoc

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- ExecutionTools: add CPE_PROJECT handling to runMain() classpath builder
  so dependent project output dirs are included at runtime
- ProjectInfoTools: trigger INCREMENTAL_BUILD after jdt_import_project
  so JDT creates problem markers (compilation errors) for imported projects

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously, renameViaAst fallback silently reported SUCCESS even when no
references were found. Now returns WARNING status so callers can verify.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduced findTypeInSourceProject() that selects non-binary IType with
a real resource, ensuring refactorings operate on the declaring project.
Replaced "first project wins" iteration in all 5 affected methods:
findElement, moveType, extractInterface, changeMethodSignature,
encapsulateField.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous check used top-level childCount which was always 1 due to
the CompositeChange wrapper. Now counts actual leaf changes recursively
so renames with references correctly return SUCCESS while renames without
references return WARNING when updateReferences=true.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In headless mode, nature.configure() may not reliably add the Java
builder to the build spec. Explicitly set JavaCore.BUILDER_ID in
createMavenModuleProject, importBasicJavaProject, and importGradleProject.
Also use FULL_BUILD instead of INCREMENTAL_BUILD after import since new
projects have no prior build state. This fixes jdt_get_compilation_errors
returning 0 errors for projects with compile errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract 8 shared helper methods into RefactoringSupport class:
findElement, findTypeInSourceProject, getRealErrors, getNonParticipantWarnings,
extractStatusMessages, countLeafChanges, describeChange.
Reduces RefactoringTools from 2085 to 1928 lines (Phase 1 of #30).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move all rename-specific logic (processor path, AST fallback, helpers)
into dedicated RenameRefactoring class. RefactoringTools delegates via
renameElementTool(). Reduces RefactoringTools from 1928 to 1452 lines.
Phase 2 of #30.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 3: Extract three more tools from RefactoringTools into dedicated classes.
Reduces RefactoringTools from 1452 to 886 lines (total reduction: 2085 -> 886, -57%).
Remaining 6 tools: extractMethod, moveType, inline, changeMethodSignature,
encapsulateField, introduceParameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract common error response builder ToolErrors.errorResult() that ensures
consistent JSON format (status, message, exceptionType, cause) and automatic
logging via McpLogger across all 14 tool classes (~40 catch blocks).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Include test-scope dependencies (JUnit 5 etc.) in Eclipse build path
  by changing -DincludeScope=compile to -DincludeScope=test
- Add -clean flag to launcher to prevent stale OSGi bundle cache
- Use ASTRewrite API in ConvertToLambdaRefactoring instead of StringBuilder
- Use ExtractInterfaceProcessor in ExtractInterfaceRefactoring for robust
  cross-project handling of generics and complex declarations
- Use OrganizeImportsOperation in ImportOrganizer for correct star-import
  expansion, static imports, and sorting
- Add test fixtures and TEST-PLAN entries for test-scope dependencies (A8),
  cross-project test execution (J3/J4), and ExternalServiceTest.testExecuteAndFormat

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- JavaPreferencesSettings: use org.eclipse.jdt.internal.ui.preferences (not codemanipulation)
- OrganizeImportsOperation: use org.eclipse.jdt.core.manipulation (public API)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chore: ignore Tycho-generated .tycho-consumer-pom.xml files
Some checks failed
Build and Release / build (push) Failing after 3m19s
5270ef1add
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fred merged commit 5270ef1add into main 2026-03-08 18:24:30 +00:00
fred deleted branch fix/43-refactoring-errors 2026-03-08 18:24:30 +00:00
Sign in to join this conversation.
No description provided.