}
//name is definitely a simple name, and it might match. Walk up type tree and if it doesn't match any of those, delve into import statements.
Node n = typeReference.getParent();
Node prevN = null;
CompilationUnit cu = null;
while (n != null) {
RawListAccessor<?, ?> list;
boolean stopAtSelf;
if (n instanceof Block) {
list = ((Block) n).rawContents();
stopAtSelf = true;
} else if (n instanceof TypeBody) {
list = ((TypeBody) n).rawMembers();
stopAtSelf = false;
} else if (n instanceof CompilationUnit) {
list = ((CompilationUnit) n).rawTypeDeclarations();
cu = (CompilationUnit) n;
stopAtSelf = false;
} else {
list = null;
stopAtSelf = false;
}
if (list != null) {
for (Node c : list) {
if (c instanceof TypeDeclaration && namesMatch(name, ((TypeDeclaration) c).astName())) return false;
if (stopAtSelf && c == prevN) break;
}
}
prevN = n;
n = n.getParent();
}
//A locally defined type is definitely not what's targeted so it could still be our wanted type reference. Let's check imports.
if (wantedPkg.isEmpty()) return cu == null || cu.rawPackageDeclaration() == null;
return true;
}