use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class TodoPackageNode method getFileCount.
private int getFileCount(final PackageElement packageElement) {
int count = 0;
if (getSettings().isFlattenPackages()) {
final PsiPackage aPackage = packageElement.getPackage();
final Module module = packageElement.getModule();
final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(aPackage.getProject());
final PsiDirectory[] directories = aPackage.getDirectories(scope);
for (PsiDirectory directory : directories) {
Iterator<PsiFile> iterator = myBuilder.getFilesUnderDirectory(directory);
while (iterator.hasNext()) {
PsiFile psiFile = iterator.next();
if (getStructure().accept(psiFile))
count++;
}
}
} else {
Iterator<PsiFile> iterator = getFiles(packageElement);
while (iterator.hasNext()) {
PsiFile psiFile = iterator.next();
if (getStructure().accept(psiFile)) {
count++;
}
}
}
return count;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class JavaProjectViewDirectoryHelper method getLocationString.
@Nullable
@Override
public String getLocationString(@NotNull PsiDirectory directory, boolean includeUrl, boolean includeRootType) {
String result = null;
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
if (ProjectRootsUtil.isSourceRoot(directory) && aPackage != null) {
//package prefix
result = StringUtil.nullize(aPackage.getQualifiedName(), true);
}
String baseString = super.getLocationString(directory, includeUrl, includeRootType);
if (result == null)
return baseString;
if (baseString == null)
return result;
return result + "," + FontUtil.spaceAndThinSpace() + baseString;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class JavaProjectViewDirectoryHelper method getNodeName.
@Nullable
@Override
public String getNodeName(final ViewSettings settings, final Object parentValue, final PsiDirectory directory) {
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
PsiPackage parentPackage;
if (!ProjectRootsUtil.isSourceRoot(directory) && aPackage != null && !aPackage.getQualifiedName().isEmpty() && parentValue instanceof PsiDirectory) {
parentPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) parentValue));
} else if (ProjectRootsUtil.isSourceRoot(directory) && aPackage != null) {
//package prefix
aPackage = null;
parentPackage = null;
} else {
parentPackage = null;
}
return PackageUtil.getNodeName(settings, aPackage, parentPackage, directory.getName(), isShowFQName(settings, parentValue, directory));
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class PackageElementNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
final PackageElement value = getValue();
if (value == null)
return Collections.emptyList();
final List<AbstractTreeNode> children = new ArrayList<>();
final Module module = value.getModule();
final PsiPackage aPackage = value.getPackage();
if (!getSettings().isFlattenPackages()) {
final PsiPackage[] subpackages = PackageUtil.getSubpackages(aPackage, module, isLibraryElement());
for (PsiPackage subpackage : subpackages) {
PackageUtil.addPackageAsChild(children, subpackage, module, getSettings(), isLibraryElement());
}
}
// process only files in package's directories
final GlobalSearchScope scopeToShow = PackageUtil.getScopeToShow(aPackage.getProject(), module, isLibraryElement());
PsiFile[] packageChildren = aPackage.getFiles(scopeToShow);
for (PsiFile file : packageChildren) {
if (file.getVirtualFile() != null) {
children.add(new PsiFileNode(getProject(), file, getSettings()));
}
}
return children;
}
use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.
the class FileStructureDialogTest method testFileStructureForClass.
public void testFileStructureForClass() throws Exception {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(getPackageDirectory());
assertNotNull(aPackage);
final PsiClass psiClass = aPackage.getClasses()[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
assertNotNull(virtualFile);
final StructureViewBuilder structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(virtualFile.getFileType(), virtualFile, myProject);
assertNotNull(structureViewBuilder);
final StructureViewModel structureViewModel = ((TreeBasedStructureViewBuilder) structureViewBuilder).createStructureViewModel(null);
final EditorFactory factory = EditorFactory.getInstance();
assertNotNull(factory);
final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
assertNotNull(document);
final Editor editor = factory.createEditor(document, myProject);
try {
final FileStructureDialog dialog = new FileStructureDialog(structureViewModel, editor, myProject, psiClass, new Disposable() {
@Override
public void dispose() {
structureViewModel.dispose();
}
}, true);
try {
final CommanderPanel panel = dialog.getPanel();
assertListsEqual((ListModel) panel.getModel(), "Inner1\n" + "Inner2\n" + "__method(): void\n" + "_myField1: int\n" + "_myField2: String\n");
} finally {
dialog.close(0);
}
} finally {
factory.releaseEditor(editor);
}
}
Aggregations