Search in sources :

Example 86 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class FormInspectionUtil method isComponentClass.

public static boolean isComponentClass(final Module module, final IComponent component, final Class componentClass) {
    final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
    if (aClass != null) {
        final PsiClass labelClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(componentClass.getName(), scope);
        if (labelClass != null && InheritanceUtil.isInheritorOrSelf(aClass, labelClass, true)) {
            return true;
        }
    }
    return false;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

Example 87 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class UpdateCopyrightCheckinHandlerFactory method createHandler.

@NotNull
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
    return new CheckinHandler() {

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            final JCheckBox updateCopyrightCb = new JCheckBox("Update copyright");
            return new RefreshableOnComponent() {

                public JComponent getComponent() {
                    return JBUI.Panels.simplePanel().addToLeft(updateCopyrightCb);
                }

                public void refresh() {
                }

                public void saveState() {
                    UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT = updateCopyrightCb.isSelected();
                }

                public void restoreState() {
                    updateCopyrightCb.setSelected(UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT);
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
            if (UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT) {
                new UpdateCopyrightProcessor(panel.getProject(), null, getPsiFiles()).run();
                FileDocumentManager.getInstance().saveAllDocuments();
            }
            return super.beforeCheckin();
        }

        private PsiFile[] getPsiFiles() {
            final Collection<VirtualFile> files = panel.getVirtualFiles();
            final List<PsiFile> psiFiles = new ArrayList<>();
            final PsiManager manager = PsiManager.getInstance(panel.getProject());
            for (final VirtualFile file : files) {
                final PsiFile psiFile = manager.findFile(file);
                if (psiFile != null) {
                    psiFiles.add(psiFile);
                }
            }
            return PsiUtilCore.toPsiFileArray(psiFiles);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) PairConsumer(com.intellij.util.PairConsumer) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class ExternalLibrariesNode method addLibraryChildren.

public static void addLibraryChildren(final LibraryOrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final VirtualFile[] files = entry.getRootFiles(OrderRootType.CLASSES);
    for (final VirtualFile file : files) {
        final PsiDirectory psiDir = psiManager.findDirectory(file);
        if (psiDir == null) {
            continue;
        }
        children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager)

Example 89 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class SyntheticLibraryElementNode method getChildren.

@NotNull
@Override
public Collection<AbstractTreeNode> getChildren() {
    List<AbstractTreeNode> children = new ArrayList<>();
    SyntheticLibrary library = getLibrary();
    Project project = Objects.requireNonNull(getProject());
    PsiManager psiManager = PsiManager.getInstance(project);
    for (VirtualFile file : library.getSourceRoots()) {
        if (!file.isValid())
            continue;
        if (file.isDirectory()) {
            PsiDirectory psiDir = psiManager.findDirectory(file);
            if (psiDir != null) {
                children.add(new PsiDirectoryNode(project, psiDir, getSettings()));
            }
        } else {
            PsiFile psiFile = psiManager.findFile(file);
            if (psiFile != null) {
                children.add(new PsiFileNode(project, psiFile, getSettings()));
            }
        }
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) SyntheticLibrary(com.intellij.openapi.roots.SyntheticLibrary) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.

the class ProjectViewProjectNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    List<VirtualFile> topLevelContentRoots = ProjectViewDirectoryHelper.getInstance(myProject).getTopLevelRoots();
    Set<Module> modules = new LinkedHashSet<>(topLevelContentRoots.size());
    for (VirtualFile root : topLevelContentRoots) {
        final Module module = ModuleUtil.findModuleForFile(root, myProject);
        if (module != null) {
            // Some people exclude module's content roots...
            modules.add(module);
        }
    }
    ArrayList<AbstractTreeNode> nodes = new ArrayList<>();
    final PsiManager psiManager = PsiManager.getInstance(getProject());
    /*
    for (VirtualFile root : reduceRoots(topLevelContentRoots)) {
      nodes.add(new PsiDirectoryNode(getProject(), psiManager.findDirectory(root), getSettings()));
    }
    */
    nodes.addAll(modulesAndGroups(modules.toArray(new Module[modules.size()])));
    final VirtualFile baseDir = getProject().getBaseDir();
    if (baseDir == null)
        return nodes;
    final VirtualFile[] files = baseDir.getChildren();
    for (VirtualFile file : files) {
        if (!file.isDirectory()) {
            if (ProjectFileIndex.SERVICE.getInstance(getProject()).getModuleForFile(file, false) == null) {
                nodes.add(new PsiFileNode(getProject(), psiManager.findFile(file), getSettings()));
            }
        }
    }
    if (getSettings().isShowLibraryContents()) {
        nodes.add(new ExternalLibrariesNode(getProject(), getSettings()));
    }
    return nodes;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiManager(com.intellij.psi.PsiManager) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiManager (com.intellij.psi.PsiManager)120 VirtualFile (com.intellij.openapi.vfs.VirtualFile)84 PsiFile (com.intellij.psi.PsiFile)61 PsiDirectory (com.intellij.psi.PsiDirectory)31 NotNull (org.jetbrains.annotations.NotNull)26 Project (com.intellij.openapi.project.Project)20 File (java.io.File)19 PsiElement (com.intellij.psi.PsiElement)18 ArrayList (java.util.ArrayList)18 Module (com.intellij.openapi.module.Module)17 Nullable (org.jetbrains.annotations.Nullable)16 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 XmlFile (com.intellij.psi.xml.XmlFile)11 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)9 PsiClass (com.intellij.psi.PsiClass)7 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)6 HashSet (java.util.HashSet)6 Nullable (javax.annotation.Nullable)5 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4