本文整理汇总了Java中org.sonar.api.batch.sensor.highlighting.TypeOfText类的典型用法代码示例。如果您正苦于以下问题:Java TypeOfText类的具体用法?Java TypeOfText怎么用?Java TypeOfText使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeOfText类属于org.sonar.api.batch.sensor.highlighting包,在下文中一共展示了TypeOfText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitNode
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {
super.visitNode(tree);
List<SyntaxToken> tokens = new ArrayList<>();
TypeOfText code = null;
if (tree.is(Tree.Kind.LESS_VARIABLE)) {
tokens.add(((LessVariableTree) tree).variable().value());
tokens.add(((LessVariableTree) tree).variablePrefix());
code = TypeOfText.CONSTANT;
}
for (SyntaxToken token : tokens) {
highlight(token, code);
}
}
示例2: visitNode
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {
super.visitNode(tree);
List<SyntaxToken> tokens = new ArrayList<>();
TypeOfText code = null;
if (tree.is(Tree.Kind.SCSS_VARIABLE)) {
tokens.add(((ScssVariableTree) tree).name().value());
tokens.add(((ScssVariableTree) tree).prefix());
code = TypeOfText.CONSTANT;
} else if (tree.is(Tree.Kind.SCSS_DIRECTIVE)) {
tokens.add(((ScssDirectiveTree) tree).at());
tokens.add(((ScssDirectiveTree) tree).name());
code = TypeOfText.ANNOTATION;
}
for (SyntaxToken token : tokens) {
highlight(token, code);
}
}
示例3: consumeFor
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Override
void consumeFor(InputFile inputFile, TokenTypeInfo message) {
NewHighlighting highlights = context.newHighlighting().onFile(inputFile);
boolean foundMappableHighlights = false;
for (SonarAnalyzer.TokenTypeInfo.TokenInfo tokenInfo : message.getTokenInfoList()) {
TypeOfText typeOfText = toType(tokenInfo.getTokenType());
if (typeOfText != null) {
highlights.highlight(toTextRange(inputFile, tokenInfo.getTextRange()), typeOfText);
foundMappableHighlights = true;
}
}
if (foundMappableHighlights) {
highlights.save();
}
}
示例4: addHighlighting
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
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.warn(format("Unexpected error adding highlighting on file %s", file.absolutePath()), e);
}
}
}
示例5: visitToken
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Override
public void visitToken(Token token) {
if (token.getType().equals(PuppetTokenType.SINGLE_QUOTED_STRING_LITERAL) || token.getType().equals(PuppetTokenType.DOUBLE_QUOTED_STRING_LITERAL)) {
// case: string literal, including doc string
highlight(token, TypeOfText.STRING);
} else if (token.getType() instanceof PuppetKeyword) {
// case: keyword
highlight(token, TypeOfText.KEYWORD);
}
for (Trivia trivia : token.getTrivia()) {
// case: comment
highlight(trivia.getToken(), TypeOfText.COMMENT);
}
}
示例6: visitNode
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {
SyntaxToken token = null;
TypeOfText code = null;
if (tree.is(Tree.Kind.KEY)) {
token = ((KeyTree) tree).value();
code = TypeOfText.KEYWORD;
} else if (tree.is(Tree.Kind.VALUE)) {
token = ((ValueTree) tree).value();
code = TypeOfText.STRING;
} else if (tree.is(Tree.Kind.TOKEN)) {
highlightComments((InternalSyntaxToken) tree);
}
if (token != null) {
highlight(token, code);
}
}
示例7: visitNode
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {
SyntaxToken token = null;
TypeOfText code = null;
if (tree.is(Tree.Kind.KEY)) {
token = ((KeyTree) tree).value();
code = TypeOfText.KEYWORD;
} else if (tree.is(Tree.Kind.STRING)) {
token = ((LiteralTree) tree).value();
code = TypeOfText.STRING;
} else if (tree.is(Tree.Kind.FALSE, Tree.Kind.TRUE, Tree.Kind.NULL, Tree.Kind.NUMBER)) {
token = ((LiteralTree) tree).value();
code = TypeOfText.CONSTANT;
}
if (token != null) {
highlight(token, code);
}
}
示例8: testCDATAWithTagsInside
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Test
public void testCDATAWithTagsInside() throws Exception {
List<HighlightingData> highlightingData = new XMLHighlighting("<tag><![CDATA[<tag/><!-- Comment -->]]></tag>").getHighlightingData();
assertEquals(5, highlightingData.size());
// <tag
assertData(highlightingData.get(0), 0, 4, TypeOfText.KEYWORD);
// >
assertData(highlightingData.get(1), 4, 5, TypeOfText.KEYWORD);
// <![CDATA[
assertData(highlightingData.get(2), 5, 14, TypeOfText.KEYWORD);
// ]]>
assertData(highlightingData.get(3), 36, 39, TypeOfText.KEYWORD);
// </tag>
assertData(highlightingData.get(4), 39, 45, TypeOfText.KEYWORD);
}
示例9: testHighlightMultilineTagWithAttributes
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Test
public void testHighlightMultilineTagWithAttributes() throws XMLStreamException {
List<HighlightingData> highlightingData = new XMLHighlighting("<tag att1='value1' \n att2\n = 'value2' att3=\n'value3' att4='multiline \n \" attribute'> </tag>").getHighlightingData();
assertEquals(11, highlightingData.size());
// <tag
assertData(highlightingData.get(0), 0, 4, TypeOfText.KEYWORD);
assertData(highlightingData.get(1), 5, 9, TypeOfText.CONSTANT);
assertData(highlightingData.get(2), 10, 18, TypeOfText.STRING);
assertData(highlightingData.get(3), 21, 27, TypeOfText.CONSTANT);
assertData(highlightingData.get(4), 29, 37, TypeOfText.STRING);
assertData(highlightingData.get(5), 38, 42, TypeOfText.CONSTANT);
assertData(highlightingData.get(6), 44, 52, TypeOfText.STRING);
assertData(highlightingData.get(7), 53, 57, TypeOfText.CONSTANT);
assertData(highlightingData.get(8), 58, 83, TypeOfText.STRING);
// >
assertData(highlightingData.get(9), 83, 84, TypeOfText.KEYWORD);
}
示例10: testXMLHeader
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Test
public void testXMLHeader() throws XMLStreamException {
List<HighlightingData> highlightingData = new XMLHighlighting("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> <tag/>").getHighlightingData();
assertEquals(9, highlightingData.size());
// <?xml
assertData(highlightingData.get(0), 0, 5, TypeOfText.KEYWORD);
// ?>
assertData(highlightingData.get(5), 37, 39, TypeOfText.KEYWORD);
// version
assertData(highlightingData.get(1), 6, 13, TypeOfText.CONSTANT);
// "1.0"
assertData(highlightingData.get(2), 14, 19, TypeOfText.STRING);
// encoding
assertData(highlightingData.get(3), 20, 28, TypeOfText.CONSTANT);
// "UTF-8"
assertData(highlightingData.get(4), 29, 36, TypeOfText.STRING);
}
示例11: fill
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
public void fill(final SensorContext context, final InputFile f, final Tokens tokens) {
try {
final NewHighlighting highlithing = context.newHighlighting().onFile(f);
for (final Token token : tokens.getToken()) {
final List<String> kinds = Arrays.asList(token.getTokenFlags().toLowerCase().split(","));
if (check("comment", token, kinds)) {
highlithing.highlight(token.getStartOffset(), token.getEndOffset(), TypeOfText.COMMENT);
continue;
}
/* if (check("CommandName", token, kinds)) {
highlithing.highlight(token.getStartOffset(), token.getEndOffset(), TypeOfText.KEYWORD_LIGHT);
continue;
}*/
if (check("keyword", token, kinds)) {
highlithing.highlight(token.getStartOffset(), token.getEndOffset(), TypeOfText.KEYWORD);
continue;
}
if (check("StringLiteral", token, kinds) || check("StringExpandable", token, kinds)) {
highlithing.highlight(token.getStartOffset(), token.getEndOffset(), TypeOfText.STRING);
continue;
}
if (check("Variable", token, kinds)) {
highlithing.highlight(token.getStartOffset(), token.getEndOffset(), TypeOfText.KEYWORD_LIGHT);
continue;
}
}
highlithing.save();
} catch (Throwable e) {
LOGGER.warn("Exception while running highliting", e);
}
}
示例12: assertHighlighting
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
private void assertHighlighting(int line, int column, int length, TypeOfText type) {
for (int i = column; i < column + length; i++) {
List<TypeOfText> typeOfTexts = sensorContext.highlightingTypeAt("moduleKey:" + file.getName(), line, i);
assertThat(typeOfTexts).hasSize(1);
assertThat(typeOfTexts.get(0)).isEqualTo(type);
}
}
示例13: toType
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@CheckForNull
private static TypeOfText toType(SonarAnalyzer.TokenType tokenType) {
// Note:
// TypeOfText.ANNOTATION -> like a type in C#, so received as DECLARATION_NAME
// TypeOfText.STRUCTURED_COMMENT -> not colored differently in C#, so received as COMMENT
// TypeOfText.PREPROCESS_DIRECTIVE -> received as KEYWORD
switch (tokenType) {
case NUMERIC_LITERAL:
return TypeOfText.CONSTANT;
case COMMENT:
return TypeOfText.COMMENT;
case KEYWORD:
return TypeOfText.KEYWORD;
case TYPE_NAME:
return TypeOfText.KEYWORD_LIGHT;
case STRING_LITERAL:
return TypeOfText.STRING;
case UNRECOGNIZED:
// generated by protobuf
case UNKNOWN:
default:
// do not color
return null;
}
}
示例14: test_syntax_highlights_get_imported
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Test
public void test_syntax_highlights_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, HIGHLIGHT_OUTPUT_PROTOBUF_NAME);
assertThat(protobuf.isFile()).withFailMessage("no such file: " + protobuf).isTrue();
new HighlightImporter(tester, f -> true).accept(protobuf.toPath());
// using System;
assertThat(tester.highlightingTypeAt(inputFile.key(), 1, 0).get(0)).isEqualTo(TypeOfText.KEYWORD);
assertThat(tester.highlightingTypeAt(inputFile.key(), 1, 4).get(0)).isEqualTo(TypeOfText.KEYWORD);
assertThat(tester.highlightingTypeAt(inputFile.key(), 1, 5)).isEmpty();
// [SuppressMessage("Maintainability", "S2326:Unused type parameters should be removed")]
assertThat(tester.highlightingTypeAt(inputFile.key(), 53, 4)).isEmpty();
assertThat(tester.highlightingTypeAt(inputFile.key(), 53, 5).get(0)).isEqualTo(TypeOfText.KEYWORD_LIGHT);
assertThat(tester.highlightingTypeAt(inputFile.key(), 53, 19).get(0)).isEqualTo(TypeOfText.KEYWORD_LIGHT);
assertThat(tester.highlightingTypeAt(inputFile.key(), 53, 20)).isEmpty();
assertThat(tester.highlightingTypeAt(inputFile.key(), 53, 21).get(0)).isEqualTo(TypeOfText.STRING);
assertThat(tester.highlightingTypeAt(inputFile.key(), 53, 37).get(0)).isEqualTo(TypeOfText.STRING);
assertThat(tester.highlightingTypeAt(inputFile.key(), 53, 38)).isEmpty();
// if (op1 == 0)
assertThat(tester.highlightingTypeAt(inputFile.key(), 27, 23).get(0)).isEqualTo(TypeOfText.CONSTANT);
assertThat(tester.highlightingTypeAt(inputFile.key(), 9, 0).get(0)).isEqualTo(TypeOfText.COMMENT);
}
示例15: visitNode
import org.sonar.api.batch.sensor.highlighting.TypeOfText; //导入依赖的package包/类
@Override
public void visitNode(Tree tree) {
List<SyntaxToken> tokens = new ArrayList<>();
TypeOfText code = null;
if (tree.is(Tree.Kind.TAG)) {
tokens.add(((TagTree) tree).prefix());
tokens.add(((TagTree) tree).value());
code = TypeOfText.ANNOTATION;
} else if (tree.is(
Tree.Kind.FEATURE_PREFIX,
Tree.Kind.BACKGROUND_PREFIX,
Tree.Kind.SCENARIO_PREFIX,
Tree.Kind.SCENARIO_OUTLINE_PREFIX,
Tree.Kind.EXAMPLES_PREFIX,
Tree.Kind.STEP_PREFIX)) {
tokens.add(((PrefixTree) tree).keyword());
code = TypeOfText.KEYWORD;
} else if (tree.is(Tree.Kind.NAME)) {
tokens.add(((NameTree) tree).value());
code = TypeOfText.STRING;
} else if (tree.is(Tree.Kind.LANGUAGE_DECLARATION)) {
tokens.add(((LanguageDeclarationTree) tree).value());
code = TypeOfText.ANNOTATION;
} else if (tree.is(Tree.Kind.TOKEN)) {
highlightComments((InternalSyntaxToken) tree);
}
for (SyntaxToken token : tokens) {
highlight(token, code);
}
}