@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());
   }
 }
예제 #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
      }
    }
예제 #3
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);
 }
 /**
  * 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();
 }
예제 #5
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) + ")");
    }
  }