use of com.intellij.psi.PsiManager in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoImportReferenceSet method computeDefaultContexts.
@NotNull
@Override
public Collection<PsiFileSystemItem> computeDefaultContexts() {
PsiFile file = getContainingFile();
if (file == null || !file.isValid() || isAbsolutePathReference()) {
return Collections.emptyList();
}
PsiManager psiManager = file.getManager();
Module module = ModuleUtilCore.findModuleForPsiElement(file);
Project project = file.getProject();
LinkedHashSet<VirtualFile> sourceRoots = GoVendoringUtil.isVendoringEnabled(module) ? GoSdkUtil.getVendoringAwareSourcesPathsToLookup(project, module, file.getVirtualFile()) : GoSdkUtil.getSourcesPathsToLookup(project, module);
return ContainerUtil.mapNotNull(sourceRoots, psiManager::findDirectory);
}
use of com.intellij.psi.PsiManager in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoFmtCheckinFactory method createHandler.
@Override
@NotNull
public CheckinHandler createHandler(@NotNull CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
return new CheckinHandler() {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
JCheckBox checkBox = new JCheckBox("Go fmt");
return new RefreshableOnComponent() {
@Override
@NotNull
public JComponent getComponent() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(checkBox, BorderLayout.WEST);
return panel;
}
@Override
public void refresh() {
}
@Override
public void saveState() {
PropertiesComponent.getInstance(panel.getProject()).setValue(GO_FMT, Boolean.toString(checkBox.isSelected()));
}
@Override
public void restoreState() {
checkBox.setSelected(enabled(panel));
}
};
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
if (enabled(panel)) {
Ref<Boolean> success = Ref.create(true);
FileDocumentManager.getInstance().saveAllDocuments();
for (PsiFile file : getPsiFiles()) {
VirtualFile virtualFile = file.getVirtualFile();
new GoFmtFileAction().doSomething(virtualFile, ModuleUtilCore.findModuleForPsiElement(file), file.getProject(), "Go fmt", true, result -> {
if (!result)
success.set(false);
});
}
if (!success.get()) {
return showErrorMessage(executor);
}
}
return super.beforeCheckin();
}
@NotNull
private ReturnResult showErrorMessage(@Nullable CommitExecutor executor) {
String[] buttons = new String[] { "&Details...", commitButtonMessage(executor, panel), CommonBundle.getCancelButtonText() };
int answer = Messages.showDialog(panel.getProject(), "<html><body>GoFmt returned non-zero code on some of the files.<br/>" + "Would you like to commit anyway?</body></html>\n", "Go Fmt", null, buttons, 0, 1, UIUtil.getWarningIcon());
if (answer == Messages.OK) {
return ReturnResult.CLOSE_WINDOW;
}
if (answer == Messages.NO) {
return ReturnResult.COMMIT;
}
return ReturnResult.CANCEL;
}
@NotNull
private List<PsiFile> getPsiFiles() {
Collection<VirtualFile> files = panel.getVirtualFiles();
List<PsiFile> psiFiles = ContainerUtil.newArrayList();
PsiManager manager = PsiManager.getInstance(panel.getProject());
for (VirtualFile file : files) {
PsiFile psiFile = manager.findFile(file);
if (psiFile instanceof GoFile) {
psiFiles.add(psiFile);
}
}
return psiFiles;
}
};
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class ThumbnailViewUI method getSelectedElements.
@NotNull
private PsiElement[] getSelectedElements() {
VirtualFile[] selectedFiles = getSelectedFiles();
Set<PsiElement> psiElements = new HashSet<>(selectedFiles.length);
PsiManager psiManager = PsiManager.getInstance(thumbnailView.getProject());
for (VirtualFile file : selectedFiles) {
PsiFile psiFile = psiManager.findFile(file);
PsiElement element = psiFile != null ? psiFile : psiManager.findDirectory(file);
if (element != null) {
psiElements.add(element);
}
}
return PsiUtilCore.toPsiElementArray(psiElements);
}
use of com.intellij.psi.PsiManager in project android by JetBrains.
the class AndroidManifestsGroupNode method findFileToOpen.
@Nullable
private VirtualFile findFileToOpen(@NotNull Set<VirtualFile> files) {
VirtualFile bestFile = Iterables.getFirst(files, null);
PsiManager psiManager = PsiManager.getInstance(myProject);
for (VirtualFile f : files) {
PsiFile psiFile = psiManager.findFile(f);
if (psiFile == null) {
continue;
}
IdeaSourceProvider sourceProvider = AndroidManifestFileNode.getSourceProvider(getValue(), psiFile);
if (sourceProvider != null && SdkConstants.FD_MAIN.equals(sourceProvider.getName())) {
bestFile = f;
}
}
return bestFile;
}
use of com.intellij.psi.PsiManager in project android by JetBrains.
the class AndroidManifestsGroupNode method getChildren.
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
PsiManager psiManager = PsiManager.getInstance(myProject);
List<AbstractTreeNode> children = Lists.newArrayList();
for (VirtualFile manifest : mySources) {
if (!manifest.isValid()) {
continue;
}
PsiFile psiFile = psiManager.findFile(manifest);
if (psiFile != null) {
AndroidFacet facet = getValue();
assert facet != null : "Android Facet for module cannot be null";
children.add(new AndroidManifestFileNode(myProject, psiFile, getSettings(), facet));
}
}
return children;
}
Aggregations