Module module = projectFileIndex.getModuleForFile(targetFile);
if (module == null) {
return Collections.emptyList();
}
final PsiManager psiManager = PsiManager.getInstance(project);
CommonProcessors.CollectUniquesProcessor<String> localPackages = new CommonProcessors.CollectUniquesProcessor<String>();
Function<VirtualFile, String> convertor = new Function<VirtualFile, String>() {
public String fun(VirtualFile virtualFile) {
GoFile goFile = (GoFile) psiManager.findFile(virtualFile);
if (goFile == null) {
return "";
}
String packageName = goFile.getPackage().getPackageName();
// in the same folder as the target file we just import the package
if (targetFile.getParent().equals(virtualFile.getParent())) {
return packageName;
}
String importName = VfsUtil.getRelativePath(virtualFile.getParent(), targetFile.getParent(), '/');
if (!virtualFile.getParent().getName().equals(packageName)) {
importName += "/" + packageName;
}
return importName;
}
};
Processor<VirtualFile> processor = new AdapterProcessor<VirtualFile, String>(localPackages, convertor) {
@Override
public boolean process(VirtualFile file) {
if (file.getFileType() == GoFileType.INSTANCE) {
GoFile goFile = (GoFile) psiManager.findFile(file);
if (goFile != null && !goFile.getPackage().isMainPackage()) {
super.process(file);
}