use of org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule in project sonarqube by SonarSource.
the class SensorContextTester method highlightingTypeAt.
/**
* Return list of syntax highlighting applied for a given position in a file. The result is a list because in theory you
* can apply several styles to the same range.
*
* @param componentKey Key of the file like 'myProjectKey:src/foo.php'
* @param line Line you want to query
* @param lineOffset Offset you want to query.
* @return List of styles applied to this position or empty list if there is no highlighting at this position.
*/
public List<TypeOfText> highlightingTypeAt(String componentKey, int line, int lineOffset) {
DefaultHighlighting syntaxHighlightingData = (DefaultHighlighting) sensorStorage.highlightingByComponent.get(componentKey);
if (syntaxHighlightingData == null) {
return Collections.emptyList();
}
List<TypeOfText> result = new ArrayList<>();
DefaultTextPointer location = new DefaultTextPointer(line, lineOffset);
for (SyntaxHighlightingRule sortedRule : syntaxHighlightingData.getSyntaxHighlightingRuleSet()) {
if (sortedRule.range().start().compareTo(location) <= 0 && sortedRule.range().end().compareTo(location) > 0) {
result.add(sortedRule.getTextType());
}
}
return result;
}
Aggregations