Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(dead-code): treat @GlideModule as a tooling-loaded root (#3886)

Abdelhadi Salmaouicd867a72a32e
diff --git a/packages/core/src/repowise/core/analysis/dead_code/constants.py b/packages/core/src/repowise/core/analysis/dead_code/constants.py
index bd86080e1..814f51b55 100644
--- a/packages/core/src/repowise/core/analysis/dead_code/constants.py
+++ b/packages/core/src/repowise/core/analysis/dead_code/constants.py
@@ -897,6 +897,9 @@ _FRAMEWORK_DECORATORS: tuple[str, ...] = (
"Module",
"Provides",
"Binds",
+ # Glide: its annotation processor generates ``GeneratedAppGlideModule``,
+ # which instantiates the annotated class. Nothing in source names it.
+ "GlideModule",
# Compose previews, rendered by the IDE (prefix match covers
# ``PreviewLightDark``, ``PreviewScreenSizes`` and the other presets).
"Preview",
diff --git a/packages/core/src/repowise/core/analysis/dead_code/jvm_reachability.py b/packages/core/src/repowise/core/analysis/dead_code/jvm_reachability.py
index fc9456acc..f307f6420 100644
--- a/packages/core/src/repowise/core/analysis/dead_code/jvm_reachability.py
+++ b/packages/core/src/repowise/core/analysis/dead_code/jvm_reachability.py
@@ -81,6 +81,7 @@ _STEREOTYPE_ANNOTATIONS: frozenset[str] = frozenset({
"RestControllerEndpoint",
"RegisterForReflection",
"Module", # Dagger / Hilt
+ "GlideModule", # Glide annotation processor
# JMH runs these by reflection; ``Benchmark`` sits on the methods.
"State",
"BenchmarkMode",
diff --git a/tests/unit/dead_code/test_compose_hilt_roots.py b/tests/unit/dead_code/test_compose_hilt_roots.py
index e2bbc6d24..0e97d3dc8 100644
--- a/tests/unit/dead_code/test_compose_hilt_roots.py
+++ b/tests/unit/dead_code/test_compose_hilt_roots.py
@@ -51,8 +51,9 @@ _FILES = {
}
-def _report(root: Path):
- source_map = {rel: text.encode() for rel, text in _FILES.items()}
+def _report(root: Path, files: dict[str, str] | None = None):
+ files = _FILES if files is None else files
+ source_map = {rel: text.encode() for rel, text in files.items()}
for rel, source in source_map.items():
path = root / rel
path.parent.mkdir(parents=True, exist_ok=True)
@@ -143,3 +144,65 @@ def test_qualified_use_matches_by_fully_qualified_name():
assert not _is_framework_registered(["@org.sample.other.ThemeShots"], visible), path
# In the other class's package, the bare name means the non-preview one.
assert not _is_framework_registered(["@ThemeShots"], meta.visible_in("app/OtherPackage.kt"))
+
+
+# Glide's annotation processor generates ``GeneratedAppGlideModule``, which
+# instantiates the annotated module class. Nothing in source names it, so both
+# the file and the class were reported dead (AntennaPod's ``ApGlideModule``).
+_GLIDE_ANNOTATED = "app/src/main/java/com/example/glide/annotated"
+_GLIDE_BARE = "app/src/main/java/com/example/glide/bare"
+
+_GLIDE_FILES = {
+ f"{_GLIDE_ANNOTATED}/ApGlideModule.java": (
+ "package com.example.glide.annotated;\n"
+
+ "\n"
+
+ "@GlideModule\n"
+
+ "public class ApGlideModule extends AppGlideModule {\n"
+
+ " @Override\n"
+
+ " public void applyOptions(Context context, GlideBuilder builder) {\n"
+
+ " builder.setLogLevel(6);\n"
+
+ " }\n"
+
+ "}\n"
+
+ ),
+ f"{_GLIDE_BARE}/BareGlideModule.java": (
+ "package com.example.glide.bare;\n"
+
+ "\n"
+
+ "public class BareGlideModule extends AppGlideModule {\n"
+
+ " @Override\n"
+
+ " public void applyOptions(Context context, GlideBuilder builder) {\n"
+
+ " builder.setLogLevel(6);\n"
+
+ " }\n"
+
+ "}\n"
+
+ ),
+}
+
+
+def test_glide_module_is_instantiated_by_the_generated_component(tmp_path: Path):
+ report = _report(tmp_path, _GLIDE_FILES)
+ flagged = _of(report, DeadCodeKind.UNUSED_EXPORT) | _of(report, DeadCodeKind.UNUSED_INTERNAL)
+ assert "ApGlideModule.java" not in _of(report, DeadCodeKind.UNREACHABLE_FILE)
+ assert "ApGlideModule" not in flagged
+ # Glide ignores a module class without the annotation, so it stays reported.
+ assert "BareGlideModule.java" in _of(report, DeadCodeKind.UNREACHABLE_FILE)
+ assert "BareGlideModule" in flagged
+
+
+def test_framework_registration_accepts_the_glide_annotation():
+ assert _is_framework_registered(["@GlideModule"])