OpenEdgeCodeColorizer implements Sensor { @Override public void execute(SensorContext context) { if (context.runtime().getProduct() == SonarProduct.SONARLINT) return; settings.init(); IRefactorSessionEnv sessions = settings.getProparseSessions(); for (InputFile file : context.fileSystem().inputFiles( context.fileSystem().predicates().hasLanguage(Constants.LANGUAGE_KEY))) { LOG.debug("Syntax highlight on {}", file); IProparseEnvironment session = sessions.getSession(file.relativePath()); try { highlightFile(context, session, file); } catch (UncheckedIOException | ProparseRuntimeException caught) { if (caught.getCause() instanceof XCodedFileException) { LOG.error("Unable to highlight xcode'd file '{}", file); } else { LOG.error("Unable to lex file '{}'", file, caught); } } } } OpenEdgeCodeColorizer(OpenEdgeSettings settings); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context);  }
@Test public void testSp2k() throws Exception { SensorContextTester context = TestProjectSensorContext.createContext(); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); OpenEdgeCodeColorizer sensor = new OpenEdgeCodeColorizer(oeSettings); sensor.execute(context); Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE1, 1, 10)); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE1, 1, 10).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE1, 1, 10).get(0), TypeOfText.COMMENT); Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 13)); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 13).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 13).get(0), TypeOfText.STRING); Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 5)); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 5).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE2, 5, 5).get(0), TypeOfText.KEYWORD); Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 3, 25)); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 3, 25).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 3, 25).get(0), TypeOfText.PREPROCESS_DIRECTIVE); Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 10)); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 10).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 10).get(0), TypeOfText.STRING); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 4, 16).size(), 0); Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 14, 9)); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 14, 9).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 14, 9).get(0), TypeOfText.CONSTANT); Assert.assertNotNull(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 3)); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 3).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 3).get(0), TypeOfText.PREPROCESS_DIRECTIVE); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 20).size(), 1); Assert.assertEquals(context.highlightingTypeAt(BASEDIR + ":" + FILE3, 21, 20).get(0), TypeOfText.PREPROCESS_DIRECTIVE); }