com.sonar.sslr.impl.Parser Java Examples
The following examples show how to use
com.sonar.sslr.impl.Parser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApexAstScanner.java From enforce-sonarqube-plugin with MIT License | 6 votes |
/** * 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(); }
Example #2
Source File: FlowAstScanner.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates the AstScanner. It will set flow and metric checks, next to the default ones. * * @param conf * Configuration * @param checks * Additional checks to set * @param metrics * Additional metrics to set * @return */ public static AstScanner<Grammar> create(FlowConfiguration conf, Collection<FlowCheck> checks, @Nullable List<SquidAstVisitor<Grammar>> metrics) { final SquidAstVisitorContextImpl<Grammar> context = new SquidAstVisitorContextImpl<Grammar>( new SourceProject("Flow Project")); final Parser<Grammar> parser = FlowParser.create(conf); AstScanner.Builder<Grammar> builder = AstScanner.<Grammar>builder(context) .setBaseParser(parser); /* Required commentAnalyzer */ builder.setCommentAnalyser(new CommentAnalyser()); /* Metrics */ ArrayList<SquidAstVisitor<Grammar>> metricList = new ArrayList<SquidAstVisitor<Grammar>>(); metricList.addAll(MetricList.getFlowVisitors()); if (metrics != null) { metricList.addAll(metrics); } setMetrics(builder, metricList); /* Checks */ for (FlowCheck flowCheck : checks) { builder.withSquidAstVisitor(flowCheck); } return builder.build(); }
Example #3
Source File: NodeAstScanner.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates the AstScanner. It will set flow and metric checks, next to the default ones. * * @param conf * Configuration * @param checks * Additional checks to set * @param metrics * Additional metrics to set * @return */ public static AstScanner<Grammar> create(FlowConfiguration conf, Collection<FlowCheck> checks, @Nullable List<SquidAstVisitor<Grammar>> metrics) { 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 commentAnalyzer */ builder.setCommentAnalyser(new CommentAnalyser()); /* Metrics */ ArrayList<SquidAstVisitor<Grammar>> metricList = new ArrayList<SquidAstVisitor<Grammar>>(); metricList.addAll(MetricList.getDefaultNodeVisitors()); if (metrics != null) { metricList.addAll(metrics); } setMetrics(builder, metricList); /* Checks */ for (FlowCheck flowCheck : checks) { builder.withSquidAstVisitor(flowCheck); } return builder.build(); }
Example #4
Source File: ApexParser.java From enforce-sonarqube-plugin with MIT License | 5 votes |
/** * 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(); }
Example #5
Source File: SoqlParser.java From enforce-sonarqube-plugin with MIT License | 5 votes |
/** * 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; }
Example #6
Source File: ApexConfigurationModel.java From enforce-sonarqube-plugin with MIT License | 4 votes |
@Override public Parser doGetParser() { return null; }
Example #7
Source File: FlowConfigurationModel.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Parser<Grammar> getParser() { return FlowParser.create(getConfiguration()); }
Example #8
Source File: NodeParser.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 4 votes |
public static Parser<Grammar> create(FlowConfiguration conf) { NodeParser.conf = conf; return Parser.builder(NodeGrammar.create()).withLexer(FlowLexer.create(conf)).build(); }
Example #9
Source File: NodeParser.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates this parser. * @return */ public static Parser<Grammar> create() { NodeParser.conf = new FlowConfiguration(Charset.defaultCharset()); return Parser.builder(NodeGrammar.create()).withLexer(FlowLexer.create(NodeParser.conf)) .build(); }
Example #10
Source File: FlowParser.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 4 votes |
public static Parser<Grammar> create(FlowConfiguration conf) { FlowParser.conf = conf; return Parser.builder(FlowGrammar.create()).withLexer(FlowLexer.create(conf)).build(); }
Example #11
Source File: FlowParser.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates this parser. * @return */ public static Parser<Grammar> create() { FlowParser.conf = new FlowConfiguration(Charset.defaultCharset()); return Parser.builder(FlowGrammar.create()).withLexer(FlowLexer.create(FlowParser.conf)) .build(); }
Example #12
Source File: LuaParser.java From sonar-lua with GNU Lesser General Public License v3.0 | 4 votes |
public static Parser<LexerlessGrammar> create(LuaConfiguration conf) { return new ParserAdapter<LexerlessGrammar>(conf.getCharset(), LuaGrammar.createGrammar()); }