本文整理汇总了Java中com.sonar.sslr.api.Grammar类的典型用法代码示例。如果您正苦于以下问题:Java Grammar类的具体用法?Java Grammar怎么用?Java Grammar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Grammar类属于com.sonar.sslr.api包,在下文中一共展示了Grammar类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: saveIssues
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Saves issues form input file and source file.
*
* @param sonarFile input file.
* @param squidFile source file.
*/
private void saveIssues(InputFile sonarFile, SourceFile squidFile) {
Collection<CheckMessage> messages = squidFile.getCheckMessages();
messages.forEach(message -> {
RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
Issuable issuable = resourcePerspectives.as(Issuable.class, sonarFile);
if (issuable != null) {
Issue issue = issuable.newIssueBuilder()
.ruleKey(ruleKey)
.line(message.getLine())
.message(message.getText(Locale.ENGLISH))
.build();
issuable.addIssue(issue);
}
});
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:23,代码来源:ApexSquidSensor.java
示例2: create
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Returns a scanner from configuration and visitors.
*
* @param config apex configuration.
* @param visitors list of visitors.
* @return a scanner.
*/
public static AstScanner<Grammar> create(ApexConfiguration config, SquidAstVisitor<Grammar>... visitors) {
final SourceProject sourceProject = new SourceProject(PROJECT_NAME);
final SquidAstVisitorContextImpl<Grammar> context = new SquidAstVisitorContextImpl<>(sourceProject);
final Parser<Grammar> parser = ApexParser.create(config);
AstScanner.Builder<Grammar> builder = AstScanner.<Grammar>builder(context).setBaseParser(parser);
builder.withMetrics(ApexMetric.values());
builder.setFilesMetric(ApexMetric.FILES);
setCommentAnalyser(builder);
setClassesAnalyser(builder);
setMethodAnalyser(builder);
setMetrics(config, builder);
for (SquidAstVisitor<Grammar> visitor : visitors) {
builder.withSquidAstVisitor(visitor);
}
return builder.build();
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:27,代码来源:ApexAstScanner.java
示例3: setMetrics
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Sets the default apex metrics in {@link AstScanner}.
*
* @param config apex configuration.
* @param builder scanner builder.
*/
private static void setMetrics(ApexConfiguration config, AstScanner.Builder<Grammar> builder) {
builder.withSquidAstVisitor(new LinesVisitor<>(ApexMetric.LINES));
builder.withSquidAstVisitor(new LinesOfCodeVisitor<>(ApexMetric.LINES_OF_CODE));
AstNodeType[] complexityAstNodeType = new AstNodeType[]{
METHOD_DECLARATION,
WHILE_STATEMENT,
FOR_STATEMENT,
IF_STATEMENT,
RETURN_STATEMENT
};
builder.withSquidAstVisitor(ComplexityVisitor.<Grammar>builder()
.setMetricDef(ApexMetric.COMPLEXITY)
.subscribeTo(complexityAstNodeType)
.build());
builder.withSquidAstVisitor(CommentsVisitor.<Grammar>builder()
.withCommentMetric(ApexMetric.COMMENT_LINES)
.withNoSonar(Boolean.TRUE)
.withIgnoreHeaderComment(config.getIgnoreHeaderComments())
.build());
builder.withSquidAstVisitor(CounterVisitor.<Grammar>builder()
.setMetricDef(ApexMetric.STATEMENTS)
.subscribeTo(STATEMENT)
.build());
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:31,代码来源:ApexAstScanner.java
示例4: setCommentAnalyser
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Sets the default visitors to mapping comments.
*
* @param builder scanner builder.
*/
private static void setCommentAnalyser(AstScanner.Builder<Grammar> builder) {
builder.setCommentAnalyser(new CommentAnalyser() {
@Override
public boolean isBlank(String line) {
for (int i = 0; i < line.length(); i++) {
if (Character.isLetterOrDigit(line.charAt(i))) {
return false;
}
}
return true;
}
@Override
public String getContents(String comment) {
return comment.substring(comment.indexOf('/'));
}
});
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:24,代码来源:ApexAstScanner.java
示例5: scanSingleFile
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Helper method for testing checks without having to deploy them on a Sonar instance.
*/
public static SourceFile scanSingleFile(File file, SquidAstVisitor<Grammar>... visitors) {
if (!file.isFile()) {
throw new IllegalArgumentException("File '" + file + "' not found.");
}
AstScanner<Grammar> scanner = create(new FlowConfiguration(Charsets.UTF_8), visitors);
scanner.scanFile(file);
Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class));
if (sources.size() != 1) {
throw new IllegalStateException("Only one SourceFile was expected whereas " + sources.size() + " has been returned.");
}
for (SourceCode squidSourceFile : sources) {
logger.debug("+++Checking Dependencies +++");
ArrayList<String> dependencies = (ArrayList<String>) squidSourceFile.getData(FlowMetric.DEPENDENCIES);
if(dependencies != null)
for(String dependency:dependencies)
logger.debug("+++Dependency: " + dependency);
}
return (SourceFile) sources.iterator().next();
}
开发者ID:I8C,项目名称:sonar-flow-plugin,代码行数:24,代码来源:FlowAstScanner.java
示例6: setMetrics
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
private static void setMetrics(FlowConfiguration conf, AstScanner.Builder<Grammar> builder) {
builder.withMetrics(FlowMetric.values());
builder.setFilesMetric(FlowMetric.FILES);
builder.withSquidAstVisitor(new LinesVisitor<Grammar>(FlowMetric.LINES));
builder.withSquidAstVisitor(new FlowLinesOfCodeVisitor<Grammar>(FlowMetric.LINES_OF_CODE));
builder.withSquidAstVisitor(new DependencyVisitor<Grammar>());
AstNodeType[] complexityAstNodeType = new AstNodeType[]{
FlowGrammar.LOOP,
FlowGrammar.BRANCH,
FlowGrammar.SEQUENCE,
FlowGrammar.RETRY
};
builder.withSquidAstVisitor(ComplexityVisitor.<Grammar>builder()
.setMetricDef(FlowMetric.COMPLEXITY)
.subscribeTo(complexityAstNodeType)
.build());
builder.withSquidAstVisitor(CommentsVisitor.<Grammar>builder().withCommentMetric(FlowMetric.COMMENT_LINES)
.withNoSonar(true)
.build());
builder.withSquidAstVisitor(CounterVisitor.<Grammar>builder()
.setMetricDef(FlowMetric.MAPS)
.subscribeTo(FlowGrammar.MAP)
.build());
}
开发者ID:I8C,项目名称:sonar-flow-plugin,代码行数:26,代码来源:FlowAstScanner.java
示例7: setCommentAnalyser
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
private static void setCommentAnalyser(AstScanner.Builder<Grammar> builder) {
builder.setCommentAnalyser(
new CommentAnalyser() {
@Override
public boolean isBlank(String line) {
for (int i = 0; i < line.length(); i++) {
if (Character.isLetterOrDigit(line.charAt(i))) {
return false;
}
}
return true;
}
@Override
public String getContents(String comment) {
return comment;
}
});
}
开发者ID:I8C,项目名称:sonar-flow-plugin,代码行数:20,代码来源:FlowAstScanner.java
示例8: create
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
public static AstScanner<Grammar> create(FlowConfiguration conf, SquidAstVisitor<Grammar>... visitors) {
final SquidAstVisitorContextImpl<Grammar> context = new SquidAstVisitorContextImpl<Grammar>(new SourceProject("Flow Project"));
final Parser<Grammar> parser = NodeParser.create(conf);
AstScanner.Builder<Grammar> builder = AstScanner.<Grammar>builder(context).setBaseParser(parser);
/* Required */
builder.setFilesMetric(FlowMetric.FILES);
setCommentAnalyser(builder);
/* External visitors (typically Check ones) */
for (SquidAstVisitor<Grammar> visitor : visitors) {
builder.withSquidAstVisitor(visitor);
}
return builder.build();
}
开发者ID:I8C,项目名称:sonar-flow-plugin,代码行数:18,代码来源:NodeAstScanner.java
示例9: FlowSquidSensor
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
public FlowSquidSensor(Settings settings, CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory,
FileSystem fileSystem, ResourcePerspectives resourcePerspectives, PathResolver pathResolver) {
logger.debug("** FlowSquidSenser constructor");
this.settings = settings;
this.pathResolver = pathResolver;
this.checks = checkFactory
.<SquidCheck<Grammar>>create(CheckList.REPOSITORY_KEY)
.addAnnotatedChecks((Iterable)CheckList.getChecks(settings.getBoolean(FlowPlugin.IGNORE_TOPLEVEL_KEY),false));
this.nodeChecks = checkFactory
.<SquidCheck<Grammar>>create(CheckList.REPOSITORY_KEY)
.addAnnotatedChecks((Iterable)CheckList.getChecks(settings.getBoolean(FlowPlugin.IGNORE_TOPLEVEL_KEY), true));
this.fileLinesContextFactory = fileLinesContextFactory;
this.fileSystem = fileSystem;
this.resourcePerspectives = resourcePerspectives;
this.mainFilePredicates = fileSystem.predicates().and(
fileSystem.predicates().hasLanguage(FlowLanguage.KEY),
fileSystem.predicates().hasType(InputFile.Type.MAIN));
}
开发者ID:I8C,项目名称:sonar-flow-plugin,代码行数:19,代码来源:FlowSquidSensor.java
示例10: execute
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
@Override
public void execute(SensorContext context) {
this.context = context;
Map<InputFile, Set<Integer>> linesOfCode = new HashMap<>();
PuppetConfiguration conf = createConfiguration();
List<SquidAstVisitor<Grammar>> visitors = Lists.newArrayList(checks.all());
visitors.add(new FileLinesVisitor(fileLinesContextFactory, context.fileSystem(), linesOfCode, conf.getIgnoreHeaderComments()));
visitors.add(new PuppetHighlighter(context));
scanner = PuppetAstScanner.create(conf, visitors.toArray(new SquidAstVisitor[visitors.size()]));
FilePredicates p = context.fileSystem().predicates();
scanner.scanFiles(Lists.newArrayList(context.fileSystem().files(p.and(p.hasType(InputFile.Type.MAIN), p.hasLanguage(Puppet.KEY)))));
Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class));
save(squidSourceFiles);
new ProjectChecks(context).reportProjectIssues();
// savePreciseIssues(
// visitors
// .stream()
// .filter(v -> v instanceof PuppetCheck)
// .map(v -> (PuppetCheck) v)
// .collect(Collectors.toList()));
// (new PuppetCoverageSensor()).execute(context, linesOfCode);
}
开发者ID:iwarapter,项目名称:sonar-puppet,代码行数:27,代码来源:PuppetSquidSensor.java
示例11: saveIssues
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
private void saveIssues(InputFile inputFile, SourceFile squidFile) {
Collection<CheckMessage> messages = squidFile.getCheckMessages();
for (CheckMessage message : messages) {
RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
NewIssue newIssue = context.newIssue();
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(message.getText(Locale.ENGLISH))
.on(inputFile);
if (message.getLine() != null) {
primaryLocation.at(inputFile.selectLine(message.getLine()));
}
newIssue.forRule(ruleKey).at(primaryLocation).save();
}
}
开发者ID:iwarapter,项目名称:sonar-puppet,代码行数:18,代码来源:PuppetSquidSensor.java
示例12: getParser
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Get a Sonar {@link Parser} from this factory
*
* @return a new parser instance
*/
public Parser<Grammar> getParser()
{
final GrappaChannel channel = new GrappaChannel(rule);
suppliers.forEach(channel::addListenerSupplier);
final LexerfulGrammarBuilder builder = getGrammarBuilder();
builder.setRootRule(entryPoint);
final Lexer lexer = Lexer.builder()
.withFailIfNoChannelToConsumeOneCharacter(true)
.withChannel(channel)
.build();
return Parser.builder(builder.build())
.withLexer(lexer)
.build();
}
开发者ID:litesolutions,项目名称:sonar-sslr-grappa,代码行数:24,代码来源:GrappaSslrFactory.java
示例13: ApexSquidSensor
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Default construct to initialize the variables.
*
* @param fileSystem source files.
* @param perspectives perspective from resources.
* @param checkFactory factory to create a check.
*/
public ApexSquidSensor(FileSystem fileSystem, ResourcePerspectives perspectives, CheckFactory checkFactory) {
this.checks = checkFactory
.<SquidAstVisitor<Grammar>>create(CheckList.REPOSITORY_KEY)
.addAnnotatedChecks(CheckList.getChecks());
this.fileSystem = fileSystem;
this.resourcePerspectives = perspectives;
FilePredicates predicates = fileSystem.predicates();
filePredicate = predicates.and(
predicates.hasType(InputFile.Type.MAIN),
predicates.hasLanguage(Apex.KEY));
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:20,代码来源:ApexSquidSensor.java
示例14: analyse
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Analyzes files for a given project.
*
* @param project current project.
* @param context sensor context.
*/
@Override
public void analyse(Project project, SensorContext context) {
this.context = context;
List<SquidAstVisitor<Grammar>> visitors = Lists.newArrayList(checks.all());
scanner = ApexAstScanner.create(createConfiguration(),
visitors.toArray(new SquidAstVisitor[visitors.size()]));
scanner.scanFiles(Lists.newArrayList(fileSystem.files(filePredicate)));
Collection<SourceCode> squidSourceFiles = scanner.getIndex()
.search(new QueryByType(SourceFile.class));
save(squidSourceFiles);
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:20,代码来源:ApexSquidSensor.java
示例15: create
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Creates a Parser integrated with Grammar and Lexer.
*
* @param config apex configuration.
* @return a parser
* @throws IllegalArgumentException when configuration is null.
*/
public static Parser<Grammar> create(ApexConfiguration config) {
if (config == null) {
throw new IllegalArgumentException(ERROR_MESSAGE);
}
return Parser.builder(ApexGrammar.create())
.withLexer(ApexLexer.create(config)).build();
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:15,代码来源:ApexParser.java
示例16: scanFile
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Returns a source file from file and visitors.
*
* @param file source file.
* @param visitors list of visitors.
* @return a source.
* @exception IllegalArgumentException when file is not found.
* @exception IllegalStateException when there is more than one sourceFile.
*/
public static SourceFile scanFile(File file, SquidAstVisitor<Grammar>... visitors) {
if (!file.isFile()) {
throw new IllegalArgumentException(String.format(FILE_NOT_FOUND, file));
}
AstScanner<Grammar> scanner = create(new ApexConfiguration(Charsets.UTF_8), visitors);
scanner.scanFile(file);
Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class));
if (sources.size() != 1) {
throw new IllegalStateException(String.format(ONE_SOURCE_FILE, sources.size()));
}
return (SourceFile) sources.iterator().next();
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:22,代码来源:ApexAstScanner.java
示例17: setMethodAnalyser
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Sets the default visitors to mapping a method.
*
* @param builder scanner builder.
*/
private static void setMethodAnalyser(AstScanner.Builder<Grammar> builder) {
builder.withSquidAstVisitor(new SourceCodeBuilderVisitor<>(
buildCallback(METHOD_IDENTIFIER, IS_CLASS),
METHOD_DECLARATION));
builder.withSquidAstVisitor(CounterVisitor.<Grammar>builder()
.setMetricDef(ApexMetric.METHODS)
.subscribeTo(METHOD_DECLARATION)
.build());
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:16,代码来源:ApexAstScanner.java
示例18: setClassesAnalyser
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Sets the default visitors to mapping a class.
*
* @param builder scanner builder.
*/
private static void setClassesAnalyser(AstScanner.Builder<Grammar> builder) {
builder.withSquidAstVisitor(new SourceCodeBuilderVisitor<>(
buildCallback(COMMON_IDENTIFIER, !IS_CLASS),
CLASS_OR_INTERFACE_DECLARATION));
builder.withSquidAstVisitor(CounterVisitor.<Grammar>builder()
.setMetricDef(ApexMetric.CLASSES)
.subscribeTo(CLASS_OR_INTERFACE_DECLARATION)
.build());
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:16,代码来源:ApexAstScanner.java
示例19: testTheNumberOfScannedFiles
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
@Test
public void testTheNumberOfScannedFiles() {
AstScanner<Grammar> scanner = ApexAstScanner.create(apexConfiguration);
scanner.scanFiles(ImmutableList.of(
new File("src/test/resources/metrics/methods.cls"),
new File("src/test/resources/metrics/lines.cls")));
SourceProject project = buildProject(scanner);
assertThat(project.getInt(ApexMetric.FILES)).isEqualTo(2);
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:10,代码来源:ApexAstScannerTest.java
示例20: parseQuery
import com.sonar.sslr.api.Grammar; //导入依赖的package包/类
/**
* Re-parses a query that was retrieved as a String.
*
* @param astNode The String's node.
* @return The query as a new QUERY_EXPRESSION node.
*/
public static AstNode parseQuery(AstNode astNode) {
AstNode parsedQuery = null;
try {
String string = astNode.getTokenOriginalValue();
String queryAsString = StringUtils.substringBetween(string, "'", "'");
Parser<Grammar> queryParser = ApexParser.create(new ApexConfiguration(Charsets.UTF_8));
queryParser.setRootRule(queryParser.getGrammar().rule(ApexGrammarRuleKey.QUERY_EXPRESSION));
parsedQuery = queryParser.parse(queryAsString);
} catch (Exception e) {
ChecksLogger.logCheckError(CLASS_TO_LOG, METHOD_TO_LOG, e.toString());
}
return parsedQuery;
}
开发者ID:fundacionjala,项目名称:enforce-sonarqube-plugin,代码行数:20,代码来源:SoqlParser.java
注:本文中的com.sonar.sslr.api.Grammar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论