in src/explorerCommands/new.ts [146:185]
async function getPackageFsPath(node: DataNode): Promise<string | undefined> {
if (node.nodeData.kind === NodeKind.Project) {
const childrenNodes: DataNode[] = await node.getChildren() as DataNode[];
const packageRoots: any[] = childrenNodes.filter((child) => {
return child.nodeData.kind === NodeKind.PackageRoot;
});
if (packageRoots.length < 1) {
// This might happen for an invisible project with "_" as its root
const packageNode: DataNode | undefined = childrenNodes.find((child) => {
return child.nodeData.kind === NodeKind.Package;
});
if (!packageNode && node.uri) {
// This means the .java files are in the default package.
return Uri.parse(node.uri).fsPath;
} else if (packageNode?.uri) {
return getPackageRootPath(Uri.parse(packageNode.uri).fsPath, packageNode.name);
}
return "";
} else if (packageRoots.length === 1) {
return Uri.parse(packageRoots[0].uri).fsPath;
} else {
const options: ISourceRootPickItem[] = packageRoots.map((root) => {
return {
label: root.name,
fsPath: Uri.parse(root.uri).fsPath,
};
});
const choice: ISourceRootPickItem | undefined = await window.showQuickPick(options, {
placeHolder: "Choose a source folder",
ignoreFocusOut: true,
},
);
return choice?.fsPath;
}
} else if (node.nodeData.kind === NodeKind.PrimaryType) {
return node.uri ? path.dirname(Uri.parse(node.uri).fsPath) : "";
}
return node.uri ? Uri.parse(node.uri).fsPath : "";
}