Search in sources :

Example 51 with PsiManager

use of com.intellij.psi.PsiManager in project intellij by bazelbuild.

the class BlazeCreateResourceUtils method getResDirFromUI.

static PsiDirectory getResDirFromUI(Project project, ComboboxWithBrowseButton directoryCombo) {
    PsiManager psiManager = PsiManager.getInstance(project);
    Object selectedItem = directoryCombo.getComboBox().getEditor().getItem();
    File selectedFile = null;
    if (selectedItem instanceof File) {
        selectedFile = (File) selectedItem;
    } else if (selectedItem instanceof String) {
        String selectedDir = (String) selectedItem;
        if (!selectedDir.equals(PLACEHOLDER_TEXT)) {
            selectedFile = new File(selectedDir);
        }
    }
    if (selectedFile == null) {
        return null;
    }
    final File finalSelectedFile = selectedFile;
    return ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {

        @Override
        public PsiDirectory compute() {
            return DirectoryUtil.mkdirs(psiManager, finalSelectedFile.getPath());
        }
    });
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 52 with PsiManager

use of com.intellij.psi.PsiManager in project intellij by bazelbuild.

the class BlazeCreateXmlResourcePanel method setupResourceDirectoryCombo.

private void setupResourceDirectoryCombo() {
    Project project = myModule.getProject();
    if (myContextFile != null) {
        // Try to figure out res/ dir from context
        // (e.g., while refactoring an xml file that's a child of a res/ directory).
        // We currently take the parent and hide the combo box.
        PsiManager manager = PsiManager.getInstance(project);
        VirtualFile virtualDirectory = BlazeCreateResourceUtils.getResDirFromDataContext(myContextFile);
        PsiDirectory directory = virtualDirectory != null ? manager.findDirectory(virtualDirectory) : null;
        if (directory != null) {
            myResDirectory = directory.getVirtualFile();
        } else {
            // As a last resort, if we have poor context,
            // e.g., quick fix from within a .java file, set up the UI
            // based on the deps of the .java file.
            BlazeCreateResourceUtils.setupResDirectoryChoices(project, myContextFile, myResDirLabel, myResDirCombo);
        }
    } else {
        // As a last resort, if we have no context at all, set up some UI.
        BlazeCreateResourceUtils.setupResDirectoryChoices(project, null, myResDirLabel, myResDirCombo);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager)

Example 53 with PsiManager

use of com.intellij.psi.PsiManager in project intellij by bazelbuild.

the class BuildReferenceManager method resolveFile.

@Nullable
public PsiFileSystemItem resolveFile(File file) {
    VirtualFile vf = VirtualFileSystemProvider.getInstance().getSystem().findFileByPath(file.getPath());
    if (vf == null) {
        return null;
    }
    PsiManager manager = PsiManager.getInstance(project);
    return vf.isDirectory() ? manager.findDirectory(vf) : manager.findFile(vf);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManager(com.intellij.psi.PsiManager) Nullable(javax.annotation.Nullable)

Example 54 with PsiManager

use of com.intellij.psi.PsiManager in project idea-php-typo3-plugin by cedricziel.

the class TableUtil method getTableDefinitionElements.

public static PsiElement[] getTableDefinitionElements(@NotNull String tableName, @NotNull Project project) {
    PsiFile[] extTablesSqlFilesInProjectContainingTable = getExtTablesSqlFilesInProjectContainingTable(tableName, project);
    Set<PsiElement> elements = new HashSet<>();
    PsiManager psiManager = PsiManager.getInstance(project);
    for (PsiFile virtualFile : extTablesSqlFilesInProjectContainingTable) {
        FileBasedIndex.getInstance().processValues(TablenameFileIndex.KEY, tableName, virtualFile.getVirtualFile(), (file, value) -> {
            PsiFile file1 = psiManager.findFile(file);
            if (file1 != null) {
                PsiElement elementAt = file1.findElementAt(value.getEndOffset() - 2);
                if (elementAt != null) {
                    elements.add(elementAt);
                }
            }
            return true;
        }, GlobalSearchScope.allScope(project));
    }
    return elements.toArray(new PsiElement[elements.size()]);
}
Also used : PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet)

Example 55 with PsiManager

use of com.intellij.psi.PsiManager in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPathUseScope method contains.

@Override
public boolean contains(@NotNull VirtualFile referenceFile) {
    VirtualFile referenceDirectory = referenceFile.isDirectory() ? referenceFile : referenceFile.getParent();
    if (referenceDirectory == null) {
        return false;
    }
    VirtualFile declarationDirectory = myDeclarationFile.getParent();
    if (referenceDirectory.equals(declarationDirectory)) {
        return true;
    }
    Project project = ObjectUtils.assertNotNull(getProject());
    PsiManager psiManager = PsiManager.getInstance(project);
    PsiFile referencePsiFile = psiManager.findFile(referenceFile);
    Module module = referencePsiFile != null ? ModuleUtilCore.findModuleForPsiElement(referencePsiFile) : null;
    GoPathScopeHelper scopeHelper = GoPathScopeHelper.fromReferenceFile(project, module, referenceFile);
    if (!scopeHelper.couldBeReferenced(myDeclarationFile, referenceFile)) {
        return false;
    }
    if (!myFilterByImportList) {
        return true;
    }
    if (!(referencePsiFile instanceof GoFile)) {
        // it's some injection or cross-reference, so we cannot check its imports
        return true;
    }
    PsiFile declarationPsiFile = psiManager.findFile(myDeclarationFile);
    if (declarationPsiFile instanceof GoFile) {
        String importPath = ((GoFile) declarationPsiFile).getImportPath(scopeHelper.isVendoringEnabled());
        Map<String, GoImportSpec> importedPackagesMap = ((GoFile) referencePsiFile).getImportedPackagesMap();
        if (importedPackagesMap.containsKey(importPath)) {
            return true;
        }
        if (hasRelativeImportOfTargetPackage(importedPackagesMap.keySet(), referenceDirectory, declarationDirectory)) {
            return true;
        }
        for (GoFile packageFile : GoPackageUtil.getAllPackageFiles(referencePsiFile.getContainingDirectory(), null)) {
            if (packageFile != referencePsiFile && referencePsiFile.getOriginalFile() != packageFile) {
                Map<String, GoImportSpec> packagesMap = packageFile.getImportedPackagesMap();
                if (packagesMap.containsKey(importPath)) {
                    return true;
                }
                if (hasRelativeImportOfTargetPackage(packagesMap.keySet(), referenceDirectory, declarationDirectory)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GoFile(com.goide.psi.GoFile) GoImportSpec(com.goide.psi.GoImportSpec) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

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