Package org.sonar.duplications.block

Examples of org.sonar.duplications.block.Block


      int indexInFile = unit.getIndexInFile();
      int startLine = unit.getStartLine();
      int endLine = unit.getEndLine();

      // TODO Godin: in fact we could work directly with id instead of key - this will allow to decrease memory consumption
      Block block = Block.builder()
        .setResourceId(resourceKey)
        .setBlockHash(new ByteArray(hash))
        .setIndexInFile(indexInFile)
        .setLines(startLine, endLine)
        .build();

      // Group blocks by hash
      Collection<Block> sameHash = cache.get(block.getBlockHash());
      if (sameHash == null) {
        sameHash = Lists.newArrayList();
        cache.put(block.getBlockHash(), sameHash);
      }
      sameHash.add(block);
    }
  }
View Full Code Here


    CloneGroup.Builder builder = CloneGroup.builder().setLength(length);

    List<ClonePart> parts = Lists.newArrayListWithCapacity(count);
    for (int[] b : blockNumbers) {
      Block firstBlock = text.getBlock(b[0]);
      Block lastBlock = text.getBlock(b[1]);
      ClonePart part = new ClonePart(
          firstBlock.getResourceId(),
          firstBlock.getIndexInFile(),
          firstBlock.getStartLine(),
          lastBlock.getEndLine());

      // TODO Godin: maybe use FastStringComparator here ?
      if (originResourceId.equals(part.getResourceId())) {
        // part from origin
        if (origin == null) {
          origin = part;
          // To calculate length important to use the origin, because otherwise block may come from DB without required data
          builder.setLengthInUnits(lastBlock.getEndUnit() - firstBlock.getStartUnit() + 1);
        } else if (part.getUnitStart() < origin.getUnitStart()) {
          origin = part;
        }
      }
View Full Code Here

  protected static Block[] newBlocks(String resourceId, String hashes) {
    List<Block> result = Lists.newArrayList();
    int indexInFile = 0;
    for (int i = 0; i < hashes.length(); i += 2) {
      Block block = newBlock(resourceId, new ByteArray("0" + hashes.charAt(i)), indexInFile);
      result.add(block);
      indexInFile++;
    }
    return result.toArray(new Block[result.size()]);
  }
View Full Code Here

    TokensLine line3 = new TokensLine(20, 29, 3, Character.toString((char) 3));

    List<Block> blocks = new PmdBlockChunker(2).chunk("resourceId", Arrays.asList(line1, line2, line3));
    assertThat(blocks.size(), is(2));

    Block block = blocks.get(0);
    // assertThat(block.getLengthInUnits(), is(11));
    assertThat(block.getStartLine(), is(1));
    assertThat(block.getEndLine(), is(2));
    assertThat(block.getBlockHash(), is(new ByteArray(1L * 31 + 2)));

    block = blocks.get(1);
    // assertThat(block.getLengthInUnits(), is(33));
    assertThat(block.getStartLine(), is(2));
    assertThat(block.getEndLine(), is(3));
    assertThat(block.getBlockHash(), is(new ByteArray(2L * 31 + 3)));
  }
View Full Code Here

      int firstLineNumber = blockData[offset++];
      int lastLineNumber = blockData[offset++];
      int startUnit = blockData[offset++];
      int endUnit = blockData[offset];

      Block block = blockBuilder
          .setResourceId(resourceId)
          .setBlockHash(new ByteArray(hash))
          .setIndexInFile(indexInFile)
          .setLines(firstLineNumber, lastLineNumber)
          .setUnit(startUnit, endUnit)
View Full Code Here

      int firstLineNumber = blockData[offset++];
      int lastLineNumber = blockData[offset++];
      int startUnit = blockData[offset++];
      int endUnit = blockData[offset];

      Block block = blockBuilder
          .setResourceId(resourceId)
          .setBlockHash(sequenceHash)
          .setIndexInFile(indexInFile)
          .setLines(firstLineNumber, lastLineNumber)
          .setUnit(startUnit, endUnit)
View Full Code Here

      TokensLine firstFragment = fragmentsArr[first];
      TokensLine lastFragment = fragmentsArr[last];
      // add last statement to hash
      hash = hash * PRIME_BASE + lastFragment.getHashCode();
      // create block
      Block block = blockBuilder
        .setBlockHash(new ByteArray(hash))
        .setIndexInFile(first)
        .setLines(firstFragment.getStartLine(), lastFragment.getEndLine())
        .setUnit(firstFragment.getStartUnit(), lastFragment.getEndUnit())
        .build();
View Full Code Here

    List<Block> list1 = group1.blocks;
    List<Block> list2 = group2.blocks;
    int i = 0;
    int j = 0;
    while (i < list1.size() && j < list2.size()) {
      Block block1 = list1.get(i);
      Block block2 = list2.get(j);
      int c = RESOURCE_ID_COMPARATOR.compare(block1.getResourceId(), block2.getResourceId());
      if (c > 0) {
        j++;
        continue;
      }
      if (c < 0) {
        i++;
        continue;
      }
      if (c == 0) {
        c = block1.getIndexInFile() + 1 - block2.getIndexInFile();
      }
      if (c == 0) {
        // list1[i] == list2[j]
        i++;
        j++;
View Full Code Here

    List<Block> list1 = group1.blocks;
    List<Block> list2 = group2.blocks;
    int i = 0;
    int j = 0;
    while (i < list1.size() && j < list2.size()) {
      Block block1 = list1.get(i);
      Block block2 = list2.get(j);
      int c = RESOURCE_ID_COMPARATOR.compare(block1.getResourceId(), block2.getResourceId());
      if (c != 0) {
        j++;
        continue;
      }
      if (c == 0) {
        c = block1.getIndexInFile() - indexCorrection - block2.getIndexInFile();
      }
      if (c < 0) {
        // list1[i] < list2[j]
        break;
      }
View Full Code Here

    List<Block> beginBlocks = beginGroup.blocks;
    List<Block> endBlocks = endGroup.blocks;
    int i = 0;
    int j = 0;
    while (i < beginBlocks.size() && j < endBlocks.size()) {
      Block beginBlock = beginBlocks.get(i);
      Block endBlock = endBlocks.get(j);
      int c = RESOURCE_ID_COMPARATOR.compare(beginBlock.getResourceId(), endBlock.getResourceId());
      if (c == 0) {
        c = beginBlock.getIndexInFile() + len - 1 - endBlock.getIndexInFile();
      }
      if (c == 0) {
        result.add(new Block[] { beginBlock, endBlock });
        i++;
        j++;
View Full Code Here

TOP

Related Classes of org.sonar.duplications.block.Block

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.