Examples of JsoStringSet


Examples of com.google.collide.json.client.JsoStringSet

    String previousContext = "moo.";
    CompletionContext<State> context = new CompletionContext<State>(
        previousContext, "", false, CompletionType.PROPERTY, null, 0);

    Position cursor = new Position(Document.createEmpty().getFirstLineInfo(), 1);
    JsoStringSet prefixes = scopeTrieBuilder.calculateScopePrefixes(context, cursor);

    assertNotNull(prefixes);
    assertFalse(prefixes.isEmpty());
    assertTrue(prefixes.contains(previousContext));
  }
View Full Code Here

Examples of com.google.collide.json.client.JsoStringSet

    String previousContext = "moo.";
    CompletionContext<State> context = new CompletionContext<State>(
        previousContext, "", false, CompletionType.PROPERTY, null, 0);

    Position cursor = new Position(Document.createEmpty().getFirstLineInfo(), 20);
    JsoStringSet prefixes = builder.calculateScopePrefixes(context, cursor);

    assertNotNull(prefixes);
    assertFalse(prefixes.isEmpty());
    assertTrue(prefixes.contains(OBJECT_1 + "." + METHOD_1 + "." + previousContext));
  }
View Full Code Here

Examples of com.google.collide.json.client.JsoStringSet

   * @param limit number of operations to perform
   * @param range how many different keys can appear in test
   */
  private void checkCorrectnessOnRandomData(final Random rnd, int limit, int range) {
    // Origin instance.
    JsoStringSet mirror = JsoStringSet.create();

    // Array to hold recently generated keys.
    JsoArray<String> values = JsoArray.create();

    // Target instance, with fully deterministic behavior.(driven by our
    // oscillator).
    SkipListStringSet target = new SkipListStringSet(8, new SkipListStringSet.LevelGenerator() {
      @Override
      public int generate() {
        int result = 0;
        while (rnd.nextInt(4) == 0 && result < 7) {
          result++;
        }
        return result;
      }
    });

    for (int i = 0; i < limit; i++) {
      boolean remove = false;
      if (values.size() > 0) {
        // Actually we simulate that set is growing
        // i.e. more key added than removed).
        remove = rnd.nextDouble() > 0.6;
      }

      // Value is either generated or selected from recent values list.
      String value;
      if (remove) {
        // When we are going to remove, recent values is a good choice
        // to choose from.
        value = values.get(rnd.nextInt(values.size()));
        // Eventually, if can't remove - add.
        if (!mirror.contains(value)) {
          remove = false;
        }
      } else {
        value = String.valueOf(rnd.nextInt(range));
        // If key already in set - remove it.
        if (mirror.contains(value)) {
          remove = true;
        } else {
          values.add(value);
        }
      }

      // Perform operation on both instances.
      if (remove) {
        target.remove(value);
        mirror.remove(value);
      } else {
        target.add(value);
        mirror.add(value);
      }
    }

    // Get sorted list of set of keys.
    JsonArray<String> keys = mirror.getKeys();
    keys.sort(new Comparator<String>() {
      @Override
      public int compare(String o1, String o2) {
        return o1.compareTo(o2);
      }
View Full Code Here

Examples of com.google.collide.json.client.JsoStringSet

    if (ignoreCase) {
      itemPrefix = itemPrefix.toLowerCase();
    }

    // A set used to avoid duplicates.
    JsoStringSet uniqueNames = JsoStringSet.create();

    // This array will be filled with proposals form different sources:
    // templates; visible names found by parser; matches from code graph.
    JsonArray<AutocompleteProposal> result = JsonCollections.createArray();

    // This also means previousContext == ""
    if (CompletionType.GLOBAL == context.getCompletionType()) {
      // Add templates.
      JsonArray<? extends TemplateProposal> templates = getTemplatesIndex().search(itemPrefix);
      result.addAll(templates);
      for (TemplateProposal template : templates.asIterable()) {
        uniqueNames.add(template.getName());
      }

      // Add visible names found by parser.
      JsonArray<String> localVariables = getLocalVariables(context.getParseResult());
      for (String localVariable : localVariables.asIterable()) {
        if (StringUtils.startsWith(itemPrefix, localVariable, ignoreCase)) {
          if (!uniqueNames.contains(localVariable)) {
            uniqueNames.add(localVariable);
            result.add(new CodeGraphProposal(localVariable, PathUtil.EMPTY_PATH, false));
          }
        }
      }
    }

    // Now use the knowledge about current scope and calculate possible
    // shortcuts in code graph.
    JsonStringSet prefixes = scopeTrieBuilder.calculateScopePrefixes(context, cursorPosition);
    // Let language-specific modifications.
    addShortcutsTo(context, prefixes);

    PrefixIndex<CodeGraphProposal> codeGraphTrie = scopeTrieBuilder.getCodeGraphTrie();
    JsonArray<AutocompleteProposal> codeProposals = JsonCollections.createArray();
    // We're iterate found shortcuts...
    for (String prefix : prefixes.getKeys().asIterable()) {
      JsonArray<? extends CodeGraphProposal> proposals = codeGraphTrie.search(prefix + itemPrefix);
      // Distill raw proposals.
      int prefixLength = prefix.length();
      for (CodeGraphProposal proposal : proposals.asIterable()) {
        // Take part of string between prefix and period.
        String proposalName = proposal.getName();
        int nameEndIndex = proposalName.length();
        int periodIndex = proposalName.indexOf('.', prefixLength);
        if (periodIndex != -1) {
          // TODO: Do we need this?
          nameEndIndex = periodIndex;
        }
        proposalName = proposalName.substring(prefixLength, nameEndIndex);

        if (!uniqueNames.contains(proposalName)) {
          uniqueNames.add(proposalName);
          codeProposals.add(
              new CodeGraphProposal(proposalName, proposal.getPath(), proposal.isFunction()));
        }
      }
    }
View Full Code Here

Examples of com.google.collide.json.client.JsoStringSet

    this.contextFile = contextFile;
    this.mode = mode;
  }

  public JsoStringSet calculateScopePrefixes(CompletionContext context, Position cursor) {
    JsoStringSet result = JsoStringSet.create();
    boolean isThisContext = context.isThisContext();
    Line line = cursor.getLine();

    if (!isThisContext) {
      result.add(context.getPreviousContext());
    }

    //PY specific.
    PyCodeScope pyScope = line.getTag(PyIndexUpdater.TAG_SCOPE);
    if (pyScope != null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.