final String suffix = name.substring(lastDot + 1);
final ClListLike[] imported = PsiTreeUtil.getChildrenOfType(importClause, ClListLike.class);
// Find or create an import member
ClListLike importMember = null;
if (imported == null) {
importMember = addFreshImportToMember(importClause, prefix);
} else {
importMember = ContainerUtil.find(imported, new Condition<ClListLike>() {
public boolean value(ClListLike elem) {
return prefix.equals(elem.getHeadText());
}
});
if (importMember == null) {
importMember = addFreshImportToMember(importClause, prefix);
}
}
assert importMember != null;
// Insert a new class into it
final PsiElement lastChild = importMember.getLastChild();
final PsiElement newClass = createSymbolNodeFromText(suffix).getPsi();
assert newClass != null;
if (lastChild instanceof LeafPsiElement) {
importMember.addBefore(newClass, lastChild);
} else {
importMember.add(newClass);
}
return importMember;
}