org.sonar.duplications.block.Block.getIndexInFile()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.sonar.duplications.block.Block.getIndexInFile()方法的一些代码示例,展示了Block.getIndexInFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getIndexInFile()方法的具体详情如下:
包路径:org.sonar.duplications.block.Block
类名称:Block
方法名:getIndexInFile

Block.getIndexInFile介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Override
public int compare(Block b1, Block b2) {
 int c = RESOURCE_ID_COMPARATOR.compare(b1.getResourceId(), b2.getResourceId());
 if (c == 0) {
  return b1.getIndexInFile() - b2.getIndexInFile();
 }
 return c;
}

代码示例来源:origin: SonarSource/sonarqube

private static List<Block[]> pairs(BlocksGroup beginGroup, BlocksGroup endGroup, int len) {
 List<Block[]> result = new ArrayList<>();
 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++;
  }
  if (c > 0) {
   j++;
  }
  if (c < 0) {
   i++;
  }
 }
 return result;
}

代码示例来源:origin: SonarSource/sonarqube

private static Map<Integer, Block> blocksByIndexInFile(List<Block> blocks) {
 Map<Integer, Block> blocksByIndexInFile = new HashMap<>();
 for (Block block : blocks) {
  blocksByIndexInFile.put(block.getIndexInFile(), block);
 }
 return blocksByIndexInFile;
}

代码示例来源:origin: SonarSource/sonarqube

private static TextSet createTextSet(Collection<Block> fileBlocks, Map<String, List<Block>> fromIndex) {
 TextSet.Builder textSetBuilder = TextSet.builder();
 // TODO Godin: maybe we can reduce size of tree and so memory consumption by removing non-repeatable blocks
 List<Block> sortedFileBlocks = new ArrayList<>(fileBlocks);
 Collections.sort(sortedFileBlocks, BLOCK_COMPARATOR);
 textSetBuilder.add(sortedFileBlocks);
 for (List<Block> list : fromIndex.values()) {
  Collections.sort(list, BLOCK_COMPARATOR);
  int i = 0;
  while (i < list.size()) {
   int j = i + 1;
   while ((j < list.size()) && (list.get(j).getIndexInFile() == list.get(j - 1).getIndexInFile() + 1)) {
    j++;
   }
   textSetBuilder.add(list.subList(i, j));
   i = j;
  }
 }
 return textSetBuilder.build();
}

代码示例来源:origin: SonarSource/sonarqube

continue;
c = block1.getIndexInFile() - indexCorrection - block2.getIndexInFile();
if (c < 0) {

代码示例来源:origin: SonarSource/sonarqube

c = block1.getIndexInFile() + 1 - block2.getIndexInFile();

代码示例来源:origin: SonarSource/sonarqube

int i = fileBlock.getIndexInFile() + 1;

代码示例来源:origin: SonarSource/sonarqube

private void reportClones(BlocksGroup beginGroup, BlocksGroup endGroup, int cloneLength) {
 List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength);
 ClonePart origin = null;
 List<ClonePart> parts = new ArrayList<>();
 for (int i = 0; i < pairs.size(); i++) {
  Block[] pair = pairs.get(i);
  Block firstBlock = pair[0];
  Block lastBlock = pair[1];
  ClonePart part = new ClonePart(firstBlock.getResourceId(),
   firstBlock.getIndexInFile(),
   firstBlock.getStartLine(),
   lastBlock.getEndLine());
  if (originResourceId.equals(part.getResourceId())) {
   if (origin == null || part.getUnitStart() < origin.getUnitStart()) {
    origin = part;
   }
  }
  parts.add(part);
 }
 filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build());
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * Given: 5 statements, block size is 3
 * Expected: 4 blocks with correct index and with line numbers
 */
@Test
public void shouldBuildBlocksFromStatements() {
 List<Statement> statements = createStatementsFromStrings("1", "2", "3", "4", "5", "6");
 BlockChunker chunker = createChunkerWithBlockSize(3);
 List<Block> blocks = chunker.chunk("resource", statements);
 assertThat(blocks.size(), is(4));
 assertThat(blocks.get(0).getIndexInFile(), is(0));
 assertThat(blocks.get(0).getStartLine(), is(0));
 assertThat(blocks.get(0).getEndLine(), is(2));
 assertThat(blocks.get(1).getIndexInFile(), is(1));
 assertThat(blocks.get(1).getStartLine(), is(1));
 assertThat(blocks.get(1).getEndLine(), is(3));
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * {@inheritDoc}
 * <p>
 * <strong>Note that this implementation allows insertion of two blocks with same index for one resource.</strong>
 * </p>
 */
@Override
public void insert(Block block) {
 sorted = false;
 ensureCapacity();
 resourceIds[size] = block.getResourceId();
 int[] hash = block.getBlockHash().toIntArray();
 if (hash.length != hashInts) {
  throw new IllegalArgumentException("Expected " + hashInts + " ints in hash, but got " + hash.length);
 }
 int offset = size * blockInts;
 for (int i = 0; i < hashInts; i++) {
  blockData[offset++] = hash[i];
 }
 blockData[offset++] = block.getIndexInFile();
 blockData[offset++] = block.getStartLine();
 blockData[offset++] = block.getEndLine();
 blockData[offset++] = block.getStartUnit();
 blockData[offset] = block.getEndUnit();
 size++;
}

代码示例来源:origin: SonarSource/sonarqube

ClonePart part = new ClonePart(
 firstBlock.getResourceId(),
 firstBlock.getIndexInFile(),
 firstBlock.getStartLine(),
 lastBlock.getEndLine());

代码示例来源:origin: SonarSource/sonarqube

if (first != null && first.getIndexInFile() == j - 2) {

代码示例来源:origin: SonarSource/sonarqube

@Test
public void testBuilder() {
 ByteArray hash = new ByteArray(1);
 Block block = Block.builder()
   .setResourceId("resource")
   .setBlockHash(hash)
   .setIndexInFile(1)
   .setLines(2, 3)
   .setUnit(4, 5)
   .build();
 assertThat(block.getResourceId(), is("resource"));
 assertThat(block.getBlockHash(), sameInstance(hash));
 assertThat(block.getIndexInFile(), is(1));
 assertThat(block.getStartLine(), is(2));
 assertThat(block.getEndLine(), is(3));
 assertThat(block.getStartUnit(), is(4));
 assertThat(block.getEndUnit(), is(5));
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

@Override
 public int compare(Block o1, Block o2) {
  return o1.getIndexInFile() - o2.getIndexInFile();
 }
};

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

@Override
public int compare(Block b1, Block b2) {
 int c = RESOURCE_ID_COMPARATOR.compare(b1.getResourceId(), b2.getResourceId());
 if (c == 0) {
  return b1.getIndexInFile() - b2.getIndexInFile();
 }
 return c;
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

private static List<Block[]> pairs(BlocksGroup beginGroup, BlocksGroup endGroup, int len) {
 List<Block[]> result = Lists.newArrayList();
 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++;
  }
  if (c > 0) {
   j++;
  }
  if (c < 0) {
   i++;
  }
 }
 return result;
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

private static TextSet createTextSet(Collection<Block> fileBlocks, Map<String, List<Block>> fromIndex) {
 TextSet.Builder textSetBuilder = TextSet.builder();
 // TODO Godin: maybe we can reduce size of tree and so memory consumption by removing non-repeatable blocks
 List<Block> sortedFileBlocks = Lists.newArrayList(fileBlocks);
 Collections.sort(sortedFileBlocks, BLOCK_COMPARATOR);
 textSetBuilder.add(sortedFileBlocks);
 for (List<Block> list : fromIndex.values()) {
  Collections.sort(list, BLOCK_COMPARATOR);
  int i = 0;
  while (i < list.size()) {
   int j = i + 1;
   while ((j < list.size()) && (list.get(j).getIndexInFile() == list.get(j - 1).getIndexInFile() + 1)) {
    j++;
   }
   textSetBuilder.add(list.subList(i, j));
   i = j;
  }
 }
 return textSetBuilder.build();
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

public void insert(InputFile inputFile, Collection<Block> blocks) {
 int resourceSnapshotId = getSnapshotIdFor(inputFile);
 // TODO Godin: maybe remove conversion of blocks to units?
 List<DuplicationUnitDto> units = Lists.newArrayList();
 for (Block block : blocks) {
  DuplicationUnitDto unit = new DuplicationUnitDto(
   currentProjectSnapshotId,
   resourceSnapshotId,
   block.getBlockHash().toString(),
   block.getIndexInFile(),
   block.getStartLine(),
   block.getEndLine());
  units.add(unit);
 }
 dao.insert(units);
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

private void reportClones(BlocksGroup beginGroup, BlocksGroup endGroup, int cloneLength) {
 List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength);
 ClonePart origin = null;
 List<ClonePart> parts = Lists.newArrayList();
 for (int i = 0; i < pairs.size(); i++) {
  Block[] pair = pairs.get(i);
  Block firstBlock = pair[0];
  Block lastBlock = pair[1];
  ClonePart part = new ClonePart(firstBlock.getResourceId(),
    firstBlock.getIndexInFile(),
    firstBlock.getStartLine(),
    lastBlock.getEndLine());
  if (originResourceId.equals(part.getResourceId())) {
   if (origin == null) {
    origin = part;
   } else if (part.getUnitStart() < origin.getUnitStart()) {
    origin = part;
   }
  }
  parts.add(part);
 }
 filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build());
}

代码示例来源:origin: org.codehaus.sonar/sonar-duplications

/**
 * {@inheritDoc}
 * <p>
 * <strong>Note that this implementation allows insertion of two blocks with same index for one resource.</strong>
 * </p>
 */
@Override
public void insert(Block block) {
 sorted = false;
 ensureCapacity();
 resourceIds[size] = block.getResourceId();
 int[] hash = block.getBlockHash().toIntArray();
 if (hash.length != hashInts) {
  throw new IllegalArgumentException("Expected " + hashInts + " ints in hash, but got " + hash.length);
 }
 int offset = size * blockInts;
 for (int i = 0; i < hashInts; i++) {
  blockData[offset++] = hash[i];
 }
 blockData[offset++] = block.getIndexInFile();
 blockData[offset++] = block.getStartLine();
 blockData[offset++] = block.getEndLine();
 blockData[offset++] = block.getStartUnit();
 blockData[offset] = block.getEndUnit();
 size++;
}

相关文章