/**
  * @param document
  * @param offset
  * @return
  */
 private String computePrefix(EmbeddedDocument document, int offset) {
   final TextPosition textPosition = document.getPositionFromIndex(offset);
   final String line = document.getLineContent(textPosition.getLine());
   final LinearRange lineRange = document.getLinearRangeForLine(textPosition.getLine());
   String partLine = line.substring(0, offset - lineRange.getStartOffset());
   for (int i = partLine.length() - 1; i >= 0; i--) {
     switch (partLine.charAt(i)) {
       case '.':
         break;
       case ' ':
       case '(':
       case ')':
       case '{':
       case '}':
       case ';':
       case '[':
       case ']':
       case '"':
       case '\'':
         return partLine.substring(i + 1);
       default:
         break;
     }
   }
   return partLine;
 }
예제 #2
0
  private void updateContent() {
    /* -save current cursor and (ideally) viewport
     * -set editor content which is also expected to
     *     -reset dirty flag
     *     -clear history
     * -restore current cursor position
     */
    final TextPosition currentCursor = getCursorPosition();
    this.documentStorage.getDocument(
        document.getFile(),
        new EmbeddedDocumentCallback() {

          @Override
          public void onDocumentReceived(final String content) {
            editorWidget.setValue(content);
            document.setCursorPosition(currentCursor);
          }

          @Override
          public void onDocumentLoadFailure(final Throwable caught) {
            displayErrorPanel(constant.editorFileErrorMessage());
          }
        });
  }
 /**
  * @param document
  * @param offset
  * @return
  */
 private String computeTemplatePrefix(EmbeddedDocument document, int offset) {
   final TextPosition textPosition = document.getPositionFromIndex(offset);
   final String line = document.getLineContent(textPosition.getLine());
   final LinearRange lineRange = document.getLinearRangeForLine(textPosition.getLine());
   return line.substring(0, offset - lineRange.getStartOffset());
 }