Ported addImportDecl from the old API, with tests.