Repository navigation
Description
Problem
The class-scoping logic in gitgalaxy/core/detector.py (lines 532-557) is flat and non-nesting-aware. It uses a single regex to find all class/struct/interface/trait/enum declarations, then assigns each class's scope to run from its declaration to the next class declaration's start position (line 541):
end_idx = class_matches[i + 1].start() if i + 1 < len(class_matches) else len(code_stream)Bug
When a class contains a nested/inner class declaration (legal in Java, C#, TypeScript, PHP, Kotlin, Dart, C++, Scala, etc.), the nested class's class keyword produces its own regex match. That match becomes class_matches[i+1] for the outer class, so the outer class's scope is truncated to end right where the nested class begins.
Consequence: Any method physically declared in the outer class after the nested class declaration gets silently excluded from the outer class's metrics. The method-linking loop (lines 560-584) does:
if cls["_start_line"] <= func.get("start_line", 0) <= cls["_end_line"]:Methods declared after the nested class have start_line > cls["_end_line"], so they fail this check and are dropped entirely from:
method_countstate_entanglementlcom_score
This corrupts every per-class metric the engine currently computes for any class containing a nested class — not just a future LCOM redesign.
Example
class Outer {
void method1() { }
class Inner { // Outer's scope ends here in current logic
void innerMethod() { }
}
void method2() { } // SILENTLY DROPPED from Outer's method_count
}Fix Location
- Class scoping logic:
gitgalaxy/core/detector.pylines 532-557 - Method-linking loop:
gitgalaxy/core/detector.pylines 560-584
Fix Direction
A real fix needs brace/indent-depth-aware scope tracking (not simple "until next match") similar to how the engine already tracks nesting depth elsewhere for other constructs. The current flat assignment strategy cannot handle nested class declarations.
Blocking
This is a standalone correctness bug affecting current method_count/state_entanglement output today for any class with a nested class inside it, and is also a blocking prerequisite for issue #1018 (LCOM redesign).
Testing
No existing test coverage found for nested class declarations in the class-scoping logic.
Activity
Remove LCOM (Lack of Cohesion of Methods) metric from the core engine (…
Re-bless golden master fixtures for #1040 merging into main
Fix nested functions being silently dropped from extraction (#1041) (#…