Package com.google.collide.dto

Examples of com.google.collide.dto.CodeBlock


    JsonStringSet visited = JsonCollections.createStringSet();

    while (!linkSourceCandidates.isEmpty()) {
      JsonArray<CodeGraphProposalImpl> newCandidates = JsonCollections.createArray();
      for (CodeGraphProposalImpl candidate : linkSourceCandidates.asIterable()) {
        CodeBlock codeBlock = candidate.codeBlock;

        JsonArray<CodeGraphProposalImpl> zeroBoundary = JsonCollections.createArray();
        JsonArray<CodeGraphProposalImpl> epsilonBoundary = JsonCollections.createArray();
        createBoundary(codeBlock, candidate.fileData, zeroBoundary, epsilonBoundary, visited);

        String linkAccessPrefix = candidate.getName();
        if (linkAccessPrefix == null) {
          linkAccessPrefix = "";
        }
        if (!StringUtils.isNullOrEmpty(linkAccessPrefix)) {
          linkAccessPrefix += ".";
        }

        for (CodeGraphProposalImpl zeroNeighbor : zeroBoundary.asIterable()) {
          searchTree(query, linkAccessPrefix, zeroNeighbor.codeBlock, zeroNeighbor.fileData,
              false, newCandidates, result);
        }

        for (CodeGraphProposalImpl epsilonNeighbor : epsilonBoundary.asIterable()) {
          String epsilonAccessPrefix = linkAccessPrefix;
          CodeBlock targetCodeBlock = epsilonNeighbor.codeBlock;
          if (targetCodeBlock.getBlockType() == CodeBlock.Type.VALUE_FILE) {
            epsilonAccessPrefix += truncateExtension(targetCodeBlock.getName());
          } else {
            epsilonAccessPrefix += targetCodeBlock.getName();
          }
          epsilonAccessPrefix += ".";
          searchTree(query, epsilonAccessPrefix, targetCodeBlock, epsilonNeighbor.fileData,
              false, newCandidates, result);
        }
View Full Code Here


      JsonArray<CodeGraphProposalImpl> matched) {
    String lcQuery = query.toLowerCase();
    String rootFqname = fileData.getFqname(root);
    JsonArray<CodeBlock> children = root.getChildren();
    for (int i = 0; i < children.size(); i++) {
      CodeBlock child = children.get(i);
      if (fileData.getFqname(child) == null) {
        // It is just a side-effect for performance reasons. Since we're traversing
        // the tree anyway, why don't we fill in fqnames table at the same time?
        String childFqname = (rootFqname == null)
            ? child.getName() : rootFqname + "." + child.getName();
        fileData.putFqname(child, childFqname);
      }

      final String childAccessPrefix = accessPrefix + child.getName();
      final String lcChildAccessPrefix = childAccessPrefix.toLowerCase();
      CodeGraphProposalImpl childProposal = new CodeGraphProposalImpl(
          child, childAccessPrefix, fileData);

      if (strictMatch && lcChildAccessPrefix.equals(lcQuery)) {
View Full Code Here

      CodeBlockAssociation link = queue.splice(0, 1).pop();
      FileIndex targetFileData = fileIdToData.get(link.getTargetFileId());
      if (targetFileData == null) {
        continue;
      }
      CodeBlock targetCodeBlock = targetFileData.findCodeBlock(link.getTargetLocalId());
      if (targetCodeBlock == null) {
        continue;
      }

      final String targetFqname = targetFileData.getFqname(targetCodeBlock);
      if (targetFqname == null) {
        if (targetCodeBlock.getBlockType() != CodeBlock.Type.VALUE_FILE) {
          throw new IllegalStateException(
              "type=" + CodeBlock.Type.valueOf(targetCodeBlock.getBlockType()));
        }
        continue;
      }

      String fullTargetId = getFullId(targetFileData, targetCodeBlock);
View Full Code Here

      return result == null ? EMPTY_LINKS_ARRAY : result;
    }

    CodeBlock findCodeBlock(String localId) {
      String key = localId == null ? "" : localId;
      CodeBlock result = getCodeBlock(key);
      if (result != null) {
        return result;
      }
      return indexUntil(key);
    }
View Full Code Here

        if (!StringUtils.isNullOrEmpty(prefix)) {
          prefix = prefix + ".";
        }

        for (int i = 0; i < head.codeBlocks.size(); i++) {
          CodeBlock codeBlock = head.codeBlocks.get(i);
          String key = getMapKey(codeBlock);
          codeBlocks.put(key, codeBlock);
          String fqname = appendFqname(prefix, codeBlock);
          putFqname(codeBlock, fqname);
          indexQueue.add(new IndexQueueItem(fqname, codeBlock.getChildren()));
        }
        CodeBlock result = codeBlocks.get(searchKey);
        if (result != null) {
          return result;
        }
      }
      return null;
View Full Code Here

   * as a child to the given block according to the given path.
   */
  public static CodeBlock createCodeBlock(CodeBlock fileBlock, String id, String qname,
      CodeBlock.Type type, int startLine, int startColumn, int endLine, int endColumn) {
    JsonArray<String> path = StringUtils.split(qname, ".");
    CodeBlock result = createCodeBlock(id, path.get(path.size() - 1), type, startLine, startColumn,
        endLine, endColumn);
    CodeBlock container;
    if (path.size() > 1) {
      JsonArray<String> parentPath = path.copy();
      parentPath.remove(parentPath.size() - 1);
      container = GrokUtils.getOrCreateCodeBlock(fileBlock, parentPath, GrokUtils.NO_MISSING_CHILD);
      if (container == null) {
        throw new RuntimeException("Can't create code block in file=" + fileBlock.getName()
            + " by qname=" + qname + ". Create all containers first");
      }
    } else {
      container = fileBlock;
    }
    container.getChildren().add(result);
    return result;
  }
View Full Code Here

    // Can't calculate scope or matching codeBlock or it is root scope.
    if (scope == null || scope == contextFile.getRootScope()) {
      return result;
    }

    CodeBlock codeBlock = scope.getCodeBlock();
    JsonArray<String> prefix = buildPrefix(codeBlock);
    // Add prefixes corresponding to outer scopes.
    if (isThisContext && Type.VALUE_FUNCTION == codeBlock.getBlockType() && prefix.size() > 1) {
      addThisPrefixes(result, prefix);
    } else {
      addLexicalPrefixes(result, prefix, context.getPreviousContext());
    }
    return result;
View Full Code Here

   * <p>Given block name is the last item in resulting sequence.
   */
  private JsonArray<String> buildPrefix(@Nonnull CodeBlock codeBlock) {
    Preconditions.checkNotNull(codeBlock);

    CodeBlock current = codeBlock;
    JsonArray<String> prefix = JsonCollections.createArray();
    while (current != null && Type.VALUE_FILE != current.getBlockType()) {
      prefix.add(current.getName());
      current = contextFile.getReferences().getParent(current);
    }
    prefix.reverse();

    return prefix;
View Full Code Here

    return prefix;
  }

  public void setCodeGraph(CodeGraph codeGraph) {
    CodeBlock contextFileCodeBlock = GrokUtils.findFileCodeBlock(codeGraph,
        contextFile.getFilePath().getPathString());
    contextFile.setRootCodeBlock(contextFileCodeBlock);
    externalTrie = new CodeGraphPrefixIndex(codeGraph, mode, contextFile.getFilePath());
  }
View Full Code Here

TOP

Related Classes of com.google.collide.dto.CodeBlock

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.