• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FileLinesContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.sonar.api.measures.FileLinesContext的典型用法代码示例。如果您正苦于以下问题:Java FileLinesContext类的具体用法?Java FileLinesContext怎么用?Java FileLinesContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileLinesContext类属于org.sonar.api.measures包,在下文中一共展示了FileLinesContext类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: leaveFile

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Override
public void leaveFile(AstNode astNode) {
  InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().is(getContext().getFile()));
  if (inputFile == null) {
    throw new IllegalStateException("InputFile is null, but it should not be.");
  }
  FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile);

  int fileLength = getContext().peekSourceCode().getInt(PuppetMetric.LINES);
  for (int line = 1; line <= fileLength; line++) {
    fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0);
    fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0);
  }
  fileLinesContext.save();

  linesOfCode.clear();
  linesOfComments.clear();
}
 
开发者ID:iwarapter,项目名称:sonar-puppet,代码行数:19,代码来源:FileLinesVisitor.java


示例2: setUp

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  WebRulesDefinition rulesDefinition = new WebRulesDefinition();
  RulesDefinition.Context context = new RulesDefinition.Context();
  rulesDefinition.define(context);
  RulesDefinition.Repository repository = context.repository(WebRulesDefinition.REPOSITORY_KEY);

  List<NewActiveRule> ar = new ArrayList<>();
  for (RulesDefinition.Rule rule : repository.rules()) {
    ar.add(new ActiveRulesBuilder().create(RuleKey.of(WebRulesDefinition.REPOSITORY_KEY, rule.key())));
  }
  ActiveRules activeRules = new DefaultActiveRules(ar);

  CheckFactory checkFactory = new CheckFactory(activeRules);
  FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
  when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
  sensor = new WebSensor(new NoSonarFilter(), fileLinesContextFactory, checkFactory);
  tester = SensorContextTester.create(TEST_DIR);
}
 
开发者ID:SonarSource,项目名称:sonar-web,代码行数:20,代码来源:WebSensorTest.java


示例3: saveLineLevelMeasures

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
private void saveLineLevelMeasures(File sonarFile, WebSourceCode webSourceCode) {
  FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(sonarFile);
  Set<Integer> linesOfCode = webSourceCode.getDetailedLinesOfCode();
  Set<Integer> linesOfComments = webSourceCode.getDetailedLinesOfComments();

  for (int line = 1; line <= webSourceCode.getMeasure(CoreMetrics.LINES).getIntValue(); line++) {
    fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0);
    fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0);
  }
  fileLinesContext.save();
}
 
开发者ID:Asqatasun,项目名称:Asqatasun-Sonar-Plugin,代码行数:12,代码来源:TanaguruSensor.java


示例4: leaveFile

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Override
public void leaveFile(AstNode astNode) {
  File sonarFile = File.fromIOFile(getContext().getFile(), project);
  FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(sonarFile);

  int fileLength = getContext().peekSourceCode().getInt(PlSQLMetric.LINES);
  for (int line = 1; line <= fileLength; line++) {
    fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0);
    fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0);
  }
  fileLinesContext.save();

  linesOfCode.clear();
  linesOfComments.clear();
}
 
开发者ID:Ne0s,项目名称:sonar-plsql,代码行数:16,代码来源:FileLinesVisitor.java


示例5: saveMeasures

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
private static void saveMeasures(XmlFile xmlFile, LineCountData data, FileLinesContext fileLinesContext, SensorContext context) {
  data.updateAccordingTo(xmlFile.getLineDelta());

  for (int line = 1; line <= data.linesNumber(); line++) {
    fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, data.linesOfCodeLines().contains(line) ? 1 : 0);
    fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, data.effectiveCommentLines().contains(line) ? 1 : 0);
  }
  fileLinesContext.save();

  saveMeasure(context, xmlFile.getInputFile(), CoreMetrics.COMMENT_LINES, data.effectiveCommentLines().size());
  saveMeasure(context, xmlFile.getInputFile(), CoreMetrics.NCLOC, data.linesOfCodeLines().size());
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:13,代码来源:LineCounter.java


示例6: init

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
private void init(boolean activateParsingErrorCheck) throws Exception {
  File moduleBaseDir = new File("src/test/resources");
  context = SensorContextTester.create(moduleBaseDir);

  fs = new DefaultFileSystem(moduleBaseDir);
  fs.setWorkDir(temporaryFolder.newFolder("temp"));

  ActiveRules activeRules = null;
  if (activateParsingErrorCheck) {
    activeRules = new ActiveRulesBuilder()
      .create(ruleKey)
      .activate()
      .create(parsingErrorCheckRuleKey)
      .setInternalKey(parsingErrorCheckKey)
      .activate()
      .build();
  } else {
    activeRules = new ActiveRulesBuilder()
      .create(ruleKey)
      .activate()
      .build();
  }
  CheckFactory checkFactory = new CheckFactory(activeRules);

  FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
  when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class));

  sensor = new XmlSensor(fs, checkFactory, fileLinesContextFactory);
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:30,代码来源:XmlSensorTest.java


示例7: should_analyze_file_with_its_own_encoding

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Test
public void should_analyze_file_with_its_own_encoding() throws IOException {
  Charset fileSystemCharset = StandardCharsets.UTF_8;
  Charset fileCharset = StandardCharsets.UTF_16;

  Path moduleBaseDir = temporaryFolder.newFolder().toPath();
  SensorContextTester context = SensorContextTester.create(moduleBaseDir);

  DefaultFileSystem fileSystem = new DefaultFileSystem(moduleBaseDir);
  fileSystem.setEncoding(fileSystemCharset);
  context.setFileSystem(fileSystem);
  String filename = "utf16.xml";
  try (BufferedWriter writer = Files.newBufferedWriter(moduleBaseDir.resolve(filename), fileCharset)) {
    writer.write("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>\n");
    writer.write("<tag></tag>");
  }

  String modulekey = "modulekey";
  DefaultInputFile defaultInputFile = new DefaultInputFile(modulekey, filename)
    .setModuleBaseDir(moduleBaseDir)
    .setType(InputFile.Type.MAIN)
    .setLanguage(Xml.KEY)
    .setCharset(fileCharset);
  defaultInputFile.initMetadata(new FileMetadata().readMetadata(defaultInputFile.file(), fileCharset));
  fileSystem.add(defaultInputFile);

  ActiveRules activeRules = new ActiveRulesBuilder()
    .create(ruleKey)
    .activate()
    .build();
  CheckFactory checkFactory = new CheckFactory(activeRules);

  FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
  when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
  sensor = new XmlSensor(fileSystem, checkFactory, fileLinesContextFactory);
  sensor.analyse(context);

  String componentKey = modulekey + ":" + filename;
  assertThat(context.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(2);
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:41,代码来源:XmlSensorTest.java


示例8: leaveFile

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Override
public void leaveFile(AstNode astNode) {
  FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(
    fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(getContext().getFile().getAbsolutePath())));

  int fileLength = getContext().peekSourceCode().getInt(LuaMetric.LINES);
  for (int line = 1; line <= fileLength; line++) {
    fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0);
    fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0);
  }
  fileLinesContext.save();

  linesOfCode.clear();
  linesOfComments.clear();
}
 
开发者ID:SonarQubeCommunity,项目名称:sonar-lua,代码行数:16,代码来源:FileLinesVisitor.java


示例9: setUp

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  NewActiveRule ar = new ActiveRulesBuilder().create(RuleKey.of("lua", "S1125")).setSeverity("BLOCKER");
  ActiveRules activeRules = new DefaultActiveRules(Collections.singletonList(ar));
  CheckFactory checkFactory = new CheckFactory(activeRules);
  FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
  when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
  sensor = new LuaSquidSensor(checkFactory, fileLinesContextFactory);
  tester = SensorContextTester.create(TEST_DIR);
}
 
开发者ID:SonarQubeCommunity,项目名称:sonar-lua,代码行数:11,代码来源:LuaSquidSensorTest.java


示例10: createFileLinesContextFactory

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
private FileLinesContextFactory createFileLinesContextFactory() {
    FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
    FileLinesContext fileLinesContext = mock(FileLinesContext.class);
    when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
    return fileLinesContextFactory;
}
 
开发者ID:antowski,项目名称:sonar-onec,代码行数:7,代码来源:OneCSensorTest.java


示例11: createFor

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Override
public FileLinesContext createFor(InputFile inputFile) {
  return new NoOpFileLinesContext();
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:5,代码来源:NoOpFileLinesContextFactory.java


示例12: test_metrics_get_imported

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Test
public void test_metrics_get_imported() throws FileNotFoundException {
  SensorContextTester tester = SensorContextTester.create(TEST_DATA_DIR);

  DefaultInputFile inputFile = new DefaultInputFile("dummyKey", TEST_FILE_PATH)
    .initMetadata(new FileMetadata().readMetadata(new FileReader(TEST_FILE)));
  tester.fileSystem().add(inputFile);

  File protobuf = new File(TEST_DATA_DIR, METRICS_OUTPUT_PROTOBUF_NAME);
  assertThat(protobuf.isFile()).withFailMessage("no such file: " + protobuf).isTrue();

  FileLinesContext fileLinesContext = mock(FileLinesContext.class);
  FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
  when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);

  NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);

  new MetricsImporter(tester, fileLinesContextFactory, noSonarFilter, f -> true).accept(protobuf.toPath());

  Collection<Measure> measures = tester.measures(inputFile.key());
  assertThat(measures).hasSize(12);

  // TODO change test data so that all metrics have different expected values

  assertThat(measures).extracting("metric", "value")
    .containsOnly(
      Tuple.tuple(CoreMetrics.CLASSES, 4),
      Tuple.tuple(CoreMetrics.STATEMENTS, 6),
      Tuple.tuple(CoreMetrics.FUNCTIONS, 3),
      Tuple.tuple(CoreMetrics.PUBLIC_API, 2),
      Tuple.tuple(CoreMetrics.PUBLIC_UNDOCUMENTED_API, 1),
      Tuple.tuple(CoreMetrics.COMPLEXITY, 7),
      Tuple.tuple(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, "0=0;5=1;10=0;20=0;30=0;60=0;90=0"),
      Tuple.tuple(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, "1=2;2=0;4=1;6=0;8=0;10=0;12=0"),
      Tuple.tuple(CoreMetrics.COMPLEXITY_IN_CLASSES, 7),
      Tuple.tuple(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, 7),
      Tuple.tuple(CoreMetrics.COMMENT_LINES, 12),
      Tuple.tuple(CoreMetrics.NCLOC, 41));

  verify(noSonarFilter).noSonarInFile(inputFile, Collections.singleton(49));

  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 10, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 11, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 12, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 13, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 17, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 18, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 19, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 20, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 21, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 22, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 54, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, 56, 1);

  verify(fileLinesContext).setIntValue(CoreMetrics.NCLOC_DATA_KEY, 1, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.NCLOC_DATA_KEY, 2, 1);
  verify(fileLinesContext).setIntValue(CoreMetrics.NCLOC_DATA_KEY, 3, 1);
}
 
开发者ID:SonarSource,项目名称:sonar-dotnet-shared-library,代码行数:59,代码来源:MetricsImporterTest.java


示例13: setUp

import org.sonar.api.measures.FileLinesContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  fileLinesContextFactory = mock(FileLinesContextFactory.class);
  fileLinesContext = mock(FileLinesContext.class);
  when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
}
 
开发者ID:SonarSource,项目名称:sonar-xml,代码行数:7,代码来源:LineCounterTest.java



注:本文中的org.sonar.api.measures.FileLinesContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NamespaceMap类代码示例发布时间:2022-05-22
下一篇:
Java ModelObject类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap