Search in sources :

Example 16 with PsiManager

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

the class InsertComponentProcessor method checkAddDependencyOnInsert.

private boolean checkAddDependencyOnInsert(final ComponentItem item) {
    if (item.getClassName().equals(HSpacer.class.getName()) || item.getClassName().equals(VSpacer.class.getName())) {
        // this is mostly required for IDEA developers, so that developers don't receive prompt to offer ui-designer-impl dependency
        return true;
    }
    PsiManager manager = PsiManager.getInstance(myEditor.getProject());
    final GlobalSearchScope projectScope = GlobalSearchScope.allScope(myEditor.getProject());
    final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myEditor.getModule());
    final PsiClass componentClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(item.getClassName(), projectScope);
    if (componentClass != null && JavaPsiFacade.getInstance(manager.getProject()).findClass(item.getClassName(), moduleScope) == null) {
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myEditor.getProject()).getFileIndex();
        List<OrderEntry> entries = fileIndex.getOrderEntriesForFile(componentClass.getContainingFile().getVirtualFile());
        if (entries.size() > 0) {
            if (entries.get(0) instanceof ModuleSourceOrderEntry) {
                if (!checkAddModuleDependency(item, (ModuleSourceOrderEntry) entries.get(0)))
                    return false;
            } else if (entries.get(0) instanceof LibraryOrderEntry) {
                if (!checkAddLibraryDependency(item, (LibraryOrderEntry) entries.get(0)))
                    return false;
            }
        }
    }
    return true;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

Example 17 with PsiManager

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

the class Java15FormInspection method checkComponentProperties.

protected void checkComponentProperties(Module module, final IComponent component, final FormErrorCollector collector) {
    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) {
        return;
    }
    for (final IProperty prop : component.getModifiedProperties()) {
        final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, prop.getName(), false, true);
        if (getter == null)
            continue;
        final LanguageLevel languageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module);
        if (Java15APIUsageInspection.getLastIncompatibleLanguageLevel(getter, languageLevel) != null) {
            registerError(component, collector, prop, "@since " + Java15APIUsageInspection.getShortName(languageLevel));
        }
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IProperty(com.intellij.uiDesigner.lw.IProperty) PsiMethod(com.intellij.psi.PsiMethod) LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager)

Example 18 with PsiManager

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

the class CompilerHierarchyInfoImpl method getHierarchyChildren.

@Override
@NotNull
public Stream<PsiElement> getHierarchyChildren() {
    PsiManager psiManager = PsiManager.getInstance(myProject);
    final LanguageLightRefAdapter adapter = ObjectUtils.notNull(CompilerReferenceServiceImpl.findAdapterForFileType(mySearchFileType));
    return myCandidatePerFile.entrySet().stream().filter(e -> mySearchScope.contains(e.getKey())).flatMap(e -> {
        final VirtualFile file = e.getKey();
        final Object[] definitions = e.getValue();
        final PsiElement[] hierarchyChildren = ReadAction.compute(() -> {
            final PsiFileWithStubSupport psiFile = (PsiFileWithStubSupport) psiManager.findFile(file);
            return mySearchType.performSearchInFile(definitions, myBaseClass, psiFile, adapter);
        });
        if (hierarchyChildren.length == definitions.length) {
            return Stream.of(hierarchyChildren);
        } else {
            LOG.assertTrue(mySearchType == CompilerHierarchySearchType.DIRECT_INHERITOR, "Should not happens for functional expression search");
            return Stream.of(hierarchyChildren).filter(c -> ReadAction.compute(() -> adapter.isDirectInheritor(c, myBaseClass)));
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerDirectHierarchyInfo(com.intellij.compiler.CompilerDirectHierarchyInfo) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileType(com.intellij.openapi.fileTypes.FileType) PsiFileWithStubSupport(com.intellij.psi.impl.source.PsiFileWithStubSupport) ReadAction(com.intellij.openapi.application.ReadAction) PsiManager(com.intellij.psi.PsiManager) Stream(java.util.stream.Stream) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiNamedElement(com.intellij.psi.PsiNamedElement) ObjectUtils(com.intellij.util.ObjectUtils) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileWithStubSupport(com.intellij.psi.impl.source.PsiFileWithStubSupport) PsiManager(com.intellij.psi.PsiManager) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with PsiManager

use of com.intellij.psi.PsiManager in project kotlin by JetBrains.

the class BasicTest method createJetFileList.

private static List<KtFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
    List<KtFile> libFiles = Lists.newArrayList();
    PsiManager psiManager = PsiManager.getInstance(project);
    VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
    VirtualFile rootFile = root == null ? null : fileSystem.findFileByPath(root);
    for (String libFileName : list) {
        VirtualFile virtualFile = rootFile == null ? fileSystem.findFileByPath(libFileName) : rootFile.findFileByRelativePath(libFileName);
        //TODO logging?
        assert virtualFile != null : "virtual file is missing, most likely the file doesn't exist: " + libFileName;
        PsiFile psiFile = psiManager.findFile(virtualFile);
        libFiles.add((KtFile) psiFile);
    }
    return libFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) PsiManager(com.intellij.psi.PsiManager) KtFile(org.jetbrains.kotlin.psi.KtFile) PsiFile(com.intellij.psi.PsiFile)

Example 20 with PsiManager

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

the class FileListPasteProvider method performPaste.

@Override
public void performPaste(@NotNull DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || ideView == null)
        return;
    if (!FileCopyPasteUtil.isFileListFlavorAvailable())
        return;
    final Transferable contents = CopyPasteManager.getInstance().getContents();
    if (contents == null)
        return;
    final List<File> fileList = FileCopyPasteUtil.getFileList(contents);
    if (fileList == null)
        return;
    if (DumbService.isDumb(project)) {
        DumbService.getInstance(project).showDumbModeNotification("Sorry, file copy/paste is not available during indexing");
        return;
    }
    final List<PsiElement> elements = new ArrayList<>();
    for (File file : fileList) {
        final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
        if (vFile != null) {
            final PsiManager instance = PsiManager.getInstance(project);
            PsiFileSystemItem item = vFile.isDirectory() ? instance.findDirectory(vFile) : instance.findFile(vFile);
            if (item != null) {
                elements.add(item);
            }
        }
    }
    if (elements.size() > 0) {
        final PsiDirectory dir = ideView.getOrChooseDirectory();
        if (dir != null) {
            final boolean move = LinuxDragAndDropSupport.isMoveOperation(contents);
            if (move) {
                new MoveFilesOrDirectoriesHandler().doMove(PsiUtilCore.toPsiElementArray(elements), dir);
            } else {
                new CopyFilesOrDirectoriesHandler().doCopy(PsiUtilCore.toPsiElementArray(elements), dir);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CopyFilesOrDirectoriesHandler(com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler) Transferable(java.awt.datatransfer.Transferable) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) MoveFilesOrDirectoriesHandler(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement)

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