Java Code Examples for com.intellij.psi.PsiFile#getManager()

The following examples show how to use com.intellij.psi.PsiFile#getManager() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo   File:    License: Apache License 2.0 6 votes vote down vote up
public static PsiFile setName(final PsiFile file, String newName) throws IncorrectOperationException {
  VirtualFile vFile = file.getViewProvider().getVirtualFile();
  PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

    final FileType newFileType = FileTypeRegistry.getInstance().getFileTypeByFileName(newName);
    if (UnknownFileType.INSTANCE.equals(newFileType) || newFileType.isBinary()) {
      // before the file becomes unknown or a binary (thus, not openable in the editor), save it to prevent data loss
      final FileDocumentManager fdm = FileDocumentManager.getInstance();
      final Document doc = fdm.getCachedDocument(vFile);
      if (doc != null) {

    vFile.rename(manager, newName);
  catch(IOException e){
    throw new IncorrectOperationException(e);

  return file.getViewProvider().isPhysical() ? manager.findFile(vFile) : file;
Example 2
Source Project: consulo   File:    License: Apache License 2.0 5 votes vote down vote up
public final boolean isAvailable(@Nonnull Project project, Editor editor, PsiFile file) {
  if (file == null) return false;
  final PsiManager manager = file.getManager();
  if (manager == null) return false;
  if (!manager.isInProject(file)) return false;
  final PsiElement element = getElement(editor, file);
  return element != null && isAvailable(project, editor, element);
Example 3
Source Project: consulo   File:    License: Apache License 2.0 5 votes vote down vote up
static PsiTreeChangeEventImpl createEvent(PsiFile file, int offset) {
  PsiTreeChangeEventImpl e = new PsiTreeChangeEventImpl(file.getManager());
  return e;
Example 4
Source Project: consulo   File:    License: Apache License 2.0 5 votes vote down vote up
public static void doDelete(final PsiFile file) throws IncorrectOperationException {
  final PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

  final VirtualFile vFile = file.getVirtualFile();
  catch(IOException e){
    throw new IncorrectOperationException(e);
Example 5
public PsiElement getCustomDocumentationElement(@NotNull Editor editor, @NotNull PsiFile file,
    @Nullable PsiElement element) {
  if (element != null) {
    List<SuggestionNode> matchedNodesFromRootTillLeaf;
    boolean requestedForTargetValue = false;

    SuggestionService suggestionService =
        ServiceManager.getService(element.getProject(), SuggestionService.class);

    Project project = element.getProject();
    Module module = findModule(element);

    List<String> ancestralKeys = null;
    PsiElement elementContext = element.getContext();
    PsiElement context = elementContext;
    do {
      if (context instanceof YAMLKeyValue) {
        if (ancestralKeys == null) {
          ancestralKeys = new ArrayList<>();
        ancestralKeys.add(0, truncateIdeaDummyIdentifier(((YAMLKeyValue) context).getKeyText()));
      context = requireNonNull(context).getParent();
    } while (context != null);

    String value = null;
    if (elementContext instanceof YAMLKeyValue) {
      value = truncateIdeaDummyIdentifier(((YAMLKeyValue) elementContext).getKeyText());
      requestedForTargetValue = false;
    } else if (elementContext instanceof YAMLPlainTextImpl) {
      value = truncateIdeaDummyIdentifier(element.getText());
      requestedForTargetValue = true;

    if (ancestralKeys != null) {
      matchedNodesFromRootTillLeaf =
          suggestionService.findMatchedNodesRootTillEnd(project, module, ancestralKeys);
      if (matchedNodesFromRootTillLeaf != null) {
        SuggestionNode target =
            matchedNodesFromRootTillLeaf.get(matchedNodesFromRootTillLeaf.size() - 1);
        String targetNavigationPathDotDelimited =
   -> v.getNameForDocumentation(module))
        return new DocumentationProxyElement(file.getManager(), file.getLanguage(),
            targetNavigationPathDotDelimited, target, requestedForTargetValue, value);
  return super.getCustomDocumentationElement(editor, file, element);