Skip to content

Commit 463a711

Browse files
committed
Use reflection for interface nil check instead
1 parent 83cd349 commit 463a711

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

go/extractor/extractor.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"log"
1414
"os"
1515
"path/filepath"
16+
"reflect"
1617
"regexp"
1718
"runtime"
1819
"strconv"
@@ -941,16 +942,7 @@ func emitScopeNodeInfo(tw *trap.Writer, nd ast.Node, lbl trap.Label) {
941942

942943
// extractExpr extracts AST information for the given expression and all its subexpressions
943944
func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, skipExtractingValue bool) {
944-
if expr == nil || expr == (*ast.Ident)(nil) || expr == (*ast.BasicLit)(nil) ||
945-
expr == (*ast.Ellipsis)(nil) || expr == (*ast.FuncLit)(nil) ||
946-
expr == (*ast.CompositeLit)(nil) || expr == (*ast.SelectorExpr)(nil) ||
947-
expr == (*ast.IndexListExpr)(nil) || expr == (*ast.SliceExpr)(nil) ||
948-
expr == (*ast.TypeAssertExpr)(nil) || expr == (*ast.CallExpr)(nil) ||
949-
expr == (*ast.StarExpr)(nil) || expr == (*ast.KeyValueExpr)(nil) ||
950-
expr == (*ast.UnaryExpr)(nil) || expr == (*ast.BinaryExpr)(nil) ||
951-
expr == (*ast.ArrayType)(nil) || expr == (*ast.StructType)(nil) ||
952-
expr == (*ast.FuncType)(nil) || expr == (*ast.InterfaceType)(nil) ||
953-
expr == (*ast.MapType)(nil) || expr == (*ast.ChanType)(nil) {
945+
if expr == nil || reflect.ValueOf(expr).IsNil() {
954946
return
955947
}
956948

@@ -1247,15 +1239,7 @@ func extractFields(tw *trap.Writer, fields *ast.FieldList, parent trap.Label, id
12471239
// extractStmt extracts AST information for a given statement and all other statements or expressions
12481240
// nested inside it
12491241
func extractStmt(tw *trap.Writer, stmt ast.Stmt, parent trap.Label, idx int) {
1250-
if stmt == nil || stmt == (*ast.DeclStmt)(nil) ||
1251-
stmt == (*ast.LabeledStmt)(nil) || stmt == (*ast.ExprStmt)(nil) ||
1252-
stmt == (*ast.SendStmt)(nil) || stmt == (*ast.IncDecStmt)(nil) ||
1253-
stmt == (*ast.AssignStmt)(nil) || stmt == (*ast.GoStmt)(nil) ||
1254-
stmt == (*ast.DeferStmt)(nil) || stmt == (*ast.BranchStmt)(nil) ||
1255-
stmt == (*ast.BlockStmt)(nil) || stmt == (*ast.IfStmt)(nil) ||
1256-
stmt == (*ast.CaseClause)(nil) || stmt == (*ast.SwitchStmt)(nil) ||
1257-
stmt == (*ast.TypeSwitchStmt)(nil) || stmt == (*ast.CommClause)(nil) ||
1258-
stmt == (*ast.ForStmt)(nil) || stmt == (*ast.RangeStmt)(nil) {
1242+
if stmt == nil || reflect.ValueOf(stmt).IsNil() {
12591243
return
12601244
}
12611245

@@ -1391,7 +1375,7 @@ func extractStmts(tw *trap.Writer, stmts []ast.Stmt, parent trap.Label, idx int,
13911375

13921376
// extractDecl extracts AST information for the given declaration
13931377
func extractDecl(tw *trap.Writer, decl ast.Decl, parent trap.Label, idx int) {
1394-
if decl == (*ast.FuncDecl)(nil) || decl == (*ast.GenDecl)(nil) {
1378+
if reflect.ValueOf(decl).IsNil() {
13951379
return
13961380
}
13971381
lbl := tw.Labeler.LocalID(decl)

0 commit comments

Comments
 (0)