Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public static void main(String[] args) {
.findFirst()
.orElse("");
boolean isServe = "serve".equalsIgnoreCase(command);
boolean isIndex = "index".equalsIgnoreCase(command);
boolean isEnrich = "enrich".equalsIgnoreCase(command);

if (isServe) {
app.setAdditionalProfiles("serving");
Expand Down
31 changes: 7 additions & 24 deletions src/main/java/io/github/randomcodespace/iq/analyzer/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import io.github.randomcodespace.iq.detector.DetectorResult;
import io.github.randomcodespace.iq.detector.DetectorUtils;
import io.github.randomcodespace.iq.grammar.AntlrParserFactory;
import io.github.randomcodespace.iq.intelligence.FileClassification;
import io.github.randomcodespace.iq.intelligence.FileEntry;
import io.github.randomcodespace.iq.intelligence.FileInventory;
import io.github.randomcodespace.iq.intelligence.RepositoryIdentity;
import io.github.randomcodespace.iq.model.CodeEdge;
import io.github.randomcodespace.iq.model.CodeNode;
Expand Down Expand Up @@ -274,9 +271,8 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
int totalFiles = files.size();
report.accept("Found " + totalFiles + " files");

// 1b. Resolve repository identity and build file inventory
// 1b. Resolve repository identity
RepositoryIdentity repoIdentity = RepositoryIdentity.resolve(root);
FileInventory fileInventory = buildFileInventory(files, cache);

// Compute language breakdown
Map<String, Integer> languageBreakdown = new HashMap<>();
Expand Down Expand Up @@ -384,9 +380,12 @@ private AnalysisResult runWithCache(Path root, Integer parallelism, AnalysisCach
report.accept("Linking cross-file relationships...");
builder.runLinkers(linkers);

// Flush and collect deferred edges
GraphBuilder.FlushResult flushed = builder.flush();
List<io.github.randomcodespace.iq.model.CodeEdge> recoveredEdges = builder.flushDeferred();
// Flush buffered graph state and retry any deferred edges so the
// side effects (provenance stamping, edge validation, dropped-edge
// counters) still run even though we read the results straight off
// the builder below.
builder.flush();
builder.flushDeferred();

// 5. Classify layers
report.accept("Classifying layers...");
Expand Down Expand Up @@ -1619,22 +1618,6 @@ private DetectorResult analyzeFileRegexOnly(DiscoveredFile file, Path repoPath,
return DetectorResult.of(allNodes, allEdges);
}

/**
* Build a deterministic FileInventory from the list of discovered files.
* Content hashes are reused from {@code cache} when available (no re-read of files).
* Hashes remain null for files not yet present in the cache.
*/
private static FileInventory buildFileInventory(List<DiscoveredFile> files, AnalysisCache cache) {
List<FileEntry> entries = new ArrayList<>(files.size());
for (DiscoveredFile f : files) {
String relPath = f.path().toString().replace('\\', '/');
FileClassification cls = FileEntry.classify(relPath, f.language());
String contentHash = cache != null ? cache.getHashForPath(relPath) : null;
entries.add(new FileEntry(relPath, f.language(), f.sizeBytes(), contentHash, cls));
}
return new FileInventory(entries);
}

/**
* Get the current git HEAD commit SHA, or null if not a git repo.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private void addGitDiscoveredFile(Path root, List<DiscoveredFile> result, String
try {
size = Files.size(absPath);
} catch (IOException e) {
log.debug("Skipping {} -- could not read size", absPath, e);
return;
}
long maxSize = CONFIG_LANGUAGES.contains(language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* Uses H2 in embedded mode — pure Java, no JNI, MVCC concurrency,
* fully compatible with virtual threads.
*/
public class AnalysisCache implements Closeable {
public final class AnalysisCache implements Closeable {

private static final Logger log = LoggerFactory.getLogger(AnalysisCache.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.NumberFormat;
Expand Down Expand Up @@ -125,7 +126,7 @@
}
}

private int enrichFromCache(AnalysisCache cache, Path root, NumberFormat nf, Instant start) {

Check failure on line 129 in src/main/java/io/github/randomcodespace/iq/cli/EnrichCommand.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 94 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=RandomCodeSpace_codeiq&issues=AZ3BU1fVUqW5vcyK-2KC&open=AZ3BU1fVUqW5vcyK-2KC&pullRequest=71
// Load all nodes and edges from H2
List<CodeNode> allNodes = cache.loadAllNodes();
List<CodeEdge> allEdges = cache.loadAllEdges();
Expand All @@ -149,9 +150,12 @@
builder.addEdges(allEdges);
builder.runLinkers(linkers);

// Flush and collect valid edges
GraphBuilder.FlushResult flushed = builder.flush();
List<CodeEdge> recoveredEdges = builder.flushDeferred();
// Flush buffered graph state and retry any deferred edges so the
// side effects (provenance stamping, edge validation, dropped-edge
// counters) still run even though we read enriched nodes/edges
// straight off the builder below.
builder.flush();
builder.flushDeferred();

List<CodeNode> enrichedNodes = new ArrayList<>(builder.getNodes());
List<CodeEdge> enrichedEdges = new ArrayList<>(builder.getEdges());
Expand Down Expand Up @@ -422,7 +426,7 @@

return 0;

} catch (Exception e) {
} catch (IOException | RuntimeException e) {
log.error("Enrichment failed", e);
CliOutput.error("Enrichment failed: " + e.getMessage());
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ record ComponentEntry(String name, String sourceId, int matchStart) {}

// RENDERS edges: scope JSX tag search to each component's body section.
// A component's body is from its match position to the next component's position.
Set<String> allDetected = new HashSet<>(componentNames);
allDetected.addAll(hookNames);

componentEntries.sort(Comparator.comparingInt(ComponentEntry::matchStart));

for (int i = 0; i < componentEntries.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ protected DetectorResult detectWithRegex(DetectorContext ctx) {

// Methods
Matcher mm = METHOD_RE.matcher(text);
Set<Integer> methodPositions = new HashSet<>();
while (mm.find()) {
methodPositions.add(mm.start());
String receiver = mm.group(1);
String methodName = mm.group(2);
boolean exported = Character.isUpperCase(methodName.charAt(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,12 @@ public Map<String, Object> serviceDependents(String serviceName, List<CodeNode>
public Map<String, Object> blastRadius(String nodeId, List<CodeNode> nodes, List<CodeEdge> edges) {
// Build adjacency for BFS
Map<String, List<String>> adjacency = new HashMap<>();
Map<String, EdgeKind> edgeKinds = new HashMap<>();
for (CodeEdge edge : edges) {
if (!RUNTIME_EDGES.contains(edge.getKind())) continue;
String src = edge.getSourceId();
String tgt = edge.getTarget() != null ? edge.getTarget().getId() : null;
if (src == null || tgt == null) continue;
adjacency.computeIfAbsent(src, k -> new ArrayList<>()).add(tgt);
edgeKinds.put(src + "->" + tgt, edge.getKind());
}

// BFS from nodeId, max depth 5
Expand Down
Loading