Skip to content

Commit

Permalink
Refactor analysis code to use callbacks instead of iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Oct 23, 2024
1 parent ab058ad commit 3cd53c3
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 309 deletions.
2 changes: 1 addition & 1 deletion config/staticconfig/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func Analyze(pkgs []*packages.Package) Analysis {
},
}

if !findDogma(ctx) {
if !resolveDogmaPackage(ctx) {
// If the dogma package is not found as an import, none of the packages
// can possibly have types that implement [dogma.Application] because
// doing so requires referring to [dogma.ApplicationConfigurer].
Expand Down
63 changes: 26 additions & 37 deletions config/staticconfig/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,36 @@ import (

"github.com/dogmatiq/enginekit/config"
"github.com/dogmatiq/enginekit/config/internal/configbuilder"
"github.com/dogmatiq/enginekit/internal/typename"
)

// analyzeApplicationType analyzes t, which must be an implementation of
// [dogma.Application].
func analyzeApplicationType(ctx *context, t types.Type) {
ctx.Analysis.Applications = append(
ctx.Analysis.Applications,
configbuilder.Application(
func(b *configbuilder.ApplicationBuilder) {
b.SetSourceTypeName(typename.OfStatic(t))

for call := range findConfigurerCalls(ctx, b, t) {
switch call.Method.Name() {
case "Identity":
analyzeIdentityCall(b, call)
case "RegisterAggregate":
b.Aggregate(func(b *configbuilder.AggregateBuilder) {
b.UpdateFidelity(call.Fidelity)
analyzeAggregate(ctx, b, call.Args[0])
})
case "RegisterProcess":
b.Process(func(b *configbuilder.ProcessBuilder) {
b.UpdateFidelity(call.Fidelity)
analyzeProcess(ctx, b, call.Args[0])
})
case "RegisterIntegration":
b.Integration(func(b *configbuilder.IntegrationBuilder) {
b.UpdateFidelity(call.Fidelity)
analyzeIntegration(ctx, b, call.Args[0])
})
case "RegisterProjection":
b.Projection(func(b *configbuilder.ProjectionBuilder) {
b.UpdateFidelity(call.Fidelity)
analyzeProjection(ctx, b, call.Args[0])
})
default:
b.UpdateFidelity(config.Incomplete)
}
}
},
),
app := configbuilder.Application(
func(b *configbuilder.ApplicationBuilder) {
analyzeEntity(
ctx,
t,
b,
analyzeApplicationConfigurerCall,
)
},
)

ctx.Analysis.Applications = append(ctx.Analysis.Applications, app)
}

func analyzeApplicationConfigurerCall(ctx *configurerCallContext[*configbuilder.ApplicationBuilder]) {
switch ctx.Method.Name() {
case "RegisterAggregate":
analyzeHandler(ctx, ctx.Builder.Aggregate, nil)
case "RegisterProcess":
analyzeHandler(ctx, ctx.Builder.Process, nil)
case "RegisterIntegration":
analyzeHandler(ctx, ctx.Builder.Integration, nil)
case "RegisterProjection":
analyzeHandler(ctx, ctx.Builder.Projection, analyzeProjectionConfigurerCall)
default:
ctx.Builder.UpdateFidelity(config.Incomplete)
}
}
162 changes: 0 additions & 162 deletions config/staticconfig/configurer.go

This file was deleted.

4 changes: 2 additions & 2 deletions config/staticconfig/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type context struct {
Analysis *Analysis
}

// findDogma updates ctx with information about the Dogma package.
// resolveDogmaPackage updates ctx with information about the Dogma package.
//
// It returns false if the Dogma package has not been imported.
func findDogma(ctx *context) bool {
func resolveDogmaPackage(ctx *context) bool {
for _, pkg := range ctx.Program.AllPackages() {
if pkg.Pkg.Path() != "github.com/dogmatiq/dogma" {
continue
Expand Down
Loading

0 comments on commit 3cd53c3

Please sign in to comment.