func deleteImport(f *ast.File, path string) (deleted bool) {
	oldImport := importSpec(f, path)

	// Find the import node that imports path, if any.
	for i, decl := range f.Decls {
		gen, ok := decl.(*ast.GenDecl)
		if !ok || gen.Tok != token.IMPORT {
			continue
		}
		for j, spec := range gen.Specs {
			impspec := spec.(*ast.ImportSpec)
			if oldImport != impspec {
				continue
			}

			// We found an import spec that imports path.
			// Delete it.
			deleted = true
			copy(gen.Specs[j:], gen.Specs[j+1:])
			gen.Specs = gen.Specs[:len(gen.Specs)-1]

			// If this was the last import spec in this decl,
			// delete the decl, too.
			if len(gen.Specs) == 0 {
				copy(f.Decls[i:], f.Decls[i+1:])
				f.Decls = f.Decls[:len(f.Decls)-1]
			} else if len(gen.Specs) == 1 {
				gen.Lparen = token.NoPos // drop parens
			}
			if j > 0 {
				// We deleted an entry but now there will be
				// a blank line-sized hole where the import was.
				// Close the hole by making the previous
				// import appear to "end" where this one did.
				gen.Specs[j-1].(*ast.ImportSpec).EndPos = impspec.End()
			}
			break
		}
	}

	// Delete it from f.Imports.
	for i, imp := range f.Imports {
		if imp == oldImport {
			copy(f.Imports[i:], f.Imports[i+1:])
			f.Imports = f.Imports[:len(f.Imports)-1]
			break
		}
	}

	return
}
func deleteImport(f *ast.File, path string) (deleted bool) {
	oldImport := importSpec(f, path)

	
	for i, decl := range f.Decls {
		gen, ok := decl.(*ast.GenDecl)
		if !ok || gen.Tok != token.IMPORT {
			continue
		}
		for j, spec := range gen.Specs {
			impspec := spec.(*ast.ImportSpec)
			if oldImport != impspec {
				continue
			}

			
			
			deleted = true
			copy(gen.Specs[j:], gen.Specs[j+1:])
			gen.Specs = gen.Specs[:len(gen.Specs)-1]

			
			
			if len(gen.Specs) == 0 {
				copy(f.Decls[i:], f.Decls[i+1:])
				f.Decls = f.Decls[:len(f.Decls)-1]
			} else if len(gen.Specs) == 1 {
				gen.Lparen = token.NoPos 
			}
			if j > 0 {
				
				
				
				
				gen.Specs[j-1].(*ast.ImportSpec).EndPos = impspec.End()
			}
			break
		}
	}

	
	for i, imp := range f.Imports {
		if imp == oldImport {
			copy(f.Imports[i:], f.Imports[i+1:])
			f.Imports = f.Imports[:len(f.Imports)-1]
			break
		}
	}

	return
}
func deleteImport ( f * ast . File , path string ) ( deleted bool ) { oldImport := importSpec ( f , path ) // Find the import node that imports path, if any. for i , decl := range f . Decls { gen , ok := decl . ( * ast . GenDecl ) if ! ok || gen . Tok != token . IMPORT { continue } for j , spec := range gen . Specs { impspec := spec . ( * ast . ImportSpec ) if oldImport != impspec { continue } // We found an import spec that imports path. // Delete it. deleted = true copy ( gen . Specs [ j : ] , gen . Specs [ j + 1 : ] ) gen . Specs = gen . Specs [ : len ( gen . Specs ) - 1 ] // If this was the last import spec in this decl, // delete the decl, too. if len ( gen . Specs ) == 0 { copy ( f . Decls [ i : ] , f . Decls [ i + 1 : ] ) f . Decls = f . Decls [ : len ( f . Decls ) - 1 ] } else if len ( gen . Specs ) == 1 { gen . Lparen = token . NoPos // drop parens } if j > 0 { // We deleted an entry but now there will be // a blank line-sized hole where the import was. // Close the hole by making the previous // import appear to "end" where this one did. gen . Specs [ j - 1 ] . ( * ast . ImportSpec ) . EndPos = impspec . End ( ) } break } } // Delete it from f.Imports. for i , imp := range f . Imports { if imp == oldImport { copy ( f . Imports [ i : ] , f . Imports [ i + 1 : ] ) f . Imports = f . Imports [ : len ( f . Imports ) - 1 ] break } } return }
// deleteImport deletes the import path from the file f, if present.
deleteImport deletes the import path from the file f if present .