Package org.cyclop.model

Examples of org.cyclop.model.ContextCqlCompletion


    }
  }

  @Test
  public void testFindInitialCompletion() {
    ContextCqlCompletion completion = cs.findInitialCompletion();
    verifyInitialCompletion(completion);
  }
View Full Code Here


    verifyInitialCompletion(completion);
  }

  @Test
  public void testFindCompletion_CursorOn0() {
    ContextCqlCompletion completion = cs.findCompletion(new CqlQuery(CqlQueryType.SELECT,
        "select * from cqldemo.mybooks  where "), 0);
    verifyInitialCompletion(completion);
  }
View Full Code Here

        "select * from cqldemo.mybooks  where "), 0);
    verifyInitialCompletion(completion);
  }

  private void veifySelectWithOrderBy(String cql) {
    ContextCqlCompletion completion = cs.findCompletion(new CqlQuery(CqlQueryType.SELECT, cql), -1);
    vh.verifyFullAndMinCompletionTheSame(completion, 18);

    ImmutableSortedSet<? extends CqlPart> cmp = completion.cqlCompletion.fullCompletion;
    vh.verifyContainsMybooksColumns(cmp, true);
    vh.verifyContainsAllKeyspaces(cmp, false);
View Full Code Here

    assertEquals(col.toString(), contains, col.contains(CqlKeyword.Def.COUNT_AST.value));
    assertEquals(col.toString(), contains, col.contains(CqlKeyword.Def.COUNT_ONE.value));
  }

  private void verifyCreateKeyspaceWith(String cql) {
    ContextCqlCompletion completion = cs.findCompletion(new CqlQuery(CqlQueryType.CREATE_KEYSPACE, cql));

    vh.verifyFullAndMinCompletionNotTheSame(completion, 10, 34);

    {
      ImmutableSortedSet<? extends CqlPart> mcmp = completion.cqlCompletion.minCompletion;
View Full Code Here

  @Inject
  private CqlParser parser;

  @Override
  public ContextCqlCompletion findInitialCompletion() {
    ContextCqlCompletion compl = new ContextCqlCompletion(CqlQueryType.UNKNOWN, parser.findInitialCompletion());

    LOG.debug("Found initial completion: {}", compl);
    return compl;
  }
View Full Code Here

    return compl;
  }

  @Override
  public ContextCqlCompletion findCompletion(CqlQuery cqlQuery) {
    ContextCqlCompletion compl = findCompletion(cqlQuery, -1);
    LOG.debug("Found completion for query {} - > {}", cqlQuery, compl);
    return compl;
  }
View Full Code Here

  public ContextCqlCompletion findCompletion(CqlQuery cqlQuery, int cursorPosition) {
    if (cursorPosition == 0 || cursorPosition == 1) {
      return findInitialCompletion();
    }
    Optional<ContextCqlCompletion> fcomp = parser.findCompletion(cqlQuery, cursorPosition);
    ContextCqlCompletion comp = fcomp.orElse(ContextCqlCompletion.EMPTY);
    LOG.debug("Found completion for query {} -> {} - > {}", cqlQuery, cursorPosition, comp);
    return comp;
  }
View Full Code Here

    Optional<DecisionListSupport> dlsOp = findCompletionDecision(cqlQuery);
    if (!dlsOp.isPresent()) {
      // user started typing, has first world and there is no decision
      // list for it
      ContextCqlCompletion initial = null;
      if (!cqlQuery.partLc.isEmpty() && !cqlQuery.partLc.contains(" ")) {
        initial = new ContextCqlCompletion(CqlQueryType.UNKNOWN, initialCqlCompletion);
      }
      return Optional.ofNullable(initial);
    }

    if (cursorPosition < 0) {
      cursorPosition = 0;
    }

    DecisionListSupport dls = dlsOp.get();
    CqlPartCompletion[][] decisionList = dls.getDecisionList();
    if (decisionList.length == 0) {
      return Optional.empty();
    }

    int cqLength = cqlQuery.partLc.length();
    if (cursorPosition > cqLength) {
      cursorPosition = cqLength;
    }

    String cqlLc = cqlQuery.partLc.substring(0, cursorPosition);
    int offset = 0;
    CqlPartCompletion lastMatchingCompletion = null;

    // go over all parsing decisions, until you find one that cannot be
    // applied - this means that previous one
    // is the right chose for completion
    for (CqlPartCompletion[] partCompletionList : decisionList) {
      LOG.debug("Next completion");
      boolean found = false;
      for (CqlPartCompletion partCompletion : partCompletionList) {
        LOG.debug("Checking: {}", partCompletion);
        int completionStartMarker = -1;
        if (partCompletion instanceof MarkerBasedCompletion) {
          MarkerBasedCompletion partStatic = (MarkerBasedCompletion) partCompletion;
          String startMarker = partStatic.startMarker().partLc;
          completionStartMarker = cqlLc.indexOf(startMarker, offset);

        } else if (partCompletion instanceof OffsetBasedCompletion) {
          OffsetBasedCompletion partDynamic = (OffsetBasedCompletion) partCompletion;
          completionStartMarker = partDynamic.canApply(cqlQuery, offset);

        } else {
          throw new ServiceException("Unsupported CqlPartCompletion: " + partCompletion.getClass());
        }

        LOG.debug("completionStartMarker: {}", completionStartMarker);

        if (completionStartMarker == -1) {
          // this decision cannot be applied - try next one
          continue;
        }
        found = true;
        // current decision can be applied - try next one
        offset = completionStartMarker + 1;
        lastMatchingCompletion = partCompletion;
      }

      if (!found) {
        break;
      }
    }
    ContextCqlCompletion cqc = null;
    if (lastMatchingCompletion != null) {
      CqlCompletion cqlCompletion = lastMatchingCompletion.getCompletion(cqlQuery);
      cqc = new ContextCqlCompletion(dls.queryName(), cqlCompletion);
      LOG.debug("Completion found: {}", cqc);
    } else {
      LOG.debug("Completion not found");
    }
View Full Code Here

      protected void onUpdate(AjaxRequestTarget target) {

        Component cmp = getComponent();
        String editorValue = cmp.getDefaultModelObjectAsString();

        ContextCqlCompletion cqlCompletion;
        if (StringUtils.isEmpty(editorValue)) {
          cqlCompletion = completionService.findInitialCompletion();
        } else {
          RequestCycle requestCycle = RequestCycle.get();
          int index = requestCycle.getRequest().getRequestParameters().getParameterValue("cursorPos").toInt();
          CqlQuery cqlQuery = new CqlQuery(CqlQueryType.UNKNOWN, editorValue);
          cqlCompletion = completionService.findCompletion(cqlQuery, index);
        }
        if (cqlCompletion.cqlCompletion.isEmpty() || cqlCompletion.equals(currentCompletion)) {
          return;
        }

        fireCompletionChanged(cqlCompletion);
        String suggestsScript = generateReplaceSuggestsJs(editorMarkupIdJq,
View Full Code Here

  @Override
  public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    response.render(JavaScriptReferenceHeaderItem.forReference(SUGGEST));

    ContextCqlCompletion cqlCompletion = completionService.findInitialCompletion();
    fireCompletionChanged(cqlCompletion);

    String suggestsScript = generateInitSuggestsJs(editorMarkupIdJq, cqlCompletion.cqlCompletion.fullCompletion);
    response.render(OnDomReadyHeaderItem.forScript(suggestsScript));
  }
View Full Code Here

TOP

Related Classes of org.cyclop.model.ContextCqlCompletion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.