(f *ast.File)
| 127 | } |
| 128 | |
| 129 | func (t *templateData) processAST(f *ast.File) error { |
| 130 | for _, decl := range f.Decls { |
| 131 | gd, ok := decl.(*ast.GenDecl) |
| 132 | if !ok { |
| 133 | continue |
| 134 | } |
| 135 | for _, spec := range gd.Specs { |
| 136 | ts, ok := spec.(*ast.TypeSpec) |
| 137 | if !ok { |
| 138 | continue |
| 139 | } |
| 140 | // Skip unexported identifiers. |
| 141 | if !ts.Name.IsExported() { |
| 142 | logf("Struct %v is unexported; skipping.", ts.Name) |
| 143 | continue |
| 144 | } |
| 145 | // Check if the struct should be skipped. |
| 146 | if skipStructs[ts.Name.Name] { |
| 147 | logf("Struct %v is in skip list; skipping.", ts.Name) |
| 148 | continue |
| 149 | } |
| 150 | if _, ok := ts.Type.(*ast.Ident); ok { // e.g. type SomeService service |
| 151 | continue |
| 152 | } |
| 153 | st, ok := ts.Type.(*ast.StructType) |
| 154 | if !ok { |
| 155 | logf("Skipping TypeSpec of type %T", ts.Type) |
| 156 | continue |
| 157 | } |
| 158 | for _, field := range st.Fields.List { |
| 159 | if len(field.Names) == 0 { |
| 160 | continue |
| 161 | } |
| 162 | |
| 163 | fieldName := field.Names[0] |
| 164 | // Skip unexported identifiers. |
| 165 | if !fieldName.IsExported() { |
| 166 | logf("Field %v is unexported; skipping.", fieldName) |
| 167 | continue |
| 168 | } |
| 169 | // Check if "struct.method" should be skipped. |
| 170 | if key := fmt.Sprintf("%v.Get%v", ts.Name, fieldName); skipStructMethods[key] { |
| 171 | logf("Method %v is skip list; skipping.", key) |
| 172 | continue |
| 173 | } |
| 174 | |
| 175 | se, ok := field.Type.(*ast.StarExpr) |
| 176 | if !ok { |
| 177 | switch x := field.Type.(type) { |
| 178 | case *ast.MapType: |
| 179 | logf("processAST: addMapType(x, %q, %q)", ts.Name.String(), fieldName.String()) |
| 180 | t.addMapType(x, ts.Name.String(), fieldName.String(), false) |
| 181 | continue |
| 182 | case *ast.ArrayType: |
| 183 | logf("processAST: addArrayType(x, %q, %q)", ts.Name.String(), fieldName.String()) |
| 184 | t.addArrayType(x, ts.Name.String(), fieldName.String(), false) |
| 185 | continue |
| 186 | case *ast.Ident: |
no test coverage detected