public void analyse(Project project, SensorContext context) { this.project = project; this.context = context; Collection<SquidAstVisitor<LexerlessGrammar>> squidChecks = annotationCheckFactory.getChecks(); List<SquidAstVisitor<LexerlessGrammar>> visitors = Lists.newArrayList(squidChecks); visitors.add(new FileLinesVisitor(project, fileLinesContextFactory)); this.scanner = FlexAstScanner.create( createConfiguration(project), visitors.toArray(new SquidAstVisitor[visitors.size()])); Collection<java.io.File> files = InputFileUtils.toFiles(project.getFileSystem().mainFiles(Flex.KEY)); files = ImmutableList.copyOf(Collections2.filter(files, Predicates.not(MXML_FILTER))); scanner.scanFiles(files); Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class)); save(squidSourceFiles); Collection<SourceCode> squidPackages = scanner.getIndex().search(new QueryByType(FlexSquidPackage.class)); for (SourceCode pkg : squidPackages) { String packageName = pkg.getKey(); if (!"".equals(packageName)) { Directory directory = resourceBridge.findDirectory(packageName); context.saveMeasure(directory, CoreMetrics.PACKAGES, 1.0); } } }
@Test public void test() { TraceUseCheck check = new TraceUseCheck(); SourceFile file = FlexAstScanner.scanSingleFile(new File("src/test/resources/checks/TraceUse.as"), check); CheckMessagesVerifier.verify(file.getCheckMessages()) .next() .atLine(1) .withMessage("Remove this use of the \"trace\" function.") .noMore(); }
@Test public void test() { SourceFile file = FlexAstScanner.scanSingleFile(new File("src/test/resources/checks/StarTypeUse.as"), check); CheckMessagesVerifier.verify(file.getCheckMessages()) .next() .atLine(5) .withMessage("Remove usage of this \"star\" type") .next() .atLine(6) .noMore(); }
@Test public void test() { SourceFile file = FlexAstScanner.scanSingleFile( new File("src/test/resources/checks/ManagedEventTagWithEvent.as"), check); CheckMessagesVerifier.verify(file.getCheckMessages()) .next() .atLine(2) .withMessage( "The managed event \"mes\" is either misspelled or is missing a companion Event metadata tag") .next() .atLine(7) .withMessage( "The managed event \"click\" is either misspelled or is missing a companion Event metadata tag") .noMore(); }
@Test public void test() { ActionScript2Check check = new ActionScript2Check(); SourceFile file = FlexAstScanner.scanSingleFile( new File("src/test/resources/checks/ActionScript2.as"), check); CheckMessagesVerifier.verify(file.getCheckMessages()) .next() .atLine(1) .withMessage("'intrinsic' not available in ActionScript 3.0") .next() .atLine(2) .withMessage("Operator '<>' not available in ActionScript 3.0") .next() .atLine(4) .withMessage("Operator 'not' not available in ActionScript 3.0") .next() .atLine(6) .withMessage("'set variable statement' not available in ActionScript 3.0") .noMore(); }