Search in sources :

Example 31 with PsiManager

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;
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) PsiManager(com.intellij.psi.PsiManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 32 with PsiManager

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);
}
Also used : PsiManager(com.intellij.psi.PsiManager) PsiElement(com.intellij.psi.PsiElement)

Example 33 with PsiManager

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;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) PsiJavaFile(com.intellij.psi.PsiJavaFile) PsiPackage(com.intellij.psi.PsiPackage)

Example 34 with PsiManager

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;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with PsiManager

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiManager(com.intellij.psi.PsiManager) ModuleGroup(com.intellij.ide.projectView.impl.ModuleGroup) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) FavoriteNodeProvider(com.intellij.ide.favoritesTreeView.FavoriteNodeProvider) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiManager (com.intellij.psi.PsiManager)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)69 PsiFile (com.intellij.psi.PsiFile)51 NotNull (org.jetbrains.annotations.NotNull)25 PsiDirectory (com.intellij.psi.PsiDirectory)24 Project (com.intellij.openapi.project.Project)17 Module (com.intellij.openapi.module.Module)16 Nullable (org.jetbrains.annotations.Nullable)16 PsiElement (com.intellij.psi.PsiElement)15 ArrayList (java.util.ArrayList)15 File (java.io.File)14 XmlFile (com.intellij.psi.xml.XmlFile)11 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)10 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)8 PsiClass (com.intellij.psi.PsiClass)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)4 IOException (java.io.IOException)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4