Package com.intellij.psi

Examples of com.intellij.psi.PsiDocumentManager$Listener


     * checks that the XML is valid .
     *
     * @return {@code true} if the POM xml is valid, {@code false} otherwise.
     */
    public boolean isValid() {
        final PsiDocumentManager mgr = PsiDocumentManager.getInstance(project);
        final PsiFile file = mgr.getCachedPsiFile(document);
        if (file == null)
            return false;
        return file.isValid();
    }
View Full Code Here


    public void navigateToSource(final GoalNode pNode) {
        navigateToSource(pNode.getUserObject());
    }

    public void navigateToSource(final Goal pGoal) {
        final PsiDocumentManager psiMgr = PsiDocumentManager.getInstance(project);
        final FileEditorManager fileMgr = FileEditorManager.getInstance(project);

        final VirtualFile script = getGoalContainerFile(pGoal.getContainer());
        if (script == null)
            return;

        final OpenFileDescriptor desc = new OpenFileDescriptor(project, script);
        if (desc.canNavigateToSource()) {
            desc.navigate(true);
            final FileEditor fileEditor = fileMgr.getSelectedEditor(script);
            if (fileEditor instanceof TextEditor) {
                final Editor editor = ((TextEditor) fileEditor).getEditor();
                final Document document = editor.getDocument();
                final PsiFile psiFile = psiMgr.getPsiFile(document);
                if (!(psiFile instanceof XmlFile))
                    return;

                final XmlFile xmlFile = (XmlFile) psiFile;
                final XmlDocument xmlDoc = xmlFile.getDocument();
View Full Code Here

     *
     * @return the XML project, or {@code null} if the file can't be found (shouldn't happen)
     */
    public static XmlFile findXmlFile(final Project pProject,
                                      final Document pDocument) {
        final PsiDocumentManager psiDocMgr = PsiDocumentManager.getInstance(pProject);

        PsiFile psiFile = psiDocMgr.getCachedPsiFile(pDocument);
        if (psiFile == null)
            psiFile = psiDocMgr.getPsiFile(pDocument);

        if (psiFile == null || psiFile instanceof XmlFile)
            return (XmlFile) psiFile;

        final VirtualFile virtualFile = psiFile.getVirtualFile();
View Full Code Here

      Runnable createFormatRunnable(final PsiFile file) {
        return new Runnable() {
          @Override
          public void run() {
            try {
              final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
              final Document document = manager.getDocument(file);

              assert document != null;

              for (int lineNum = 0; lineNum < document.getLineCount(); lineNum++) {
                CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(getProject());
View Full Code Here

                    }
                }
            }

            private void removeImport(LineColRange range) {
                PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
                Document document = manager.getDocument(psiFile);
                if (document == null)
                    return;
                manager.commitDocument(document);
                TextRange textRange = range.getRange(psiFile);
                int start = textRange.getStartOffset();
                int end = textRange.getEndOffset();
                int line = document.getLineNumber(end);
                int lineStart = document.getLineStartOffset(line);
View Full Code Here

        }
        return nextPsiElement;
    }

    public static PsiFile getPsiFile(Project project, Document document) {
        PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
        return psiDocumentManager == null ? null : psiDocumentManager.getPsiFile(document);
    }
View Full Code Here

  @NotNull
  public static TextRange getLineRange(@NotNull PsiFile psiFile, Integer line) {
    if (line == null) return TextRange.EMPTY_RANGE;
    Project project = psiFile.getProject();
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    Document document = documentManager.getDocument(psiFile.getContainingFile());
    if (document == null) {
      return TextRange.EMPTY_RANGE;
    }
    int ijLine = line > 0 ? line - 1 : 0;
    return getTextRangeForLine(document, ijLine);
View Full Code Here

    }
  }

  public static TextRange getLineRange(@NotNull PsiElement psiElement) {
    Project project = psiElement.getProject();
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    Document document = documentManager.getDocument(psiElement.getContainingFile().getContainingFile());
    if (document == null) {
      return TextRange.EMPTY_RANGE;
    }
    int line = document.getLineNumber(psiElement.getTextOffset());
    int lineEndOffset = document.getLineEndOffset(line);
View Full Code Here

            }
        }
    }

    private String getEditorContent(Editor editor, Project project) {
        final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
        pdm.commitDocument(editor.getDocument());
        PsiFile file = pdm.getPsiFile(editor.getDocument());
        if (file != null) {
            return file.getText();
        }
        return "";
    }
View Full Code Here

    Project project = psiFile.getProject();
    final PsiImportList newImportList = JavaCodeStyleManager.getInstance(project).prepareOptimizeImportsResult(
        (PsiJavaFile) psiFile);

    try {
      final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
      final Document document = manager.getDocument(psiFile);
      if (document != null) {
        manager.commitDocument(document);
      }
      final PsiImportList oldImportList = ((PsiJavaFile) psiFile).getImportList();
      assert oldImportList != null;
      if (newImportList != null) {
        oldImportList.replace(newImportList);
      }
      manager.doPostponedOperationsAndUnblockDocument(document);
    } catch (IncorrectOperationException e) {
      LOG.error(e);
    }
  }
View Full Code Here

TOP

Related Classes of com.intellij.psi.PsiDocumentManager$Listener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.