當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.setText方法代碼示例

本文整理匯總了Java中com.intellij.openapi.editor.Document.setText方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.setText方法的具體用法?Java Document.setText怎麽用?Java Document.setText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.editor.Document的用法示例。


在下文中一共展示了Document.setText方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyFix

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    try {
        PsiElement element = descriptor.getPsiElement();
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        int quotePosition = CsvIntentionHelper.getOpeningQuotePosition(element);
        if (quotePosition != -1) {
            quotePositions.add(quotePosition);
        }
        PsiElement endSeparatorElement = CsvIntentionHelper.findQuotePositionsUntilSeparator(element, quotePositions);
        if (endSeparatorElement == null) {
            quotePositions.add(document.getTextLength());
        } else {
            quotePositions.add(endSeparatorElement.getTextOffset());
        }
        String text = CsvIntentionHelper.addQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:24,代碼來源:CsvValidationInspection.java

示例2: unquoteAll

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void unquoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        List<Integer> quotePositions = new ArrayList<>();
        Collection<PsiElement> fields = getAllFields(psiFile);
        for (PsiElement field : fields) {
            if (getChildren(field).stream().anyMatch(element -> getElementType(element) == CsvTypes.ESCAPED_TEXT)) {
                continue;
            }
            if (getElementType(field.getFirstChild()) == CsvTypes.QUOTE) {
                quotePositions.add(field.getFirstChild().getTextOffset());
            }
            if (getElementType(field.getLastChild()) == CsvTypes.QUOTE) {
                quotePositions.add(field.getLastChild().getTextOffset());
            }
        }
        String text = removeQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:23,代碼來源:CsvIntentionHelper.java

示例3: quoteValue

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void quoteValue(@NotNull Project project, @NotNull PsiElement element) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        element = getParentFieldElement(element);
        int quotePosition = getOpeningQuotePosition(element.getFirstChild(), element.getLastChild());
        if (quotePosition != -1) {
            quotePositions.add(quotePosition);
        }
        PsiElement endSeparatorElement = findQuotePositionsUntilSeparator(element, quotePositions);
        if (endSeparatorElement == null) {
            quotePositions.add(document.getTextLength());
        } else {
            quotePositions.add(endSeparatorElement.getTextOffset());
        }
        String text = addQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:23,代碼來源:CsvIntentionHelper.java

示例4: unquoteValue

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void unquoteValue(@NotNull Project project, @NotNull PsiElement element) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        element = getParentFieldElement(element);
        if (getElementType(element.getFirstChild()) == CsvTypes.QUOTE) {
            quotePositions.add(element.getFirstChild().getTextOffset());
        }
        if (getElementType(element.getLastChild()) == CsvTypes.QUOTE) {
            quotePositions.add(element.getLastChild().getTextOffset());
        }
        String text = removeQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:19,代碼來源:CsvIntentionHelper.java

示例5: refmt

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
void refmt(Project project, String format, Document document) {
    String oldText = document.getText();
    String newText = m_refmtProcess.run(project, format, oldText);
    if (!oldText.isEmpty() && !newText.isEmpty()) { // additional protection
        document.setText(newText);
    }
}
 
開發者ID:reasonml-editor,項目名稱:reasonml-idea-plugin,代碼行數:8,代碼來源:RefmtManager.java

示例6: save

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void save(VirtualFile file, String content)
{
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    Document document = fileDocumentManager.getDocument(file);
    if (document != null)
    {
        document.setText(content);
        fileDocumentManager.saveDocument(document);
    }
}
 
開發者ID:miche-atucha,項目名稱:deps-checker,代碼行數:11,代碼來源:VirtualFileHelper.java

示例7: resetDocument

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static void resetDocument(@NotNull final Document document,
                                     @NotNull final TaskFile taskFile) {
  StudyUtils.deleteGuardedBlocks(document);
  taskFile.setTrackChanges(false);
  clearDocument(document);

  document.setText(taskFile.text);
  taskFile.setTrackChanges(true);
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:10,代碼來源:StudyRefreshTaskFileAction.java

示例8: actionPerformed

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {
    //Get all the required data from data keys
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    //Access document, caret, and selection
    final Document document = editor.getDocument();
    final SelectionModel selectionModel = editor.getSelectionModel();

    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    //New instance of Runnable to make a replacement
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            //  return hex(random.randint(0, 2 ** 64) | 1 << 63)
            // from 0 to 64
            BigInteger rand = new BigInteger(64, new Random());
            rand = rand.or(new BigInteger("1").shiftLeft(63));
            String capnpId = rand.toString(16);
            document.setText( String.format("@0x%s; \n\n", capnpId) + document.getText());
        }
    };
    //Making the replacement
    WriteCommandAction.runWriteCommandAction(project, runnable);
    selectionModel.removeSelection();
}
 
開發者ID:xmonader,項目名稱:sercapnp,代碼行數:28,代碼來源:GenerateCapnpID.java

示例9: quoteAll

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void quoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        List<Integer> quotePositions = new ArrayList<>();
        Collection<PsiElement> fields = getAllFields(psiFile);
        PsiElement separator;
        for (PsiElement field : fields) {
            if (field.getFirstChild() == null || getElementType(field.getFirstChild()) != CsvTypes.QUOTE) {
                separator = getPreviousSeparator(field);
                if (separator == null) {
                    quotePositions.add(field.getParent().getTextOffset());
                } else {
                    quotePositions.add(separator.getTextOffset() + separator.getTextLength());
                }
            }
            if (field.getLastChild() == null || getElementType(field.getLastChild()) != CsvTypes.QUOTE) {
                separator = getNextSeparator(field);
                if (separator == null) {
                    quotePositions.add(field.getParent().getTextOffset() + field.getParent().getTextLength());
                } else {
                    quotePositions.add(separator.getTextOffset());
                }
            }
        }
        String text = addQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:31,代碼來源:CsvIntentionHelper.java


注:本文中的com.intellij.openapi.editor.Document.setText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。