com.sonar.sslr.api.Grammar Java Examples
The following examples show how to use
com.sonar.sslr.api.Grammar.
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: EmptyMapCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void emptyMapCheckInvalid() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new EmptyMapCheck()); // Invalid String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkEmptyMapInvalid/flow.xml"; String expectedMessage = "This map step in the flow is empty, create content or remove the map."; SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); List<CheckMessage> violationMessages = new ArrayList<CheckMessage>( sfViolation.getCheckMessages()); assertEquals(1, violationMessages.size()); assertTrue("Returned check message not as expected", expectedMessage.equals(violationMessages.get(0).getDefaultMessage())); }
Example #2
Source File: QualifiedNameCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void qualifiedNameCheckValid() { Configuration cfg = mock(Configuration.class); Mockito.when(cfg.get(QualifiedNameCheck.QUALIFIED_NAME_KEY)).thenReturn(Optional.of(QualifiedNameCheck.QUALIFIED_NAME_DEFVALUE)); FlowLanguage.setConfig(cfg); List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); QualifiedNameCheck qnc = new QualifiedNameCheck(); checks.add(qnc); String validPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkQualityNameInvalid/flow.xml"; SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File(validPath), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(0, scmCorrect.size()); }
Example #3
Source File: NodeAstScanner.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
/** * Helper method for testing checks without having to deploy them on a Sonar instance. */ public static SourceFile scanSingleFile(File file, Collection<FlowCheck> nodeChecks, List<SquidAstVisitor<Grammar>> metrics) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<Grammar> scanner = create(new FlowConfiguration(Charsets.UTF_8), nodeChecks, metrics); 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."); } return (SourceFile) sources.iterator().next(); }
Example #4
Source File: QualifiedNameCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void qualifiedNameCheckInvalid() { Configuration cfg = mock(Configuration.class); Mockito.when(cfg.get(QualifiedNameCheck.QUALIFIED_NAME_KEY)).thenReturn(Optional.of("test.*")); FlowLanguage.setConfig(cfg); List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); QualifiedNameCheck qnc = new QualifiedNameCheck(); checks.add(qnc); String validPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkQualityNameInvalid/flow.xml"; SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File(validPath), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(1, scmCorrect.size()); }
Example #5
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 #6
Source File: SavePipelineCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void savePipelineCheck() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new SavePipelineCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkSavePipelineInvalid/flow.xml"; String expectedMessage = "Remove service pub.flow:savePipeline"; SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); List<CheckMessage> violationMessages = new ArrayList<CheckMessage>( sfViolation.getCheckMessages()); assertEquals(1, violationMessages.size()); assertTrue("Returned check message not as expected", expectedMessage.equals(violationMessages.get(0).getDefaultMessage())); }
Example #7
Source File: EmptyFlowCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void emptyFlowCheck() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new EmptyFlowCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkEmptyFlowInvalid/flow.xml"; String expectedMessage = "Service doesn't contain any flow steps. Remove service or add flow steps."; SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); List<CheckMessage> violationMessages = new ArrayList<CheckMessage>( sfViolation.getCheckMessages()); assertEquals(1, violationMessages.size()); assertTrue("Returned check message not as expected", expectedMessage.equals(violationMessages.get(0).getDefaultMessage())); }
Example #8
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 #9
Source File: TryCatchCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void tryCatchCheckInvalid() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new TryCatchCheck()); // check invalid flow String invalidFlowPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkTryCatchInvalid/flow.xml"; String expectedMessage = "Create try-catch sequence"; SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidFlowPath), checks, metrics); List<CheckMessage> violationMessages = new ArrayList<CheckMessage>( sfViolation.getCheckMessages()); assertEquals(1, violationMessages.size()); assertTrue("Returned check message not as expected", expectedMessage.equals(violationMessages.get(0).getDefaultMessage())); }
Example #10
Source File: BranchPropertiesCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void branchPropertiesCheckInvalidB() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new BranchPropertiesCheck()); final String expectedMessageB = "Evaluate labels must be true when no switch parameter is defined in BRANCH"; // Check violation flow B: neither switch nor evaluate labels defined SourceFile sfViolationB = FlowAstScanner .scanSingleFile(new File("src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkBranchPropertiesInvalidB/flow.xml"), checks, metrics); List<CheckMessage> violationBMessages = new ArrayList<CheckMessage>( sfViolationB.getCheckMessages()); assertEquals(1, violationBMessages.size()); assertTrue("Returned check message not as expected", expectedMessageB.equals(violationBMessages.get(0).getDefaultMessage())); }
Example #11
Source File: ApexAstScanner.java From enforce-sonarqube-plugin with MIT License | 6 votes |
/** * 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('/')); } }); }
Example #12
Source File: EmptyMapCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void emptyMapCheckValid() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new EmptyMapCheck()); // Valid String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkEmptyMapValid/flow.xml"; SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); List<CheckMessage> violationMessages = new ArrayList<CheckMessage>( sfViolation.getCheckMessages()); assertEquals(0, violationMessages.size()); }
Example #13
Source File: ExitCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void exitCheck() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new ExitCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkExitStepInvalid/flow.xml"; SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); List<CheckMessage> violationMessages = new ArrayList<CheckMessage>( sfViolation.getCheckMessages()); assertEquals(2, violationMessages.size()); // TODO check both violation messages }
Example #14
Source File: ApexAstScanner.java From enforce-sonarqube-plugin with MIT License | 6 votes |
/** * 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()); }
Example #15
Source File: DisabledCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void disabledCheck() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new DisabledCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkDisabledInvalid/flow.xml"; String expectedMessage = "Remove disabled code"; SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); List<CheckMessage> violationMessages = new ArrayList<CheckMessage>( sfViolation.getCheckMessages()); assertEquals(1, violationMessages.size()); assertTrue("Returned check message not as expected", expectedMessage.equals(violationMessages.get(0).getDefaultMessage())); }
Example #16
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 #17
Source File: BranchPropertiesCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void branchPropertiesCheckInvalidA() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new BranchPropertiesCheck()); final String expectedMessageA = "Both switch and evaluate labels are defined in properties of BRANCH"; // Check violation flow A: both switch and evaluate labels defined SourceFile sfViolationA = FlowAstScanner .scanSingleFile(new File("src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkBranchPropertiesInvalidA/flow.xml"), checks, metrics); List<CheckMessage> violationAMessages = new ArrayList<CheckMessage>( sfViolationA.getCheckMessages()); assertEquals(1, violationAMessages.size()); assertTrue("Returned check message not as expected", expectedMessageA.equals(violationAMessages.get(0).getDefaultMessage())); }
Example #18
Source File: ApexSquidSensor.java From enforce-sonarqube-plugin with MIT License | 6 votes |
/** * 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); } }); }
Example #19
Source File: InterfaceCommentsCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void interfaceCommentsCheckInvalid2() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new InterfaceCommentsCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkInterfaceCommentsInvalid2/node.ndf"; SourceFile sfCorrect = NodeAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(4, scmCorrect.size()); }
Example #20
Source File: TryCatchCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void tryCatchCheckValid() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new TryCatchCheck()); // check valid flow String validFlowPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest/pub/checkTryCatchValid/flow.xml"; SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File(validFlowPath), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(0, scmCorrect.size()); }
Example #21
Source File: BranchPropertiesCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void branchPropertiesCheckValid() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new BranchPropertiesCheck()); // Check correct flow SourceFile sfCorrect = FlowAstScanner .scanSingleFile(new File("src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkBranchPropertiesValid/flow.xml"), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(0, scmCorrect.size()); }
Example #22
Source File: NodeAstScannerTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void scanFile() { logger.debug("Scanning file"); List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); NodeAstScanner.scanSingleFile(nodeFile, checks, metrics); }
Example #23
Source File: InterfaceCommentsCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void interfaceCommentsCheckInvalid() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new InterfaceCommentsCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkInterfaceCommentsInvalid/node.ndf"; SourceFile sfCorrect = NodeAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(2, scmCorrect.size()); }
Example #24
Source File: ApexSquidSensor.java From enforce-sonarqube-plugin with MIT License | 5 votes |
/** * 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); }
Example #25
Source File: InterfaceCommentsCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void interfaceCommentsCheckWs() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new InterfaceCommentsCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkInterfaceCommentsWs/node.ndf"; SourceFile sfCorrect = NodeAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(0, scmCorrect.size()); }
Example #26
Source File: InterfaceCommentsCheckTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void interfaceCommentsCheckValid() { List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new SimpleMetricVisitor()); List<FlowCheck> checks = new ArrayList<FlowCheck>(); checks.add(new InterfaceCommentsCheck()); String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkInterfaceCommentsValid/node.ndf"; SourceFile sfCorrect = NodeAstScanner.scanSingleFile(new File(invalidPath), checks, metrics); Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages(); assertEquals(0, scmCorrect.size()); }
Example #27
Source File: FlowLinesOfCodeVisitorTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void linesOfCodeTest() { logger.debug("Scanning file"); List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); List<FlowCheck> checks = new ArrayList<FlowCheck>(); SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File( "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/checkLinesOfCode/flow.xml"), checks, metrics); int lines = (int) sfCorrect.getDouble(FlowMetric.LINES_OF_CODE); assertEquals(13, lines); }
Example #28
Source File: FlowCommentLinesVisitorTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void commentLinesTest() { logger.debug("Scanning file"); List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); List<FlowCheck> checks = new ArrayList<FlowCheck>(); SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File( "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/commentLinesVisitor/flow.xml"), checks, metrics); int lines = (int) sfCorrect.getDouble(FlowMetric.COMMENT_LINES); assertEquals(2, lines); }
Example #29
Source File: FlowCommentLinesVisitorTest.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void commentLinesTest2() { logger.debug("Scanning file"); List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>(); metrics.add(new FlowCommentLinesVisitor<Grammar>(FlowMetric.COMMENT_LINES)); List<FlowCheck> checks = new ArrayList<FlowCheck>(); SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File( "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest" + "/pub/commentLinesVisitor2/flow.xml"), checks, metrics); int lines = (int) sfCorrect.getDouble(FlowMetric.COMMENT_LINES); assertEquals(0, lines); }
Example #30
Source File: FlowSquidSensor.java From sonar-flow-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void saveClassComplexity(SensorContext context, AstScanner<Grammar> flowScanner, InputFile inputFile, SourceFile squidFile) { Collection<SourceCode> classes = flowScanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceClass.class)); Integer complexityInClasses = 0; for (SourceCode squidClass : classes) { int classComplexity = squidClass.getInt(FlowMetric.INVOKES); complexityInClasses += classComplexity; } context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COMPLEXITY_IN_CLASSES) .withValue(complexityInClasses).save(); }