Пример #1
0
  /** @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean) */
  public IRegion getDamageRegion(
      final ITypedRegion partition,
      final DocumentEvent event,
      final boolean documentPartitioningChanged) {
    if (!documentPartitioningChanged) {
      try {

        final IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
        final int start = Math.max(partition.getOffset(), info.getOffset());

        int end =
            event.getOffset()
                + (event.getText() == null ? event.getLength() : event.getText().length());

        if ((info.getOffset() <= end) && (end <= info.getOffset() + info.getLength())) {
          // optimize the case of the same line
          end = info.getOffset() + info.getLength();
        } else {
          end = endOfLineOf(end);
        }

        end = Math.min(partition.getOffset() + partition.getLength(), end);
        return new Region(start, end - start);

      } catch (final BadLocationException x) {
      }
    }

    return partition;
  }
Пример #2
0
    /*
     * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
     */
    public void update(DocumentEvent event) {

      int eventOffset = event.getOffset();
      int eventOldLength = event.getLength();
      int eventNewLength = event.getText() == null ? 0 : event.getText().length();
      int deltaLength = eventNewLength - eventOldLength;

      try {
        Position[] positions = event.getDocument().getPositions(fCategory);

        for (int i = 0; i != positions.length; i++) {

          Position position = positions[i];

          if (position.isDeleted()) continue;

          int offset = position.getOffset();
          int length = position.getLength();
          int end = offset + length;

          if (offset >= eventOffset + eventOldLength)
            // position comes
            // after change - shift
            position.setOffset(offset + deltaLength);
          else if (end <= eventOffset) {
            // position comes way before change -
            // leave alone
          } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) {
            // event completely internal to the position - adjust
            // length
            position.setLength(length + deltaLength);
          } else if (offset < eventOffset) {
            // event extends over end of position - adjust length
            int newEnd = eventOffset;
            position.setLength(newEnd - offset);
          } else if (end > eventOffset + eventOldLength) {
            // event extends from before position into it - adjust
            // offset
            // and length
            // offset becomes end of event, length ajusted
            // acordingly
            int newOffset = eventOffset + eventNewLength;
            position.setOffset(newOffset);
            position.setLength(end - newOffset);
          } else {
            // event consumes the position - delete it
            position.delete();
          }
        }
      } catch (BadPositionCategoryException e) {
        // ignore and return
      }
    }
    public synchronized void documentChanged(DocumentEvent event) {
      if (!enabled) return;

      String text = event.getText();

      if (text.equals(COMMAND_TERMINATOR)) {
        if (buffer.length() > 0) { // If we just get a new-line token, execute the current 'thing'.
          buffer.append(COMMAND_TERMINATOR);
          String command = buffer.toString();
          reset();

          console.revertAndAppend(command);
        } else { // If there is no current 'thing', just execute the command terminator ('\n', '\r'
                 // or '\r\n') command.
          queue(COMMAND_TERMINATOR, console.getInputOffset());
          execute();
        }
        return;
      }

      int offset = event.getOffset();
      int length = event.getLength();

      int start = offset - console.getInputOffset();
      if (start >= 0) {
        buffer.replace(start, start + length, text);

        int commandStartOffset = console.getInputOffset();

        String rest = buffer.toString();
        boolean commandsQueued = false;
        do {
          int index = rest.indexOf(COMMAND_TERMINATOR);
          if (index == -1) {
            reset();
            buffer.append(rest);
            break;
          }

          String command = rest.substring(0, index);

          queue(command, commandStartOffset);
          commandStartOffset += index;
          commandsQueued = true;

          rest = rest.substring(index + COMMAND_TERMINATOR.length());
        } while (true);

        if (commandsQueued) execute();
      } else {
        buffer.insert(0, text);
        String toAppend = buffer.toString();
        reset();
        console.revertAndAppend(toAppend);
      }
    }
 /**
  * Whenever the document changes, we stop listening to change the document from within this
  * listener (passing commands to the handler if needed, getting results, etc).
  */
 public void documentChanged(DocumentEvent event) {
   lastChangeMillis = System.currentTimeMillis();
   startDisconnected();
   try {
     int eventOffset = event.getOffset();
     String eventText = event.getText();
     proccessAddition(eventOffset, eventText);
   } finally {
     stopDisconnected();
   }
 }
Пример #5
0
 private void handleDocumentChanged(DocumentEvent event) {
   if (log.isTraceEnabled()) {
     log.trace("Reconciler cancelled");
   }
   cancel();
   ReplaceRegion newReplaceRegion =
       new ReplaceRegion(event.getOffset(), event.getLength(), event.getText());
   synchronized (pendingReplaceRegionLock) {
     if (pendingReplaceRegion != null) {
       pendingReplaceRegion.mergeWith(newReplaceRegion, event.getDocument());
     } else {
       pendingReplaceRegion = newReplaceRegion;
     }
   }
   if (log.isTraceEnabled()) {
     log.trace("Reconciler scheduled with delay: " + delay, new Exception());
   }
   schedule(delay);
 }
Пример #6
0
  public static String buildTestCase(
      URI sourceLRI,
      URI copyLri,
      Collection<DocumentEvent> history,
      String testCaseName,
      String description) {
    StringBuilder sb = new StringBuilder(1024);
    sb.append("    /**\n    " + description + "\n\n    */\n");
    sb.append("    @Test\n");
    sb.append(
        "    public void test"
            + testCaseName
            + "() throws PartInitException, BadLocationException, CoreException {\n");
    sb.append("        // Source / Copy of: " + sourceLRI.toString() + "\n");
    sb.append("        String lriString = \"" + copyLri.toString() + "\";\n");
    sb.append("        URI lri = connection.getSession().getMoin().createLri(lriString);\n");
    sb.append("        final RefObject refObject = (RefObject) connection.getElement(lri);\n");
    sb.append("        assertNotNull(refObject); \n");
    sb.append("        assertTrue(refObject.is___Alive()); \n");
    sb.append("        AbstractGrammarBasedEditor editor = openEditor(refObject);\n");
    sb.append("        CtsDocument document = getDocument(editor);\n");

    for (DocumentEvent stmnt : history) {
      sb.append("        document.replace(");
      sb.append(stmnt.getOffset()).append(", ");
      sb.append(stmnt.getLength()).append(", \"");
      sb.append(escape(stmnt.getText())).append("\");\n");
    }
    sb.append("        saveAll(editor);\n");
    sb.append("        //failOnError(editor);\n");
    sb.append("        assertTrue(refObject.is___Alive());\n");
    sb.append("        // Your assertions on refObject here \n\n");
    sb.append("        close(editor);\n");
    sb.append("    };\n");
    return sb.toString();
  }