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());
}
});
}
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);
}
}
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);
}
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()]);
}
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;
}
Aggregations