@Beta public class SensorContextTester extends Object implements SensorContext
Sensor. This is not an API and method signature may evolve.
Usage: call create(File) to create an "in memory" implementation of SensorContext with a filesystem initialized with provided baseDir.
You have to manually register inputFiles using:
sensorContextTester.fileSystem().add(new DefaultInputFile("myProjectKey", "src/Foo.java")
.setLanguage("java")
.initMetadata("public class Foo {\n}"));
Then pass it to your Sensor. You can then query elements provided by your sensor using methods allIssues(), ...
| Modifier and Type | Method and Description |
|---|---|
ActiveRules |
activeRules()
Get list of active rules.
|
Collection<Issue> |
allIssues() |
Integer |
conditions(String fileKey,
CoverageType type,
int line) |
Integer |
coveredConditions(String fileKey,
CoverageType type,
int line) |
List<TokensLine> |
cpdTokens(String componentKey) |
static SensorContextTester |
create(File moduleBaseDir) |
static SensorContextTester |
create(Path moduleBaseDir) |
DefaultFileSystem |
fileSystem()
Get filesystem of the current module.
|
Version |
getSonarQubeVersion()
Default value is the version of this API.
|
List<TypeOfText> |
highlightingTypeAt(String componentKey,
int line,
int lineOffset)
Return list of syntax highlighting applied for a given position in a file.
|
Integer |
lineHits(String fileKey,
CoverageType type,
int line) |
<G extends Serializable> |
measure(String componetKey,
Metric<G> metric) |
<G extends Serializable> |
measure(String componentKey,
String metricKey) |
Collection<Measure> |
measures(String componentKey) |
InputModule |
module() |
NewCoverage |
newCoverage()
Builder to define coverage in a file.
|
NewCpdTokens |
newCpdTokens()
Builder to define CPD tokens in a file.
|
NewHighlighting |
newHighlighting()
Builder to define highlighting of a file.
|
NewIssue |
newIssue()
Fluent builder to create a new
Issue. |
<G extends Serializable> |
newMeasure()
Fluent builder to create a new
Measure. |
NewSymbolTable |
newSymbolTable()
Builder to define symbol table of a file.
|
Collection<TextRange> |
referencesForSymbolAt(String componentKey,
int line,
int lineOffset)
Return list of symbol references ranges for the symbol at a given position in a file.
|
SensorContextTester |
setActiveRules(ActiveRules activeRules) |
SensorContextTester |
setFileSystem(DefaultFileSystem fs) |
SensorContextTester |
setSettings(Settings settings) |
SensorContextTester |
setSonarQubeVersion(Version version) |
Settings |
settings()
Get settings of the current module.
|
public static SensorContextTester create(File moduleBaseDir)
public static SensorContextTester create(Path moduleBaseDir)
public Settings settings()
SensorContextsettings in interface SensorContextpublic SensorContextTester setSettings(Settings settings)
public DefaultFileSystem fileSystem()
SensorContextfileSystem in interface SensorContextpublic SensorContextTester setFileSystem(DefaultFileSystem fs)
public ActiveRules activeRules()
SensorContextactiveRules in interface SensorContextpublic SensorContextTester setActiveRules(ActiveRules activeRules)
public Version getSonarQubeVersion()
setSonarQubeVersion(Version) to test your Sensor behavior.getSonarQubeVersion in interface SensorContextpublic SensorContextTester setSonarQubeVersion(Version version)
public InputModule module()
module in interface SensorContextpublic <G extends Serializable> NewMeasure<G> newMeasure()
SensorContextMeasure. Don't forget to call NewMeasure.save() once all parameters are provided.newMeasure in interface SensorContextpublic Collection<Measure> measures(String componentKey)
public <G extends Serializable> Measure<G> measure(String componetKey, Metric<G> metric)
public <G extends Serializable> Measure<G> measure(String componentKey, String metricKey)
public NewIssue newIssue()
SensorContextIssue. Don't forget to call NewIssue.save() once all parameters are provided.newIssue in interface SensorContextpublic Collection<Issue> allIssues()
@CheckForNull public Integer lineHits(String fileKey, CoverageType type, int line)
@CheckForNull public Integer conditions(String fileKey, CoverageType type, int line)
@CheckForNull public Integer coveredConditions(String fileKey, CoverageType type, int line)
@CheckForNull public List<TokensLine> cpdTokens(String componentKey)
public NewHighlighting newHighlighting()
SensorContextNewHighlighting.save() once all elements are provided.newHighlighting in interface SensorContextpublic NewCoverage newCoverage()
SensorContextNewCoverage.save().newCoverage in interface SensorContextpublic NewCpdTokens newCpdTokens()
SensorContextNewCpdTokens.save().newCpdTokens in interface SensorContextpublic NewSymbolTable newSymbolTable()
SensorContextNewSymbolTable.save() once all symbols are provided.newSymbolTable in interface SensorContextpublic List<TypeOfText> highlightingTypeAt(String componentKey, int line, int lineOffset)
componentKey - Key of the file like 'myProjectKey:src/foo.php'line - Line you want to querylineOffset - Offset you want to query.public Collection<TextRange> referencesForSymbolAt(String componentKey, int line, int lineOffset)
componentKey - Key of the file like 'myProjectKey:src/foo.php'line - Line you want to querylineOffset - Offset you want to query.Copyright © 2009–2017 SonarSource. All rights reserved.