Java源码示例:org.sonar.api.batch.fs.TextRange
示例1
private void addHighlighting(final NewHighlighting newHighlightning, final Token token, final InputFile file,
final TextRange range) {
try {
if (token.getType() == TSqlParser.COMMENT || token.getType() == TSqlParser.LINE_COMMENT) {
newHighlightning.highlight(range, TypeOfText.COMMENT);
}
if (token.getType() == TSqlParser.STRING) {
newHighlightning.highlight(range, TypeOfText.STRING);
}
if (this.keywordsProvider.isKeyword(TSqlParser.VOCABULARY.getSymbolicName(token.getType()))) {
newHighlightning.highlight(range, TypeOfText.KEYWORD);
}
} catch (final Throwable e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Unexpected error adding highlighting on file %s", file.absolutePath()), e);
}
}
}
示例2
@Override
public void visitNode(Tree tree) {
if (((InternalSyntaxToken) tree).isEOF()) {
return;
}
SyntaxToken token = (SyntaxToken) tree;
String text = token.text();
if ( text.startsWith("'") ) {
text = "LITERAL";
}
TextRange range = inputFile.newRange(token.line(), token.column(), token.endLine(), token.endColumn());
cpdTokens.addToken(range, text);
}
示例3
@Override
public void visitNode(Tree tree) {
if (((InternalSyntaxToken) tree).isEOF()) {
return;
}
if (((InternalSyntaxToken) tree).isBOM()) {
return;
}
SyntaxToken token = (SyntaxToken) tree;
TextRange range = inputFile.newRange(token.line(), token.column(), token.endLine(), token.endColumn());
cpdTokens.addToken(range, token.text());
}
示例4
private void addErrorTestForLine(final int pLineNo) {
final ActiveRule rule = setupRule("repo", "key");
final NewIssue newIssue = mock(NewIssue.class);
final NewIssueLocation newLocation = mock(NewIssueLocation.class);
when(context.newIssue()).thenReturn(newIssue);
when(newIssue.newLocation()).thenReturn(newLocation);
when(newIssue.forRule(rule.ruleKey())).thenReturn(newIssue);
when(newIssue.at(newLocation)).thenReturn(newIssue);
when(newLocation.on(any(InputComponent.class))).thenReturn(newLocation);
when(newLocation.at(any(TextRange.class))).thenReturn(newLocation);
when(newLocation.message(anyString())).thenReturn(newLocation);
when(inputFile.selectLine(anyInt())).thenReturn(new DefaultTextRange(
new DefaultTextPointer(1, 1), new DefaultTextPointer(1, 2)));
final AuditEvent eventAdded = new AuditEvent(this, file.getAbsolutePath(),
new LocalizedMessage(pLineNo, "", "", null, "", CheckstyleAuditListenerTest.class,
"msg"));
addErrorToListener(eventAdded);
verify(newIssue, times(1)).save();
verify(newIssue, times(1)).forRule(rule.ruleKey());
verify(newIssue, times(1)).at(newLocation);
verify(newIssue, times(1)).newLocation();
verify(newLocation, times(1)).on(any());
verify(newLocation, times(1)).at(any());
verify(newLocation, times(1)).message(any());
}
示例5
private static void assertLocation(IssueLocation location, InputFile file,
String message, int startLine, int startOffset, int endLine, int endOffset) {
assertThat(location.inputComponent(),is(equalTo(file)));
assertThat(location.message(),is(equalTo(message)));
TextRange textRange = location.textRange();
TextPointer start = textRange.start();
assertThat(start.line(),is(equalTo(startLine)));
assertThat(start.lineOffset(),is(equalTo(startOffset)));
TextPointer end = textRange.end();
assertThat(end.line(),is(equalTo(endLine)));
assertThat(end.lineOffset(),is(equalTo(endOffset)));
}
示例6
private static void addCpdToken(final NewCpdTokens cpdTokens, InputFile file, final Token token,
final TextRange range) {
try {
cpdTokens.addToken(range, token.getText());
} catch (Throwable e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Unexpected error adding cpd tokens on file %s", file.absolutePath()), e);
}
}
}
示例7
private Collection<TextRange> references(String key, int line, int column) {
return sensorContext.referencesForSymbolAt(key, line, column);
}