Skip to content

Commit 06f9a28

Browse files
committed
chore: Address review comments requires minor changes
1 parent a994362 commit 06f9a28

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

internal/injector/aspect/advice/call_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestAppendArgs(t *testing.T) {
2626

2727
testCases := map[string]testCase{
2828
"imports-none": {
29-
argType: typed.MustTypeName("any"),
29+
argType: typed.Any,
3030
args: []*code.Template{code.MustTemplate("true", nil, context.GoLangVersion{})},
3131
},
3232
"imports-from-arg-type": {
@@ -35,7 +35,7 @@ func TestAppendArgs(t *testing.T) {
3535
expectedImports: []string{"net/http"},
3636
},
3737
"imports-from-templates": {
38-
argType: typed.MustTypeName("any"),
38+
argType: typed.Any,
3939
args: []*code.Template{
4040
code.MustTemplate("imp.Value", map[string]string{"imp": "github.com/namespace/foo"}, context.GoLangVersion{}),
4141
code.MustTemplate("imp.Value", map[string]string{"imp": "github.com/namespace/bar"}, context.GoLangVersion{}),

internal/injector/config/builtin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var builtIn = configGo{
2222
ID: "built.WithOrchestrion",
2323
TracerInternal: true, // This is safe to apply in the tracer itself
2424
JoinPoint: join.AllOf(
25-
join.ValueDeclaration(typed.MustTypeName("bool")),
25+
join.ValueDeclaration(typed.Bool),
2626
join.OneOf(
2727
join.DeclarationOf("github.com/DataDog/orchestrion/runtime/built", "WithOrchestrion"),
2828
join.Directive("orchestrion:enabled"),
@@ -39,7 +39,7 @@ var builtIn = configGo{
3939
ID: "built.WithOrchestrionVersion",
4040
TracerInternal: true, // This is safe to apply in the tracer itself
4141
JoinPoint: join.AllOf(
42-
join.ValueDeclaration(typed.MustTypeName("string")),
42+
join.ValueDeclaration(typed.String),
4343
join.OneOf(
4444
join.DeclarationOf("github.com/DataDog/orchestrion/runtime/built", "WithOrchestrionVersion"),
4545
join.Directive("orchestrion:version"),

internal/injector/typed/typename.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ import (
1414
"github.com/DataDog/orchestrion/internal/fingerprint"
1515
)
1616

17+
// Common built-in type definitions for convenience.
18+
// These pre-defined TypeName instances help avoid repeated string literals
19+
// and potential typos when referring to common Go built-in types.
20+
var (
21+
// Basic types currently used in the codebase
22+
Any = MustTypeName("any")
23+
Bool = MustTypeName("bool")
24+
String = MustTypeName("string")
25+
// Uncomment these when we used.
26+
// Byte = MustTypeName("byte")
27+
// Int = MustTypeName("int")
28+
// Error = MustTypeName("error")
29+
)
30+
1731
// TypeName represents a parsed Go type name, potentially including a package path and pointer indicator.
1832
type TypeName struct {
1933
// ImportPath is the import Path that provides the type, or an empty string if the
@@ -35,13 +49,13 @@ func NewTypeName(n string) (tn TypeName, err error) {
3549
matches := typeNameRe.FindStringSubmatch(n)
3650
if matches == nil {
3751
err = fmt.Errorf("invalid TypeName syntax: %q", n)
38-
return
52+
return tn, err
3953
}
4054

4155
tn.Pointer = matches[1] == "*"
4256
tn.ImportPath = matches[2]
4357
tn.Name = matches[3]
44-
return
58+
return tn, nil
4559
}
4660

4761
// MustTypeName is the same as NewTypeName, except it panics in case of an error.
@@ -50,7 +64,7 @@ func MustTypeName(n string) (tn TypeName) {
5064
if tn, err = NewTypeName(n); err != nil {
5165
panic(err)
5266
}
53-
return
67+
return tn
5468
}
5569

5670
// Matches determines whether the provided AST expression node represents the same type

0 commit comments

Comments
 (0)