use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class BaseCheckTestSupport method createChecker.
/**
* Creates {@link Checker} instance based on specified {@link Configuration}.
* @param checkConfig {@link Configuration} instance.
* @return {@link Checker} instance.
* @throws CheckstyleException if an exception occurs during checker configuration.
*/
protected Checker createChecker(Configuration checkConfig) throws Exception {
final DefaultConfiguration dc = createCheckerConfig(checkConfig);
final Checker checker = new Checker();
// make sure the tests always run with English error messages
// so the tests don't fail in supported locales like German
final Locale locale = Locale.ENGLISH;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(dc);
checker.addListener(new BriefUtLogger(stream));
return checker;
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class SuppressionCommentFilterTest method createChecker.
@Override
public Checker createChecker(Configuration checkConfig) throws CheckstyleException {
final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
checksConfig.addChild(createCheckConfig(FileContentsHolder.class));
final DefaultConfiguration memberNameCheckConfig = createCheckConfig(MemberNameCheck.class);
memberNameCheckConfig.addAttribute("id", "ignore");
checksConfig.addChild(memberNameCheckConfig);
final DefaultConfiguration constantNameCheckConfig = createCheckConfig(ConstantNameCheck.class);
constantNameCheckConfig.addAttribute("id", null);
checksConfig.addChild(constantNameCheckConfig);
checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class));
checkerConfig.addChild(checksConfig);
if (checkConfig != null) {
checkerConfig.addChild(checkConfig);
}
final Checker checker = new Checker();
final Locale locale = Locale.ROOT;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefUtLogger(stream));
return checker;
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class SuppressionFilterTest method testLocalFileExternalResourceContentDoesNotChange.
@Test
public void testLocalFileExternalResourceContentDoesNotChange() throws Exception {
final DefaultConfiguration filterConfig = createCheckConfig(SuppressionFilter.class);
filterConfig.addAttribute("file", getPath("suppressions_none.xml"));
final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
checkerConfig.addChild(filterConfig);
final String cacheFile = temporaryFolder.newFile().getPath();
checkerConfig.addAttribute("cacheFile", cacheFile);
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.addListener(new BriefUtLogger(stream));
checker.configure(checkerConfig);
final String filePath = temporaryFolder.newFile("file.java").getPath();
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checker, filePath, expected);
// One more time to use cache.
verify(checker, filePath, expected);
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilterTest method createChecker.
@Override
public Checker createChecker(Configuration checkConfig) throws CheckstyleException {
final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
checksConfig.addChild(createCheckConfig(FileContentsHolder.class));
final DefaultConfiguration memberNameCheckConfig = createCheckConfig(MemberNameCheck.class);
memberNameCheckConfig.addAttribute("id", "ignore");
checksConfig.addChild(memberNameCheckConfig);
final DefaultConfiguration constantNameCheckConfig = createCheckConfig(ConstantNameCheck.class);
constantNameCheckConfig.addAttribute("id", null);
checksConfig.addChild(constantNameCheckConfig);
checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class));
checkerConfig.addChild(checksConfig);
if (checkConfig != null) {
checkerConfig.addChild(checkConfig);
}
final Checker checker = new Checker();
final Locale locale = Locale.ROOT;
checker.setLocaleCountry(locale.getCountry());
checker.setLocaleLanguage(locale.getLanguage());
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(new BriefUtLogger(stream));
return checker;
}
use of com.puppycrawl.tools.checkstyle.Checker in project checkstyle by checkstyle.
the class TranslationCheckTest method testLogIoExceptionFileNotFound.
@Test
public void testLogIoExceptionFileNotFound() throws Exception {
//I can't put wrong file here. Checkstyle fails before check started.
//I saw some usage of file or handling of wrong file in Checker, or somewhere
//in checks running part. So I had to do it with reflection to improve coverage.
final TranslationCheck check = new TranslationCheck();
final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class);
check.configure(checkConfig);
final Checker checker = createChecker(checkConfig);
check.setMessageDispatcher(checker);
final Method loadKeys = check.getClass().getDeclaredMethod("getTranslationKeys", File.class);
loadKeys.setAccessible(true);
loadKeys.invoke(check, new File(""));
}
Aggregations