use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class DependenciesPanel method selectElementInLeftTree.
private void selectElementInLeftTree(PsiElement elt) {
PsiManager manager = PsiManager.getInstance(myProject);
PackageDependenciesNode root = (PackageDependenciesNode) myLeftTree.getModel().getRoot();
Enumeration enumeration = root.breadthFirstEnumeration();
while (enumeration.hasMoreElements()) {
PackageDependenciesNode child = (PackageDependenciesNode) enumeration.nextElement();
if (manager.areElementsEquivalent(child.getPsiElement(), elt)) {
myLeftTree.setSelectionPath(new TreePath(((DefaultTreeModel) myLeftTree.getModel()).getPathToRoot(child)));
break;
}
}
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class PsiElementBaseIntentionAction method isAvailable.
@Override
public final boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (file == null)
return false;
final PsiManager manager = file.getManager();
if (manager == null)
return false;
if (!manager.isInProject(file))
return false;
final PsiElement element = getElement(editor, file);
return element != null && isAvailable(project, editor, element);
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class AnalysisScopeRule method getData.
@Override
public Object getData(final DataProvider dataProvider) {
final Object psiFile = dataProvider.getData(CommonDataKeys.PSI_FILE.getName());
if (psiFile instanceof PsiJavaFile) {
return new JavaAnalysisScope((PsiJavaFile) psiFile);
}
Object psiTarget = dataProvider.getData(CommonDataKeys.PSI_ELEMENT.getName());
if (psiTarget instanceof PsiPackage) {
PsiPackage pack = (PsiPackage) psiTarget;
PsiManager manager = pack.getManager();
if (!manager.isInProject(pack))
return null;
PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(manager.getProject()));
if (dirs.length == 0)
return null;
return new JavaAnalysisScope(pack, (Module) dataProvider.getData(LangDataKeys.MODULE.getName()));
}
return null;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class AnnotatedMacro method findAnnotated.
@Nullable
private static Query<PsiMember> findAnnotated(ExpressionContext context, Expression[] params) {
if (params == null || params.length == 0)
return null;
PsiManager instance = PsiManager.getInstance(context.getProject());
final String paramResult = params[0].calculateResult(context).toString();
if (paramResult == null)
return null;
final GlobalSearchScope scope = GlobalSearchScope.allScope(context.getProject());
final PsiClass myBaseClass = JavaPsiFacade.getInstance(instance.getProject()).findClass(paramResult, scope);
if (myBaseClass != null) {
return AnnotatedMembersSearch.search(myBaseClass, scope);
}
return null;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class AddToFavoritesAction method createNodes.
@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
if (project == null)
return Collections.emptyList();
ArrayList<AbstractTreeNode> result = new ArrayList<>();
for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
if (treeNode != null) {
result.add(treeNode);
return result;
}
}
final PsiManager psiManager = PsiManager.getInstance(project);
final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
//on psi elements
if (object instanceof PsiElement[]) {
for (PsiElement psiElement : (PsiElement[]) object) {
addPsiElementNode(psiElement, project, result, favoritesConfig);
}
return result;
}
//on psi element
if (object instanceof PsiElement) {
Module containingModule = null;
if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
abstractTreeNode = abstractTreeNode.getParent();
}
if (abstractTreeNode != null) {
containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
}
}
}
addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
return result;
}
if (object instanceof VirtualFile[]) {
for (VirtualFile vFile : (VirtualFile[]) object) {
PsiElement element = psiManager.findFile(vFile);
if (element == null)
element = psiManager.findDirectory(vFile);
addPsiElementNode(element, project, result, favoritesConfig);
}
return result;
}
//on form in editor
if (object instanceof VirtualFile) {
final VirtualFile vFile = (VirtualFile) object;
final PsiFile psiFile = psiManager.findFile(vFile);
addPsiElementNode(psiFile, project, result, favoritesConfig);
return result;
}
//on module groups
if (object instanceof ModuleGroup[]) {
for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
}
return result;
}
//on module nodes
if (object instanceof Module)
object = new Module[] { (Module) object };
if (object instanceof Module[]) {
for (Module module1 : (Module[]) object) {
result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
}
return result;
}
//on library group node
if (object instanceof LibraryGroupElement[]) {
for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
}
return result;
}
//on named library node
if (object instanceof NamedLibraryElement[]) {
for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
}
return result;
}
return result;
}
Aggregations