Examples of PsiDocumentManager


Examples of com.intellij.psi.PsiDocumentManager

        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

Examples of com.intellij.psi.PsiDocumentManager

        this.mySortedXml = sortedXml;
        this.myPsiFile = psiFile;
    }

    public void run() {
        PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myPsiFile.getProject());
        Document document = documentManager.getDocument(myPsiFile);
        document.setText(mySortedXml);

        documentManager.commitDocument(document);
    }
View Full Code Here

Examples of com.intellij.psi.PsiDocumentManager

    return Result.CONTINUE;
  }

  public static boolean insertCloseTagIfNeeded(Editor editor, PsiFile file, Project project) {
    final Document document = editor.getDocument();
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);

    int offset = editor.getCaretModel().getOffset();
    documentManager.commitDocument(document);
    char charAtOffset = DocumentUtils.getCharAt(document, offset);

    if (charAtOffset != '>') {
      EditorModificationUtil.insertStringAtCaret(editor, ">", true, 0);
    }
View Full Code Here

Examples of com.intellij.psi.PsiDocumentManager

      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

Examples of com.intellij.psi.PsiDocumentManager

    if (file instanceof YAMLFile && file.isValid()) {
      final YAMLFile yamlFile = (YAMLFile) file;
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
          Document document = manager.getDocument(yamlFile);
          int length = document.getTextLength();
          document.insertString(length, "\n" + "test:");
          manager.commitDocument(document);
        }
      });
    }
  }
View Full Code Here

Examples of com.intellij.psi.PsiDocumentManager

    @Override
    protected void doCheckFile(@NotNull GoFile file,
                               @NotNull final InspectionResult result) {
        Project project = file.getProject();

        PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
        Document document = pdm.getDocument(file);
        if (document != null) {
            pdm.commitDocument(document);
        }

        Collection<GoImportDeclaration> unusedImports =
                UnusedImportsFinder.findUnusedImports(file);
View Full Code Here

Examples of com.intellij.psi.PsiDocumentManager

        if (violations == null) {
            return null;
        }

        Project project = element.getProject();
        PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
        Document document = documentManager.getDocument(element.getContainingFile());
        if (document == null) {
            return null;
        }

        List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
View Full Code Here

Examples of com.intellij.psi.PsiDocumentManager

                VirtualFile virtualFile = TranslationKeyIntentionAction.this.yamlFile.getVirtualFile();
                if(virtualFile == null) {
                    return;
                }

                PsiDocumentManager manager = PsiDocumentManager.getInstance(yamlFile.getProject());
                Document document = manager.getDocument(yamlFile);
                if (document != null) {
                    manager.commitDocument(document);
                }

                final PsiElement yamlDocu = PsiTreeUtil.findChildOfType(yamlFile, YAMLDocument.class);
                if(yamlDocu == null) {
                    return;
                }

                final YamlKeyFinder.MatchedKey goToPsi = YamlKeyFinder.findLastValueElement(yamlDocu, keyName);
                if(goToPsi == null) {
                    return;
                }

                // search indent and EOL value
                String indent = TranslationInsertUtil.findIndent(goToPsi.getYamlKeyValue());
                String eol = TranslationInsertUtil.findEol(goToPsi.getYamlKeyValue());

                String currentIndentOffset = "";
                PsiElement lastKnownPsiElement = goToPsi.getYamlKeyValue();
                if(lastKnownPsiElement instanceof YAMLKeyValue) {
                    currentIndentOffset = ((YAMLKeyValue) lastKnownPsiElement).getValueIndent();
                }

                String insertString = "";
                String[] missingKeys = goToPsi.getMissingKeys();
                for ( int i = 0; i < missingKeys.length; i++ ) {
                    String currentKeyName = missingKeys[i];

                    // add indent
                    insertString += eol + currentIndentOffset + StringUtils.repeat(indent, i);

                    // on last key name we dont need new lines
                    if(goToPsi.getMissingKeys().length - 1 == i) {
                        // we are developer should other translate it
                        insertString += currentKeyName + ": '" + keyName + "'";
                    } else {
                        insertString += currentKeyName + ":";
                    }
                }


                // @TODO: check is last array line on contains eol and indent and move above this line
                document.insertString(goToPsi.getYamlKeyValue().getTextRange().getEndOffset(), insertString);
                manager.doPostponedOperationsAndUnblockDocument(document);
                manager.commitDocument(document);

                // navigate to new psi element
                // @TODO: jump into quote value
                manager.commitAndRunReadAction(new Runnable() {
                    @Override
                    public void run() {
                        YAMLKeyValue psiElement = YamlKeyFinder.find(yamlDocu, keyName);
                        if(psiElement != null) {
                            Symfony2SearchForm.navigateToPsiElement(psiElement.getValue());
View Full Code Here

Examples of com.intellij.psi.PsiDocumentManager

        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            @Override
            public void run() {

                final PsiDocumentManager manager = PsiDocumentManager.getInstance(yamlFile.getProject());
                final Document document = manager.getDocument(yamlFile);
                if (document != null) {
                    manager.commitDocument(document);
                }

                final PsiElement yamlDocu = PsiTreeUtil.findChildOfType(yamlFile, YAMLDocument.class);
                if(yamlDocu == null) {
                    return;
                }

                final YamlKeyFinder.MatchedKey goToPsi = YamlKeyFinder.findLastValueElement(yamlDocu, keyName);
                if(goToPsi == null) {
                    return;
                }

                // search indent and EOL value
                String indent = findIndent(goToPsi.getYamlKeyValue());
                String eol = findEol(goToPsi.getYamlKeyValue());

                String currentIndentOffset = "";
                PsiElement lastKnownPsiElement = goToPsi.getYamlKeyValue();
                if(lastKnownPsiElement instanceof YAMLKeyValue) {
                    currentIndentOffset = ((YAMLKeyValue) lastKnownPsiElement).getValueIndent();
                }

                String insertString = "";
                String[] missingKeys = goToPsi.getMissingKeys();
                for ( int i = 0; i < missingKeys.length; i++ ) {
                    String currentKeyName = missingKeys[i];

                    // add indent
                    insertString += eol + currentIndentOffset + StringUtils.repeat(indent, i);

                    // on last key name we dont need new lines
                    if(goToPsi.getMissingKeys().length - 1 == i) {
                        // we are developer should other translate it
                        insertString += currentKeyName + ": '" + translation + "'";
                    } else {
                        insertString += currentKeyName + ":";
                    }
                }


                // @TODO: check is last array line on contains eol and indent and move above this line

                final String finalInsertString = insertString;
                new WriteCommandAction(yamlFile.getProject()) {
                    @Override
                    protected void run(Result result) throws Throwable {
                        document.insertString(goToPsi.getYamlKeyValue().getTextRange().getEndOffset(), finalInsertString);
                        manager.doPostponedOperationsAndUnblockDocument(document);
                        manager.commitDocument(document);
                    }

                    @Override
                    public String getGroupID() {
                        return "Translation Extraction";
                    }
                }.execute();


                if(!openFile) {
                    return;
                }

                // navigate to new psi element
                // @TODO: jump into quote value
                manager.commitAndRunReadAction(new Runnable() {
                    @Override
                    public void run() {
                        YAMLKeyValue psiElement = YamlKeyFinder.find(yamlDocu, keyName);
                        if(psiElement != null) {
                            Symfony2SearchForm.navigateToPsiElement(psiElement.getValue());
View Full Code Here

Examples of com.intellij.psi.PsiDocumentManager

        for (ErlangTopType type : topTypeList) {
          ErlangQVar qVar = type.getQVar();
          vars.add(qVar != null ? qVar.getName() : "_");
        }

        PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
        Document document = manager.getDocument(file);
        PsiElement lastChild = file.getLastChild();
        int textOffset = lastChild == null ? 0 : lastChild.getTextRange().getEndOffset();

        if (document == null) return;
        String join = StringUtil.join(vars, ", ");
        String newFunction = "\n" + name + "(" + join + ") ->\n erlang:error(not_implemented).\n";
        document.insertString(textOffset, newFunction);
        manager.commitDocument(document);
        CodeStyleManager.getInstance(project).reformatText(file, textOffset, textOffset + newFunction.length());
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.