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


Java Document.getText方法代碼示例

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


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

示例1: handleEnterInComment

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static void handleEnterInComment(
    PsiElement element, @NotNull PsiFile file, @NotNull Editor editor) {
  if (element.getText().startsWith("/*")) {
    Document document = editor.getDocument();

    int caretOffset = editor.getCaretModel().getOffset();
    int lineNumber = document.getLineNumber(caretOffset);

    String lineTextBeforeCaret =
        document.getText(new TextRange(document.getLineStartOffset(lineNumber), caretOffset));
    String lineTextAfterCaret =
        document.getText(new TextRange(caretOffset, document.getLineEndOffset(lineNumber)));

    if (lineTextAfterCaret.equals("*/")) {
      return;
    }

    String toInsert = lineTextBeforeCaret.equals("") ? " * " : "* ";
    insertText(file, editor, toInsert, toInsert.length());
  }
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:22,代碼來源:EnterHandler.java

示例2: postProcessEnter

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
@Override
public Result postProcessEnter(
    @NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
  if (file.getFileType() != SoyFileType.INSTANCE) {
    return Result.Continue;
  }

  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(caretOffset);
  Document document = editor.getDocument();

  int lineNumber = document.getLineNumber(caretOffset) - 1;
  int lineStartOffset = document.getLineStartOffset(lineNumber);
  String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));

  if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
    handleEnterInComment(element, file, editor);
  } else if (lineTextBeforeCaret.startsWith("/*")) {
    insertText(file, editor, " * \n ", 3);
  }

  return Result.Continue;
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:24,代碼來源:EnterHandler.java

示例3: 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

示例4: getSelectedText

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
/**
 * Returns the selected text if there is any selection. If not return all based on parameter
 *
 * @param defaultToAll If no selection, then this decides whether to return all text
 */
String getSelectedText(boolean defaultToAll) {
    ConsoleView console = this.getConsole();
    Editor myEditor = console != null ? (Editor) CommonDataKeys.EDITOR.getData((DataProvider) console) : null;
    if (myEditor != null) {
        Document document = myEditor.getDocument();
        final SelectionModel selectionModel = myEditor.getSelectionModel();
        if (selectionModel.hasSelection()) {
            return selectionModel.getSelectedText();
        } else if (defaultToAll) {
            return document.getText();
        }
    }
    return null;
}
 
開發者ID:josesamuel,項目名稱:logviewer,代碼行數:20,代碼來源:LogView.java

示例5: getCurrentWords

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private String getCurrentWords(Editor editor) {
    Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    int caretOffset = caretModel.getOffset();
    int lineNum = document.getLineNumber(caretOffset);
    int lineStartOffset = document.getLineStartOffset(lineNum);
    int lineEndOffset = document.getLineEndOffset(lineNum);
    String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));
    char[] chars = lineContent.toCharArray();
    int start = 0, end = 0, cursor = caretOffset - lineStartOffset;

    if (!Character.isLetter(chars[cursor])) {
        return null;
    }

    for (int ptr = cursor; ptr >= 0; ptr--) {
        if (!Character.isLetter(chars[ptr])) {
            start = ptr + 1;
            break;
        }
    }

    int lastLetter = 0;
    for (int ptr = cursor; ptr < lineEndOffset - lineStartOffset; ptr++) {
        lastLetter = ptr;
        if (!Character.isLetter(chars[ptr])) {
            end = ptr;
            break;
        }
    }
    if (end == 0) {
        end = lastLetter + 1;
    }

    return new String(chars, start, end - start);
}
 
開發者ID:a483210,項目名稱:GoogleTranslation,代碼行數:37,代碼來源:GoogleTranslation.java

示例6: rememberAnswers

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private void rememberAnswers(int nextSubtaskIndex, @NotNull TaskWithSubtasks task) {
  VirtualFile taskDir = task.getTaskDir(myProject);
  if (taskDir == null) {
    return;
  }
  VirtualFile srcDir = taskDir.findChild(EduNames.SRC);
  if (srcDir != null) {
    taskDir = srcDir;
  }
  for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
    TaskFile taskFile = entry.getValue();
    VirtualFile virtualFile = taskDir.findFileByRelativePath(entry.getKey());
    if (virtualFile == null) {
      continue;
    }
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    if (document == null) {
      continue;
    }
    for (AnswerPlaceholder placeholder : taskFile.getActivePlaceholders()) {
      if (placeholder.getSubtaskInfos().containsKey(nextSubtaskIndex - 1)) {
        int offset = placeholder.getOffset();
        String answer = document.getText(TextRange.create(offset, offset + placeholder.getRealLength()));
        placeholder.getSubtaskInfos().get(nextSubtaskIndex - 1).setAnswer(answer);
      }
    }
  }
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:29,代碼來源:TaskWithSubtasksChecker.java

示例7: replaceAnswerPlaceholder

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static void replaceAnswerPlaceholder(@NotNull final Document document,
                                             @NotNull final AnswerPlaceholder placeholder) {
  final int offset = placeholder.getOffset();
  final String text = document.getText(TextRange.create(offset, offset + placeholder.getRealLength()));
  placeholder.setTaskText(text);
  placeholder.init();
  String replacementText = placeholder.getPossibleAnswer();

  CommandProcessor.getInstance().runUndoTransparentAction(() -> ApplicationManager.getApplication().runWriteAction(() -> {
    document.replaceString(offset, offset + placeholder.getRealLength(), replacementText);
    FileDocumentManager.getInstance().saveDocument(document);
  }));
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:14,代碼來源:CCFromCourseArchive.java

示例8: getCurrentWords

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public String getCurrentWords(Editor editor) {
    Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    int caretOffset = caretModel.getOffset();
    int lineNum = document.getLineNumber(caretOffset);
    int lineStartOffset = document.getLineStartOffset(lineNum);
    int lineEndOffset = document.getLineEndOffset(lineNum);
    String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));
    char[] chars = lineContent.toCharArray();
    int start = 0, end = 0, cursor = caretOffset - lineStartOffset;

    if (!Character.isLetter(chars[cursor])) {
        Logger.warn("Caret not in a word");
        return null;
    }

    for (int ptr = cursor; ptr >= 0; ptr--) {
        if (!Character.isLetter(chars[ptr])) {
            start = ptr + 1;
            break;
        }
    }

    int lastLetter = 0;
    for (int ptr = cursor; ptr < lineEndOffset - lineStartOffset; ptr++) {
        lastLetter = ptr;
        if (!Character.isLetter(chars[ptr])) {
            end = ptr;
            break;
        }
    }
    if (end == 0) {
        end = lastLetter + 1;
    }

    String ret = new String(chars, start, end-start);
    Logger.info("Selected words: " + ret);
    return ret;
}
 
開發者ID:BolexLiu,項目名稱:ReciteWords,代碼行數:40,代碼來源:ReciteWords.java

示例9: applyFix

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    try {
        PsiElement element = descriptor.getPsiElement();
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        String text = document.getText();
        document.setText(text.substring(0, element.getTextOffset()) + CsvCodeStyleSettings.getCurrentSeparator(project) + text.substring(element.getTextOffset()));
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
開發者ID:SeeSharpSoft,項目名稱:intellij-csv-validator,代碼行數:11,代碼來源:CsvValidationInspection.java

示例10: getPreviousChar

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private String getPreviousChar(Document document, int offset) {
  return offset <= 0 ? " " : document.getText(new TextRange(offset - 1, offset));
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:4,代碼來源:QuoteHandler.java

示例11: getNextChar

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private String getNextChar(Document document, int offset) {
  return offset >= document.getTextLength()
      ? " "
      : document.getText(new TextRange(offset, offset + 1));
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:6,代碼來源:QuoteHandler.java

示例12: smartCheck

import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static void smartCheck(@NotNull final AnswerPlaceholder placeholder,
                              @NotNull final Project project,
                              @NotNull final VirtualFile answerFile,
                              @NotNull final TaskFile answerTaskFile,
                              @NotNull final TaskFile usersTaskFile,
                              @NotNull final PyStudyTestRunner testRunner,
                              @NotNull final VirtualFile virtualFile,
                              @NotNull final Document usersDocument) {
  VirtualFile fileWindows = null;
  VirtualFile windowCopy = null;
  try {
    final int index = placeholder.getIndex();
    String windowCopyName = answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX + answerFile.getExtension();
    windowCopy = answerFile.copy(project, answerFile.getParent(), windowCopyName);
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    final Document windowDocument = documentManager.getDocument(windowCopy);
    if (windowDocument != null) {
      TaskFile windowTaskFile = answerTaskFile.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(virtualFile));
      if (windowTaskFile == null) {
        return;
      }
      EduDocumentListener listener = new EduDocumentListener(windowTaskFile);
      windowDocument.addDocumentListener(listener);
      int start = placeholder.getOffset();
      int end = start + placeholder.getRealLength();
      final AnswerPlaceholder userAnswerPlaceholder = usersTaskFile.getAnswerPlaceholders().get(placeholder.getIndex());
      int userStart = userAnswerPlaceholder.getOffset();
      int userEnd = userStart + userAnswerPlaceholder.getRealLength();
      String text = usersDocument.getText(new TextRange(userStart, userEnd));
      windowDocument.replaceString(start, end, text);
      ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(windowDocument));
      fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy);
      Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
      final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath());
      final ProcessOutput output = handler.runProcess();
      final Course course = StudyTaskManager.getInstance(project).getCourse();
      if (course != null) {
        boolean res = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()).isSuccess();
        StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
      }
    }
  }
  catch (ExecutionException | IOException e) {
    LOG.error(e);
  }
  finally {
    StudyUtils.deleteFile(windowCopy);
    StudyUtils.deleteFile(fileWindows);
  }
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:51,代碼來源:PyStudySmartChecker.java


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