make get_javadoc_ref perform according to docs

Store current match so that we do longest match
instead of last match as currently.

This was impeding match of "javax.servlet" in a different
place than, say, "javax.sql".