Ported withAnnotation from the mainline.