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

The following examples show how to use com.intellij.psi.PsiFile#getManager() . 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 File: PsiFileImplUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
public static PsiFile setName(final PsiFile file, String newName) throws IncorrectOperationException {
  VirtualFile vFile = file.getViewProvider().getVirtualFile();
  PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

  try{
    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) {
        fdm.saveDocumentAsIs(doc);
      }
    }

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

  return file.getViewProvider().isPhysical() ? manager.findFile(vFile) : file;
}
 
Example 2
Source File: SuppressIntentionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
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 File: ChangeInfoImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static PsiTreeChangeEventImpl createEvent(PsiFile file, int offset) {
  PsiTreeChangeEventImpl e = new PsiTreeChangeEventImpl(file.getManager());
  e.setFile(file);
  e.setOffset(offset);
  return e;
}
 
Example 4
Source File: PsiFileImplUtil.java    From consulo with 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();
  try{
    vFile.delete(manager);
  }
  catch(IOException e){
    throw new IncorrectOperationException(e);
  }
}
 
Example 5
Source File: YamlDocumentationProvider.java    From intellij-spring-assistant with MIT License 4 votes vote down vote up
@Nullable
@Override
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 =
            matchedNodesFromRootTillLeaf.stream().map(v -> v.getNameForDocumentation(module))
                .collect(joining("."));
        return new DocumentationProxyElement(file.getManager(), file.getLanguage(),
            targetNavigationPathDotDelimited, target, requestedForTargetValue, value);
      }
    }
  }
  return super.getCustomDocumentationElement(editor, file, element);
}