if (imports.length == 0) {
addImportUnderPackage(file, document, pathToImport);
return;
}
GoImportDeclaration lastImport = imports[imports.length - 1];
PsiElement lastChild = getPrevSiblingIfItsWhiteSpaceOrComment(importDeclarations.getLastChild());
if (lastChild == null) {
addImportUnderPackage(file, document, pathToImport);
return;
}
if (")".equals(lastChild.getText())) {
document.insertString(lastChild.getTextOffset(), "\"" + pathToImport + "\"\n");
int line = document.getLineNumber(lastChild.getTextOffset());
reformatLines(file, editor, line, line);
} else {
String oldImport = lastImport.getText();
int start = lastImport.getTextOffset();
int end = start + lastImport.getTextLength();
String declarations = String.format("(\n%s\n\"%s\"\n)", oldImport, pathToImport);
document.replaceString(start, end, declarations);
reformatPositions(file, start, start + declarations.length());
}
}