final String packageDir;
if (isNew) {
//Create folders bin and pkg and add main.go to src folder:
PsiDirectory srcDir = PsiManager.getInstance(module.getProject()).findDirectory(sourceRoots[0]);
PsiDirectory baseDir = srcDir.getParentDirectory();
baseDir.createSubdirectory("bin");
baseDir.createSubdirectory("pkg");
String packageNameLeafTemp = packageName;
PsiDirectory currentDir = srcDir;
if (packageName.contains("/") || packageName.contains("\\")) {
String[] parts = packageName.split("[\\\\/]");
for (int i = 0; i < parts.length-1; ++i) {
currentDir = currentDir.createSubdirectory(parts[i]);
}
packageNameLeafTemp = parts[parts.length-1];
}
final String packageNameLeaf = packageNameLeafTemp;
final PsiDirectory mainPackage = currentDir.createSubdirectory(packageNameLeaf);
packageDir = mainPackage.getVirtualFile().getPath();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
String mainFileName = projectName.concat(".go");
mainPackage.checkCreateFile(mainFileName);
GoTemplatesFactory.createFromTemplate(mainPackage, "main", "main", mainFileName, GoTemplatesFactory.Template.GoAppMain);
toolWindow.printNormalMessage(String.format("%nFinished creating package %s from template.%n", packageName));
sourceRoots[0].refresh(true, true);
}
});