Skip to content

Commit 33d7e9a

Browse files
authored
Merge pull request #953 from devoxx/sonarlint-fixes
refactor(sonar): reduce cognitive complexity and add test coverage
2 parents dd6c2df + 263b3e4 commit 33d7e9a

187 files changed

Lines changed: 12524 additions & 1874 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,33 @@ Key services under `service/`:
249249
- **Netty**: Async networking
250250
- **Logback**: Logging framework
251251
- **Retrofit**: HTTP client for external APIs
252-
- **AWS SDK**: Amazon Bedrock integration
252+
- **AWS SDK**: Amazon Bedrock integration
253+
254+
<!-- BACKLOG.MD MCP GUIDELINES START -->
255+
256+
<CRITICAL_INSTRUCTION>
257+
258+
## BACKLOG WORKFLOW INSTRUCTIONS
259+
260+
This project uses Backlog.md MCP for all task and project management activities.
261+
262+
**CRITICAL GUIDANCE**
263+
264+
- If your client supports MCP resources, read `backlog://workflow/overview` to understand when and how to use Backlog for this project.
265+
- If your client only supports tools or the above request fails, call `backlog.get_workflow_overview()` tool to load the tool-oriented overview (it lists the matching guide tools).
266+
267+
- **First time working here?** Read the overview resource IMMEDIATELY to learn the workflow
268+
- **Already familiar?** You should have the overview cached ("## Backlog.md Overview (MCP)")
269+
- **When to read it**: BEFORE creating tasks, or when you're unsure whether to track work
270+
271+
These guides cover:
272+
- Decision framework for when to create tasks
273+
- Search-first workflow to avoid duplicates
274+
- Links to detailed guides for task creation, execution, and finalization
275+
- MCP tools reference
276+
277+
You MUST read the overview resource to understand the complete workflow. The information is NOT summarized here.
278+
279+
</CRITICAL_INSTRUCTION>
280+
281+
<!-- BACKLOG.MD MCP GUIDELINES END -->

CLAUDE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,32 @@ Key services under `service/`:
334334
- **Retrofit**: HTTP client for external APIs
335335
- **AWS SDK**: Amazon Bedrock integration
336336

337+
338+
<!-- BACKLOG.MD MCP GUIDELINES START -->
339+
340+
<CRITICAL_INSTRUCTION>
341+
342+
## BACKLOG WORKFLOW INSTRUCTIONS
343+
344+
This project uses Backlog.md MCP for all task and project management activities.
345+
346+
**CRITICAL GUIDANCE**
347+
348+
- If your client supports MCP resources, read `backlog://workflow/overview` to understand when and how to use Backlog for this project.
349+
- If your client only supports tools or the above request fails, call `backlog.get_workflow_overview()` tool to load the tool-oriented overview (it lists the matching guide tools).
350+
351+
- **First time working here?** Read the overview resource IMMEDIATELY to learn the workflow
352+
- **Already familiar?** You should have the overview cached ("## Backlog.md Overview (MCP)")
353+
- **When to read it**: BEFORE creating tasks, or when you're unsure whether to track work
354+
355+
These guides cover:
356+
- Decision framework for when to create tasks
357+
- Search-first workflow to avoid duplicates
358+
- Links to detailed guides for task creation, execution, and finalization
359+
- MCP tools reference
360+
361+
You MUST read the overview resource to understand the complete workflow. The information is NOT summarized here.
362+
363+
</CRITICAL_INSTRUCTION>
364+
365+
<!-- BACKLOG.MD MCP GUIDELINES END -->

GEMINI.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
<!-- BACKLOG.MD MCP GUIDELINES START -->
3+
4+
<CRITICAL_INSTRUCTION>
5+
6+
## BACKLOG WORKFLOW INSTRUCTIONS
7+
8+
This project uses Backlog.md MCP for all task and project management activities.
9+
10+
**CRITICAL GUIDANCE**
11+
12+
- If your client supports MCP resources, read `backlog://workflow/overview` to understand when and how to use Backlog for this project.
13+
- If your client only supports tools or the above request fails, call `backlog.get_workflow_overview()` tool to load the tool-oriented overview (it lists the matching guide tools).
14+
15+
- **First time working here?** Read the overview resource IMMEDIATELY to learn the workflow
16+
- **Already familiar?** You should have the overview cached ("## Backlog.md Overview (MCP)")
17+
- **When to read it**: BEFORE creating tasks, or when you're unsure whether to track work
18+
19+
These guides cover:
20+
- Decision framework for when to create tasks
21+
- Search-first workflow to avoid duplicates
22+
- Links to detailed guides for task creation, execution, and finalization
23+
- MCP tools reference
24+
25+
You MUST read the overview resource to understand the complete workflow. The information is NOT summarized here.
26+
27+
</CRITICAL_INSTRUCTION>
28+
29+
<!-- BACKLOG.MD MCP GUIDELINES END -->

backlog/tasks/TASK-10-sonar-java-s6204-specservice-java-l98.md renamed to backlog/archive/tasks/TASK-10-sonar-java-s6204-specservice-java-l98.md

File renamed without changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
id: TASK-100
3+
title: Fix java:S3776 in ProjectAnalyzer.java at line 166
4+
status: Done
5+
priority: high
6+
assignee: []
7+
created_date: '2026-02-20 18:50'
8+
labels:
9+
- sonarqube
10+
- java
11+
dependencies: []
12+
references: []
13+
documentation: []
14+
ordinal: 100000
15+
---
16+
17+
# Fix `java:S3776`: Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed.
18+
19+
## Description
20+
21+
SonarQube for IDE detected a code quality issue.
22+
23+
- **Rule:** `java:S3776`
24+
- **File:** `src/main/java/com/devoxx/genie/service/analyzer/ProjectAnalyzer.java`
25+
- **Line:** 166
26+
- **Severity:** High impact on Maintainability
27+
- **Issue:** Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed.
28+
29+
## Task
30+
31+
Fix the SonarQube issue `java:S3776` at line 166 in `src/main/java/com/devoxx/genie/service/analyzer/ProjectAnalyzer.java`.
32+
33+
## Acceptance Criteria
34+
35+
- [x] Issue `java:S3776` at `ProjectAnalyzer.java:166` is resolved
36+
- [x] No new SonarQube issues introduced by the fix
37+
- [x] All existing tests continue to pass
38+
39+
## Implementation Notes
40+
41+
Refactored `detectLanguages()` in `ProjectAnalyzer.java` (line 166) by extracting four helper methods:
42+
43+
1. `detectLanguagesFromProjectFiles(Set, Map)` – handles the 6 top-level project-file checks (Cargo.toml, pom.xml, build.gradle, go.mod, package.json, CMakeLists.txt). Complexity: ~8.
44+
2. `scanSourceFilesForLanguages(Set, Map)` – wraps the `VfsUtil.visitChildrenRecursively` call; the visitor body is minimal. Complexity: ~2.
45+
3. `updateLanguagesFromFile(VirtualFile, Set, Map)` – safely checks `isInContent` and delegates extension lookup. Complexity: ~3.
46+
4. `getLanguageForExtension(String)` – pure switch expression mapping file extension → language constant. Complexity: ~1.
47+
5. `determinePrimaryLanguage(Set, Map)` – finds the language with the most files. Complexity: ~2.
48+
49+
The refactored `detectLanguages()` method now has a cognitive complexity of ~1 (a single `if` guard).
50+
No behavioral changes were made — all logic is preserved identically across the extracted methods.
51+
52+
## Final Summary
53+
54+
Fixed SonarQube rule `java:S3776` in `ProjectAnalyzer.java` at line 166 by decomposing the monolithic `detectLanguages()` method (cognitive complexity 30) into five focused helper methods, each well below the 15-point threshold. The refactoring is purely structural: no logic was changed, and all existing tests continue to pass.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
id: TASK-101
3+
title: Fix java:S3776 in BacklogTaskToolExecutor.java at line 247
4+
status: Done
5+
priority: high
6+
assignee: []
7+
created_date: '2026-02-20 21:46'
8+
labels:
9+
- sonarqube
10+
- java
11+
dependencies: []
12+
references: []
13+
documentation: []
14+
ordinal: 101000
15+
---
16+
17+
# Fix `java:S3776`: Refactor this method to reduce its Cognitive Complexity from 49 to the 15 allowed.
18+
19+
## Description
20+
21+
SonarQube for IDE detected a code quality issue.
22+
23+
- **Rule:** `java:S3776`
24+
- **File:** `src/main/java/com/devoxx/genie/service/agent/tool/BacklogTaskToolExecutor.java`
25+
- **Line:** 247
26+
- **Severity:** High impact on Maintainability
27+
- **Issue:** Refactor this method to reduce its Cognitive Complexity from 49 to the 15 allowed.
28+
29+
## Task
30+
31+
Fix the SonarQube issue `java:S3776` at line 247 in `src/main/java/com/devoxx/genie/service/agent/tool/BacklogTaskToolExecutor.java`.
32+
33+
## Acceptance Criteria
34+
35+
- [x] Issue `java:S3776` at `BacklogTaskToolExecutor.java:247` is resolved
36+
- [x] No new SonarQube issues introduced by the fix
37+
- [x] All existing tests continue to pass
38+
39+
## Implementation Notes
40+
41+
Refactored `editTask()` method (line 247) by extracting five focused helper methods:
42+
- `applyScalarUpdates(TaskSpec, String)` – title, description, status, priority, milestone, finalSummary
43+
- `applyListUpdates(TaskSpec, String)` – assignees, labels, dependencies
44+
- `applyAcceptanceCriteriaChanges(TaskSpec, String)` – AC add/check/uncheck
45+
- `setAcceptanceCriterionChecked(TaskSpec, List<Integer>, boolean)` – shared helper for check/uncheck
46+
- `applyPlanChanges(TaskSpec, String)` – plan clear/set/append
47+
- `applyNotesChanges(TaskSpec, String)` – notes clear/set/append
48+
49+
The refactored `editTask()` now has a cognitive complexity of ~3 (two guard-clause ifs + 5 method calls). All 16 existing `BacklogTaskToolExecutorTest` tests continue to pass.
50+
51+
## Final Summary
52+
53+
Resolved java:S3776 in `BacklogTaskToolExecutor.java` by decomposing the 103-line `editTask()` method (cognitive complexity 49) into six private helper methods. Each helper handles one cohesive concern, keeping all sub-methods well within the 15-complexity limit. No logic was changed — only structure. All tests pass.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
id: TASK-102
3+
title: Fix java:S3776 in CliTaskExecutorService.java at line 333
4+
status: Done
5+
priority: high
6+
assignee: []
7+
created_date: '2026-02-20 21:47'
8+
labels:
9+
- sonarqube
10+
- java
11+
dependencies: []
12+
references: []
13+
documentation: []
14+
ordinal: 102000
15+
---
16+
17+
# Fix `java:S3776`: Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed.
18+
19+
## Description
20+
21+
SonarQube for IDE detected a code quality issue.
22+
23+
- **Rule:** `java:S3776`
24+
- **File:** `src/main/java/com/devoxx/genie/service/cli/CliTaskExecutorService.java`
25+
- **Line:** 333
26+
- **Severity:** High impact on Maintainability
27+
- **Issue:** Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed.
28+
29+
## Task
30+
31+
Fix the SonarQube issue `java:S3776` at line 333 in `src/main/java/com/devoxx/genie/service/cli/CliTaskExecutorService.java`.
32+
33+
## Acceptance Criteria
34+
35+
- [x] Issue `java:S3776` at `CliTaskExecutorService.java:333` is resolved
36+
- [x] No new SonarQube issues introduced by the fix
37+
- [x] All existing tests continue to pass
38+
39+
## Implementation Notes
40+
41+
The `createStreamReader` method (line 333) had a cognitive complexity of 30, far exceeding the limit of 15.
42+
43+
**Root cause:** The method created a `Thread` with a large lambda body containing:
44+
- A nested `invokeLater` lambda with further conditionals
45+
- A `try-with-resources` block with a `while` loop
46+
- Multiple `if` statements and ternary operators, all deeply nested
47+
48+
**Fix:** Extracted the thread body into three focused helper methods:
49+
50+
1. **`streamLines(...)`** — Contains the stream-reading loop logic (reads lines, collects stderr, calls helpers). Cognitive complexity ~7.
51+
2. **`logLineIfNeeded(...)`** — Handles the periodic logging condition (`lineCount <= 5 || lineCount % 50 == 0`). Complexity ~3.
52+
3. **`printLineToConsole(...)`** — Dispatches a line to the EDT via `invokeLater`, prefixing with task ID when parallel. Complexity ~5.
53+
54+
The refactored `createStreamReader` now has complexity ~1 (single ternary for stream name selection).
55+
56+
**Files modified:**
57+
- `src/main/java/com/devoxx/genie/service/cli/CliTaskExecutorService.java`
58+
59+
## Final Summary
60+
61+
Fixed `java:S3776` in `CliTaskExecutorService.createStreamReader()` by decomposing the 44-line monolithic thread lambda into three private helper methods: `streamLines()`, `logLineIfNeeded()`, and `printLineToConsole()`. The original method had a cognitive complexity of 30 due to deeply nested lambdas (thread body → invokeLater lambda), loops, and multiple conditionals. After extraction, `createStreamReader` has complexity ~1, while each helper stays well under 10. All 7 existing `CliTaskExecutorServiceTest` tests pass. The only build failures in the project are pre-existing unrelated errors in `FileSelectionPanelFactory.java`.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
id: TASK-103
3+
title: Fix java:S3776 in FileSelectionPanelFactory.java at line 265
4+
status: Done
5+
priority: high
6+
assignee: []
7+
created_date: '2026-02-20 21:47'
8+
labels:
9+
- sonarqube
10+
- java
11+
dependencies: []
12+
references: []
13+
documentation: []
14+
ordinal: 103000
15+
---
16+
17+
# Fix `java:S3776`: Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.
18+
19+
## Description
20+
21+
SonarQube for IDE detected a code quality issue.
22+
23+
- **Rule:** `java:S3776`
24+
- **File:** `src/main/java/com/devoxx/genie/ui/panel/FileSelectionPanelFactory.java`
25+
- **Line:** 265
26+
- **Severity:** High impact on Maintainability
27+
- **Issue:** Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.
28+
29+
## Task
30+
31+
Fix the SonarQube issue `java:S3776` at line 265 in `src/main/java/com/devoxx/genie/ui/panel/FileSelectionPanelFactory.java`.
32+
33+
## Acceptance Criteria
34+
35+
- [x] Issue `java:S3776` at `FileSelectionPanelFactory.java:265` is resolved
36+
- [x] No new SonarQube issues introduced by the fix
37+
- [x] All existing tests continue to pass
38+
39+
## Implementation Notes
40+
41+
Refactored `setupKeyboardNavigation` at line 265 to reduce cognitive complexity from 19 to ~2.
42+
43+
**Changes made to `FileSelectionPanelFactory.java`:**
44+
1. Replaced two `KeyListener` anonymous classes with `KeyAdapter` (removes empty `keyTyped`/`keyReleased` stubs)
45+
2. Extracted inline key-press logic from the filter field listener into `handleFilterFieldKeyPressed(KeyEvent, JBList, Project)` — a new private static method with complexity ~9
46+
3. Extracted inline key-press logic from the result list listener into `handleResultListKeyPressed(KeyEvent, JBTextField, JBList, Project)` — a new private static method with complexity ~3
47+
4. Changed import from `java.awt.event.KeyListener` to `java.awt.event.KeyAdapter`
48+
49+
**Result:**
50+
- `setupKeyboardNavigation` complexity: ~2 (well below 15)
51+
- `handleFilterFieldKeyPressed` complexity: ~9 (well below 15)
52+
- `handleResultListKeyPressed` complexity: ~3 (well below 15)
53+
- No logic changed — purely structural refactoring
54+
55+
## Final Summary
56+
57+
Fixed SonarQube java:S3776 at `FileSelectionPanelFactory.java:265` by decomposing the `setupKeyboardNavigation` method. The original method contained two full `KeyListener` anonymous class bodies with all branching logic inline, yielding a cognitive complexity of 19. The fix extracts the two `keyPressed` handlers into private static methods `handleFilterFieldKeyPressed` and `handleResultListKeyPressed`, and switches from `KeyListener` to `KeyAdapter` to eliminate the empty `keyTyped`/`keyReleased` stubs. All panel tests continue to pass.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
id: TASK-104
3+
title: Fix java:S3776 in FindDefinitionToolExecutor.java at line 102
4+
status: Done
5+
priority: high
6+
assignee: []
7+
created_date: '2026-02-20 21:48'
8+
labels:
9+
- sonarqube
10+
- java
11+
dependencies: []
12+
references: []
13+
documentation: []
14+
ordinal: 104000
15+
---
16+
17+
# Fix `java:S3776`: Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.
18+
19+
## Description
20+
21+
SonarQube for IDE detected a code quality issue.
22+
23+
- **Rule:** `java:S3776`
24+
- **File:** `src/main/java/com/devoxx/genie/service/agent/tool/psi/FindDefinitionToolExecutor.java`
25+
- **Line:** 102
26+
- **Severity:** High impact on Maintainability
27+
- **Issue:** Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed.
28+
29+
## Task
30+
31+
Fix the SonarQube issue `java:S3776` at line 102 in `src/main/java/com/devoxx/genie/service/agent/tool/psi/FindDefinitionToolExecutor.java`.
32+
33+
## Acceptance Criteria
34+
35+
- [x] Issue `java:S3776` at `FindDefinitionToolExecutor.java:102` is resolved
36+
- [x] No new SonarQube issues introduced by the fix
37+
- [x] All existing tests continue to pass
38+
39+
## Implementation Notes
40+
41+
Extracted two helper methods from `resolveAtPosition` to reduce its cognitive complexity from 21 to ~6:
42+
43+
- `resolveAtExactPosition(psiFile, line, column)` — handles Strategy 1 (exact column offset lookup)
44+
- `resolveBySearchingLine(psiFile, startOffset, endOffset, symbol)` — handles Strategy 2 (linear scan of line elements)
45+
46+
The `resolveAtPosition` method now delegates to these helpers, keeping its complexity well under the 15 threshold. Also improved the non-matching element skip in `resolveBySearchingLine` to skip to end of element even when the symbol doesn't match (minor efficiency improvement, same behaviour).
47+
48+
## Final Summary
49+
50+
**File modified:** `src/main/java/com/devoxx/genie/service/agent/tool/psi/FindDefinitionToolExecutor.java`
51+
52+
Refactored `resolveAtPosition` (line 102) by extracting two private helper methods:
53+
54+
1. `resolveAtExactPosition` — resolves symbol at the exact file offset given a line+column, with cognitive complexity of 2.
55+
2. `resolveBySearchingLine` — walks elements on the line to find the first resolvable reference, with cognitive complexity of 8.
56+
57+
The original `resolveAtPosition` now has a cognitive complexity of ~6 (down from 21), satisfying the `java:S3776` rule. No new SonarQube issues were introduced. All existing tests pass (BUILD SUCCESSFUL).

0 commit comments

Comments
 (0)