Пример #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;
  }
    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();
   }
 }
 @Override
 public void documentChanged(DocumentEvent event) {
   IDocument newDoc = event.getDocument();
   if (docLines != newDoc.getNumberOfLines()) {
     updateAnnotations(false);
     docLines = newDoc.getNumberOfLines();
     docLength = newDoc.getLength();
   } else {
     changeAnnotations(event.getOffset(), newDoc.getLength());
   }
 }
Пример #5
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
      }
    }
Пример #6
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);
 }
Пример #7
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();
  }
 /**
  * Provides the invocation of DeltaResource.setFileSize(long fileSize) method in order to get
  * buffer size. This method is called every document change since this EclipseSensorPlugin
  * instance was added to IDocumentLister. Since this method, the current buffer size of an
  * active file could be grabbed.
  *
  * @param event An event triggered when a document is changed.
  */
 public void documentChanged(DocumentEvent event) {
   EclipseSensor.this.activeBufferSize = event.getDocument().getLength();
 }
Пример #9
0
  public void documentChanged(DocumentEvent event) {

    System.out.println("Document changed");

    IDocument document = event.getDocument();

    // creation of DOM/AST from a ICompilationUnit
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    // set the source as the contents of the document
    parser.setSource(document.get().toCharArray());
    CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);

    // visitor
    astRoot.accept(
        new ASTVisitor() {

          public boolean visit(VariableDeclarationFragment inv) {

            if (inv.getParent() instanceof VariableDeclarationStatement) {

              VariableDeclarationStatement var = (VariableDeclarationStatement) inv.getParent();

              String type = var.getType().toString();

              if (type.equals("FragmentSystem")) {

                fsVariableName = inv.getName().toString();

              } else {

                // store all other variable declarations
                variables.put(inv.getName().toString(), type);
              }
            }

            return false;
          }

          public boolean visit(MethodInvocation inv) {
            if (inv.getExpression() instanceof SimpleName) {

              SimpleName name = (SimpleName) inv.getExpression();

              // check if we have set properties on the fragment system
              // if so, save the information
              if (name.toString().equals(fsVariableName)) {

                if (inv.getName().toString().equals("setGrammar")) {

                  Expression expr = (Expression) inv.arguments().get(0);
                  if (expr != null) fsGrammar = expr.toString();
                } else if (inv.getName().toString().equals("setFragmentsFolder")) {

                  Expression expr = (Expression) inv.arguments().get(0);
                  if (expr != null) fsFragmentsLocation = expr.toString();
                }
              }
            }

            // only type check bind statements if required properties
            // of the fragment system are set
            if (fsGrammar != null && fsFragmentsLocation != null) {

              if (inv.getName().toString().equals("bind")) {

                System.out.print("BIND called, with: ");

                List<Expression> args = inv.arguments();
                for (Expression arg : args) {
                  System.out.print(arg.toString() + ", ");
                }
                System.out.println();

                System.out.println("GRA: " + fsGrammar);
                System.out.println("LOC: " + fsFragmentsLocation);

                // check the bind statement
                System.out.println("CALL");
                typeCheckBindStatement(
                    fsGrammar,
                    fsFragmentsLocation,
                    inv.getExpression().toString(),
                    args.get(0).toString(),
                    args.get(1).toString());
                System.out.println("BACK");
              }
            }

            return false;
          }
        });

    System.out.println("STA: " + variables.size());
    Enumeration<String> en = variables.keys();
    while (en.hasMoreElements()) {
      String s = en.nextElement();
      System.out.println("VAR: (" + s + "," + variables.get(s) + ")");
    }
  }