当前位置: 首页>>代码示例>>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;未经允许,请勿转载。