/**
* Returns a symbol given the type's or packages's canonical name,
* or null if the name isn't found.
*/
private <S extends Symbol> S nameToSymbol(String nameStr, Class<S> clazz) {
Name name = names.fromString(nameStr);
// First check cache.
Symbol sym = (clazz == ClassSymbol.class)
? syms.classes.get(name)
: syms.packages.get(name);
try {
if (sym == null)
sym = javaCompiler.resolveIdent(nameStr);
sym.complete();
return (sym.kind != Kinds.ERR &&
sym.exists() &&
clazz.isInstance(sym) &&
name.equals(sym.getQualifiedName()))
? clazz.cast(sym)
: null;
} catch (CompletionFailure e) {
return null;
}