Java 类com.intellij.psi.impl.source.resolve.reference.impl.providers.PsiFileSystemItemUtil 实例源码

项目:intellij-ce-playground    文件:ExtractIncludeFileBase.java   
@NotNull
protected String doExtract(final PsiDirectory targetDirectory,
                           final String targetfileName,
                           final T first,
                           final T last,
                           final Language includingLanguage) throws IncorrectOperationException {
  final PsiFile file = targetDirectory.createFile(targetfileName);
  Project project = targetDirectory.getProject();
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document document = documentManager.getDocument(file);
  document.replaceString(0, document.getTextLength(), first.getText().trim());
  documentManager.commitDocument(document);
  CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(file);  //TODO: adjustLineIndent

  final String relativePath = PsiFileSystemItemUtil.getRelativePath(first.getContainingFile(), file);
  if (relativePath == null) throw new IncorrectOperationException("Cannot extract!");
  return relativePath;
}
项目:tools-idea    文件:ExtractIncludeFileBase.java   
@NotNull
protected String doExtract(final PsiDirectory targetDirectory,
                           final String targetfileName,
                           final T first,
                           final T last,
                           final Language includingLanguage) throws IncorrectOperationException {
  final PsiFile file = targetDirectory.createFile(targetfileName);
  Project project = targetDirectory.getProject();
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document document = documentManager.getDocument(file);
  document.replaceString(0, document.getTextLength(), first.getText().trim());
  documentManager.commitDocument(document);
  CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(file);  //TODO: adjustLineIndent

  final String relativePath = PsiFileSystemItemUtil.getRelativePath(first.getContainingFile(), file);
  if (relativePath == null) throw new IncorrectOperationException("Cannot extract!");
  return relativePath;
}
项目:consulo    文件:ExtractIncludeFileBase.java   
@Nonnull
protected String doExtract(final PsiDirectory targetDirectory,
                           final String targetfileName,
                           final T first,
                           final T last,
                           final Language includingLanguage) throws IncorrectOperationException {
  final PsiFile file = targetDirectory.createFile(targetfileName);
  Project project = targetDirectory.getProject();
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document document = documentManager.getDocument(file);
  document.replaceString(0, document.getTextLength(), first.getText().trim());
  documentManager.commitDocument(document);
  CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(file);  //TODO: adjustLineIndent

  final String relativePath = PsiFileSystemItemUtil.getRelativePath(first.getContainingFile(), file);
  if (relativePath == null) throw new IncorrectOperationException("Cannot extract!");
  return relativePath;
}
项目:intellij-ce-playground    文件:ExtractIncludeDialog.java   
@Override
protected void doOKAction() {
  final Project project = myCurrentDirectory.getProject();

  final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/');
  final String targetFileName = getTargetFileName();

  if (isFileExist(directoryName, targetFileName)) {
    Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title"));
    return;
  }

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName);
  if (type == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          try {
            PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName);
            targetDirectory.checkCreateFile(targetFileName);
            final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory);
            myTargetDirectory = webPath == null ? null : targetDirectory;
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project);
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  }, RefactoringBundle.message("create.directory"), null);
  if (myTargetDirectory == null) return;
  super.doOKAction();
}
项目:tools-idea    文件:ExtractIncludeDialog.java   
@Override
protected void doOKAction() {
  final Project project = myCurrentDirectory.getProject();

  final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/');
  final String targetFileName = getTargetFileName();

  if (isFileExist(directoryName, targetFileName)) {
    Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title"));
    return;
  }

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName);
  if (type == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          try {
            PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName);
            targetDirectory.checkCreateFile(targetFileName);
            final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory);
            myTargetDirectory = webPath == null ? null : targetDirectory;
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project);
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  }, RefactoringBundle.message("create.directory"), null);
  if (myTargetDirectory == null) return;
  super.doOKAction();
}
项目:consulo    文件:ExtractIncludeDialog.java   
@Override
protected void doOKAction() {
  final Project project = myCurrentDirectory.getProject();

  final String directoryName = myTargetDirectoryField.getText().replace(File.separatorChar, '/');
  final String targetFileName = getTargetFileName();

  if (isFileExist(directoryName, targetFileName)) {
    Messages.showErrorDialog(project, RefactoringBundle.message("file.already.exist", targetFileName), RefactoringBundle.message("file.already.exist.title"));
    return;
  }

  final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(targetFileName);
  if (type == null) {
    return;
  }

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      final Runnable action = new Runnable() {
        @Override
        public void run() {
          try {
            PsiDirectory targetDirectory = DirectoryUtil.mkdirs(PsiManager.getInstance(project), directoryName);
            targetDirectory.checkCreateFile(targetFileName);
            final String webPath = PsiFileSystemItemUtil.getRelativePath(myCurrentDirectory, targetDirectory);
            myTargetDirectory = webPath == null ? null : targetDirectory;
          }
          catch (IncorrectOperationException e) {
            CommonRefactoringUtil.showErrorMessage(REFACTORING_NAME, e.getMessage(), null, project);
          }
        }
      };
      ApplicationManager.getApplication().runWriteAction(action);
    }
  }, RefactoringBundle.message("create.directory"), null);
  if (myTargetDirectory == null) return;
  super.doOKAction();
}