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

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

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

Block.builder介绍

暂无

代码示例

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

hash = hash * PRIME_BASE + statementsArr[last].getValue().hashCode();
Block.Builder blockBuilder = Block.builder().setResourceId(resourceId);
for (; last < statementsArr.length; last++, first++) {
 Statement firstStatement = statementsArr[first];

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

hash = hash * PRIME_BASE + fragmentsArr[last].getHashCode();
Block.Builder blockBuilder = Block.builder().setResourceId(resourceId);
for (; last < fragmentsArr.length; last++, first++) {
 TokensLine firstFragment = fragmentsArr[first];

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

@Override
 public Block apply(@Nonnull DuplicationUnitDto dto) {
  // Note that the dto doesn't contains start/end token indexes
  return Block.builder()
   .setResourceId(dto.getComponentKey())
   .setBlockHash(new ByteArray(dto.getHash()))
   .setIndexInFile(dto.getIndexInFile())
   .setLines(dto.getStartLine(), dto.getEndLine())
   .build();
 }
}

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

@Override
 public Block apply(@Nonnull CpdTextBlock duplicationBlock) {
  Block block = Block.builder()
   .setResourceId(fileKey)
   .setBlockHash(new ByteArray(duplicationBlock.getHash()))
   .setIndexInFile(indexInFile)
   .setLines(duplicationBlock.getStartLine(), duplicationBlock.getEndLine())
   .setUnit(duplicationBlock.getStartTokenIndex(), duplicationBlock.getEndTokenIndex())
   .build();
  indexInFile++;
  return block;
 }
}

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

@Test
public void should_timeout() {
 Block block = Block.builder()
  .setBlockHash(new ByteArray("AAAABBBBCCCC"))
  .setResourceId(batchComponent1.key())
  .build();
 index.insert(batchComponent1, Collections.singletonList(block));
 when(executorService.submit(ArgumentMatchers.any(Callable.class))).thenReturn(new CompletableFuture());
 executor.execute(1);
 readDuplications(0);
 assertThat(logTester.logs(LoggerLevel.WARN))
  .usingElementComparator((l, r) -> l.matches(r) ? 0 : 1)
  .containsOnly(
   "Timeout during detection of duplications for .*Foo.php");
}

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

@Test
public void should_ignore_missing_component() {
 Block block = Block.builder()
  .setBlockHash(new ByteArray("AAAABBBBCCCC"))
  .setResourceId("unknown")
  .build();
 index.insert(batchComponent1, Collections.singletonList(block));
 executor.execute();
 verify(executorService).shutdown();
 verifyNoMoreInteractions(executorService);
 readDuplications(batchComponent1, 0);
 assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Resource not found in component store: unknown. Skipping CPD computation for it");
}

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

/**
 * {@link BlocksGroup} uses only resourceId and index from block, thus we can simplify testing.
 */
private static Block newBlock(String resourceId, int indexInFile) {
 return Block.builder()
   .setResourceId(resourceId)
   .setIndexInFile(indexInFile)
   .setLines(indexInFile, indexInFile)
   .build();
}

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

/**
 * To simplify testing we assume that each block starts from a new line and contains {@link #LINES_PER_BLOCK} lines,
 * so we can simply use index and hash.
 */
protected static Block newBlock(String resourceId, ByteArray hash, int index) {
 return Block.builder()
  .setResourceId(resourceId)
  .setBlockHash(hash)
  .setIndexInFile(index)
  .setLines(index, index + LINES_PER_BLOCK)
  .build();
}

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

private static Block newBlock(String resourceId, long hash) {
 return Block.builder()
   .setResourceId(resourceId)
   .setBlockHash(new ByteArray(hash))
   .setIndexInFile(1)
   .setLines(1, 2)
   .build();
}

代码示例来源: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: SonarSource/sonarqube

public void same_lines_but_different_indexes() {
 CloneIndex cloneIndex = createIndex();
 Block.Builder block = Block.builder()
  .setResourceId("a")
  .setLines(0, 1);

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

hash = hash * PRIME_BASE + statementsArr[last].getValue().hashCode();
Block.Builder blockBuilder = Block.builder().setResourceId(resourceId);
for (; last < statementsArr.length; last++, first++) {
 Statement firstStatement = statementsArr[first];

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

hash = hash * PRIME_BASE + fragmentsArr[last].getHashCode();
Block.Builder blockBuilder = Block.builder().setResourceId(resourceId);
for (; last < fragmentsArr.length; last++, first++) {
 TokensLine firstFragment = fragmentsArr[first];

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

public void prepareCache(InputFile inputFile) {
 int resourceSnapshotId = getSnapshotIdFor(inputFile);
 List<DuplicationUnitDto> units = dao.selectCandidates(resourceSnapshotId, lastSnapshotId, languageKey);
 cache.clear();
 // TODO Godin: maybe remove conversion of units to blocks?
 for (DuplicationUnitDto unit : units) {
  String hash = unit.getHash();
  String resourceKey = unit.getResourceKey();
  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);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

@Override
 public Block apply(@Nonnull DuplicationUnitDto dto) {
  // Note that the dto doesn't contains start/end token indexes
  return Block.builder()
   .setResourceId(dto.getComponentKey())
   .setBlockHash(new ByteArray(dto.getHash()))
   .setIndexInFile(dto.getIndexInFile())
   .setLines(dto.getStartLine(), dto.getEndLine())
   .build();
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

@Override
 public Block apply(@Nonnull CpdTextBlock duplicationBlock) {
  Block block = Block.builder()
   .setResourceId(fileKey)
   .setBlockHash(new ByteArray(duplicationBlock.getHash()))
   .setIndexInFile(indexInFile)
   .setLines(duplicationBlock.getStartLine(), duplicationBlock.getEndLine())
   .setUnit(duplicationBlock.getStartTokenIndex(), duplicationBlock.getEndTokenIndex())
   .build();
  indexInFile++;
  return block;
 }
}

相关文章