I made a similar module to this, but I don't have it anymore (and I don't own the code, my ex-employer does).
Anyways, in my module I had this simple function that just collects the import symbols and scans the source for these tokens. Imports that don't have a token in the file can be safely removed.
Saves a lot of time and keeps the import list clean.