本文整理汇总了Java中org.sonar.api.batch.fs.internal.DefaultInputFile.setLanguage方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultInputFile.setLanguage方法的具体用法?Java DefaultInputFile.setLanguage怎么用?Java DefaultInputFile.setLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.api.batch.fs.internal.DefaultInputFile
的用法示例。
在下文中一共展示了DefaultInputFile.setLanguage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExecute
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void testExecute() throws IOException, InterruptedException {
File baseFile = folder.newFile("test.ps1");
FileUtils.copyURLToFile(getClass().getResource("/testFiles/test.ps1"), baseFile);
DefaultFileSystem fs = new DefaultFileSystem(folder.getRoot());
DefaultInputFile ti = new DefaultInputFile("test", "test.ps1");
ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
ti.setLanguage(PowershellLanguage.KEY);
fs.add(ti);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ctxTester.setFileSystem(fs);
TokenizerSensor s = new TokenizerSensor(new Settings(), temp);
s.execute(ctxTester);
Assert.assertEquals(16, ctxTester.cpdTokens("test:test.ps1").size());
Assert.assertEquals(1, ctxTester.highlightingTypeAt("test:test.ps1", 1, 5).size());
}
示例2: testHighlighting2
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void testHighlighting2() throws Throwable {
Settings settings = new Settings();
File baseFile = folder.newFile("test.sql");
FileUtils.write(baseFile, "SELECT * FROM dbo.test");
DefaultInputFile file1 = new DefaultInputFile("test", "test.sql");
file1.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
file1.setLanguage(TSQLLanguage.KEY);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ctxTester.fileSystem().add(file1);
HighlightingSensor sensor = new HighlightingSensor(settings);
sensor.execute(ctxTester);
Assert.assertEquals(1, ctxTester.highlightingTypeAt("test:test.sql", 1, 5).size());
Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 2, 0).size());
Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 5, 0).size());
Assert.assertEquals(1, ctxTester.cpdTokens("test:test.sql").size());
}
示例3: test
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
String s = "/** comment **/\r\n" + "select\r\n" + "11\n" + "--aaa\r\n";
File ff = folder.newFile("test.sql");
FileUtils.write(ff, s);
DefaultInputFile f = new DefaultInputFile("test", "test.sql");
f.initMetadata(s);
f.setLanguage(TSQLLanguage.KEY);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ctxTester.fileSystem().add(f);
AntrlResult result = Antlr4Utils.getFull(s);
AntlrMeasurer m = new AntlrMeasurer();
SourceLine[] lines = new SourceLinesProvider().getLines(new FileInputStream(ff), Charset.defaultCharset());
m.fill(ctxTester, new FillerRequest(f, result.getStream(), result.getTree(), lines));
Assert.assertEquals(2, ctxTester.measure("test:test.sql", CoreMetrics.NCLOC).value().intValue());
Assert.assertEquals(2, ctxTester.measure("test:test.sql", CoreMetrics.COMMENT_LINES).value().intValue());
}
示例4: beforeClass
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Before
public void beforeClass() {
fileSystem = new DefaultFileSystem(new File(""));
fileSystem.setWorkDir(new File(""));
final DefaultInputFile inputFile = new DefaultInputFile("", "mainFile");
inputFile.setLanguage("java");
inputFile.setType(InputFile.Type.MAIN);
fileSystem.add(inputFile);
final DefaultInputFile testFile = new DefaultInputFile("", "testFile");
testFile.setLanguage("java");
testFile.setType(InputFile.Type.TEST);
fileSystem.add(testFile);
}
示例5: addFile
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
private void addFile(final SensorContextTester sensorContext, final String name, final String language,
final Type type) {
final DefaultInputFile file = new DefaultInputFile("moduleKey", name);
file.setLanguage(language);
file.setType(type);
sensorContext.fileSystem().add(file);
}
示例6: run
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void run() throws IOException {
TemporaryFolder folder = new TemporaryFolder();
folder.create();
Settings settings = new Settings();
settings.setProperty(Constants.PLUGIN_SKIP_CUSTOM_RULES, false);
String dirPath = "..\\grammars\\tsql";
File dir = new File(dirPath);
Collection<File> files = FileUtils.listFiles(dir, new String[] { "sql" }, true);
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
for (File f : files) {
String tempName = f.getName() + System.nanoTime();
File dest = folder.newFile(tempName);
FileUtils.copyFile(f, dest);
DefaultInputFile file1 = new DefaultInputFile("test", tempName);
file1.initMetadata(new String(Files.readAllBytes(f.toPath())));
file1.setLanguage(TSQLLanguage.KEY);
ctxTester.fileSystem().add(file1);
}
HighlightingSensor sensor = new HighlightingSensor(settings);
sensor.execute(ctxTester);
Collection<Issue> issues = ctxTester.allIssues();
// System.out.println(files.size() + " " + issues.size() + " " + took);
Assert.assertEquals(97, issues.size());
}
示例7: testHighlighting
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void testHighlighting() throws Throwable {
File baseFile0 = temp.newFile("customRulesSample", "xml");
FileUtils.copyURLToFile(getClass().getResource("/customRulesSample.xml"), baseFile0);
Settings settings = new Settings();
settings.setProperty(Constants.PLUGIN_CUSTOM_RULES_PATH, baseFile0.getAbsolutePath());
settings.setProperty(Constants.PLUGIN_CUSTOM_RULES_PREFIX, "customRulesSample");
File baseFile = folder.newFile("test.sql");
FileUtils.copyURLToFile(getClass().getResource("/testFiles/scriptExample.sql"), baseFile);
DefaultInputFile file1 = new DefaultInputFile("test", "test.sql");
file1.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
file1.setLanguage(TSQLLanguage.KEY);
DefaultInputFile file2 = new DefaultInputFile("test", "test.php");
file2.setLanguage("php");
SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
ctxTester.fileSystem().add(file1);
ctxTester.fileSystem().add(file2);
HighlightingSensor sensor = new HighlightingSensor(settings);
sensor.execute(ctxTester);
Collection<Issue> issues = ctxTester.allIssues();
Assert.assertEquals(3, issues.size());
Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 0, 0).size());
Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 2, 0).size());
Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 5, 0).size());
Assert.assertEquals(16, ctxTester.cpdTokens("test:test.sql").size());
}
示例8: compareWithDefaultInputFile
import org.sonar.api.batch.fs.internal.DefaultInputFile; //导入方法依赖的package包/类
@Test
public void compareWithDefaultInputFile() throws IOException {
String s = "select " + "*" + "from dbo.test\r\nselect 1";
File ff = folder.newFile("test.sql");
FileUtils.write(ff, s);
DefaultInputFile f = new DefaultInputFile("test", "test.sql");
f.initMetadata(s);
f.setLanguage(TSQLLanguage.KEY);
AntrlResult result = Antlr4Utils.getFull(s);
SourceLinesProvider p = new SourceLinesProvider();
SourceLine[] lines = p.getLines(new FileInputStream(ff), Charset.defaultCharset());
FillerRequest file = new FillerRequest(null, null, result.getTree(), lines);
for (SourceLine l : lines) {
System.out.println(l);
}
for (Token t : result.getStream().getTokens()) {
if (t.getType() == Token.EOF) {
continue;
}
int[] start = file.getLineAndColumn(t.getStartIndex());
int[] end = file.getLineAndColumn(t.getStopIndex());
TextPointer p1 = f.newPointer(t.getStartIndex());
TextPointer p2 = f.newPointer(t.getStopIndex());
Assert.assertNotNull(start);
Assert.assertNotNull(end);
Assert.assertEquals(p1.line(), start[0]);
Assert.assertEquals(p1.lineOffset(), start[1]);
Assert.assertEquals(p2.line(), end[0]);
Assert.assertEquals(p2.lineOffset(), end[1]);
}
}