本文整理匯總了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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();
}
示例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);
}
}