当前位置: 首页>>代码示例>>Java>>正文


Java Checker类代码示例

本文整理汇总了Java中com.puppycrawl.tools.checkstyle.Checker的典型用法代码示例。如果您正苦于以下问题:Java Checker类的具体用法?Java Checker怎么用?Java Checker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Checker类属于com.puppycrawl.tools.checkstyle包,在下文中一共展示了Checker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verify

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
protected void verify(Checker checker, File[] processedFiles, String messageFileName, String... expectedErrorTexts)
		throws Exception {
	this.stream.flush();
	int numberOfErrors = checker.process(Arrays.asList(processedFiles));

	LineNumberReader errors = new LineNumberReader(
			new InputStreamReader(new ByteArrayInputStream(this.stream.toByteArray())));

	for (int i = 0; i < expectedErrorTexts.length; ++i) {
		String actual = errors.readLine();
		assertThat(actual).as("error message %s", i).contains(expectedErrorTexts[i]);
	}

	assertThat(numberOfErrors).as("got unexpected error count with error message: %s", errors.readLine())
			.isEqualTo(expectedErrorTexts.length);

	checker.destroy();
}
 
开发者ID:NovaTecConsulting,项目名称:stereotype-check,代码行数:19,代码来源:AbstractStereotypeCheckTest.java

示例2: createChecker

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
/**
 * Creates {@link Checker} instance based on the given {@link Configuration} instance.
 * @param moduleConfig {@link Configuration} instance.
 * @return {@link Checker} instance based on the given {@link Configuration} instance.
 * @throws Exception if an exception occurs during checker configuration.
 */
public final Checker createChecker(Configuration moduleConfig)
        throws Exception {
    if (checkstyleModules == null) {
        checkstyleModules = CheckUtil.getCheckstyleModules();
    }

    final String name = moduleConfig.getName();
    ModuleCreationOption moduleCreationOption = ModuleCreationOption.IN_CHECKER;

    for (Class<?> moduleClass : checkstyleModules) {
        if (moduleClass.getSimpleName().equals(name)
                || moduleClass.getSimpleName().equals(name + "Check")) {
            if (ModuleReflectionUtils.isCheckstyleTreeWalkerCheck(moduleClass)
                    || ModuleReflectionUtils.isTreeWalkerFilterModule(moduleClass)) {
                moduleCreationOption = ModuleCreationOption.IN_TREEWALKER;
            }
            break;
        }
    }

    return createChecker(moduleConfig, moduleCreationOption);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:29,代码来源:AbstractModuleTestSupport.java

示例3: testIsSuppressedWithAllArgument

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
@Test
public void testIsSuppressedWithAllArgument() throws Exception {
    createHolder("all", 100, 100, 350, 350);

    final Checker source = new Checker();
    final LocalizedMessage firstMessageForTest =
        new LocalizedMessage(100, 10, null, null, null, "id", MemberNameCheck.class, "msg");
    final AuditEvent firstEventForTest =
        new AuditEvent(source, "fileName", firstMessageForTest);
    assertFalse("Event is suppressed",
            SuppressWarningsHolder.isSuppressed(firstEventForTest));

    final LocalizedMessage secondMessageForTest =
        new LocalizedMessage(100, 150, null, null, null, "id", MemberNameCheck.class, "msg");
    final AuditEvent secondEventForTest =
        new AuditEvent(source, "fileName", secondMessageForTest);
    assertTrue("Event is not suppressed",
            SuppressWarningsHolder.isSuppressed(secondEventForTest));

    final LocalizedMessage thirdMessageForTest =
        new LocalizedMessage(200, 1, null, null, null, "id", MemberNameCheck.class, "msg");
    final AuditEvent thirdEventForTest =
        new AuditEvent(source, "fileName", thirdMessageForTest);
    assertTrue("Event is not suppressed",
            SuppressWarningsHolder.isSuppressed(thirdEventForTest));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:SuppressWarningsHolderTest.java

示例4: testLogIoExceptionFileNotFound

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
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 = createModuleConfig(TranslationCheck.class);
    check.configure(checkConfig);
    final Checker checker = createChecker(checkConfig);
    final SeverityLevelCounter counter = new SeverityLevelCounter(SeverityLevel.ERROR);
    checker.addListener(counter);
    check.setMessageDispatcher(checker);

    final Method loadKeys =
        check.getClass().getDeclaredMethod("getTranslationKeys", File.class);
    loadKeys.setAccessible(true);
    final Set<String> keys = (Set<String>) loadKeys.invoke(check, new File(""));
    assertTrue("Translation keys should be empty when File is not found", keys.isEmpty());
    assertEquals("Invalid error count", 1, counter.getCount());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:TranslationCheckTest.java

示例5: testBeginTreeClear

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
@Test
public void testBeginTreeClear() throws Exception {
    final DefaultConfiguration checkConfig =
        createModuleConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("specialImportsRegExp", "com");
    checkConfig.addAttribute("separateLineBetweenGroups", "false");
    checkConfig.addAttribute("customImportOrderRules",
        "STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS");
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    final Checker checker = createChecker(checkConfig);
    final String fileName1 = getPath("InputCustomImportOrderImportsContainingJava.java");
    final String fileName2 = getPath("InputCustomImportOrderNoValid.java");
    final File[] files = {
        new File(fileName1),
        new File(fileName2),
    };
    verify(checker, files, fileName1, expected);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:CustomImportOrderCheckTest.java

示例6: testAllModulesWithDefaultConfiguration

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
@Test
public void testAllModulesWithDefaultConfiguration() throws Exception {
    final String inputFilePath = getPath("InputAllChecksDefaultConfig.java");
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;

    for (Class<?> module : CheckUtil.getCheckstyleModules()) {
        if (ModuleReflectionUtils.isRootModule(module)) {
            continue;
        }

        final DefaultConfiguration moduleConfig = createModuleConfig(module);
        final Checker checker;
        if (module.equals(ImportControlCheck.class)) {
            // ImportControlCheck must have the import control configuration file to avoid
            // violation.
            moduleConfig.addAttribute("file", getPath(
                    "InputAllChecksImportControl.xml"));
        }
        checker = createChecker(moduleConfig);
        verify(checker, inputFilePath, expected);
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:23,代码来源:AllChecksTest.java

示例7: verify

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
private void verify(Checker checker, File[] processedFiles, String messageFileName,
                    String[] expected) throws Exception {
  printStream.flush();
  List<File> testInputFiles = Lists.newArrayList(processedFiles);
  int foundErrorsCount = checker.process(testInputFiles);

  // Process each output line
  ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  BufferedReader br = new BufferedReader(new InputStreamReader(bais));

  try {
    for (int i = 0; i < expected.length; i++) {
      final String expectedResult = messageFileName + ":" + expected[i];
      final String actual = br.readLine();
      assertEquals("error message " + i, expectedResult, actual);
    }

    assertEquals("Check generated unexpected warning: " + br.readLine(), expected.length,
                 foundErrorsCount);
    checker.destroy();
  } finally {
    br.close();
    bais.close();
  }
}
 
开发者ID:startupheroes,项目名称:startupheroes-checkstyle,代码行数:26,代码来源:BaseCheckTestSupport.java

示例8: verify

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
protected void verify(Checker checker, File[] processedFiles, String messageFileName,
                      String[] expected) throws Exception {
    printStream.flush();
    List<File> testInputFiles = Lists.newArrayList(processedFiles);
    int foundErrorsCount = checker.process(testInputFiles);

    // Process each output line
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    BufferedReader br = new BufferedReader(new InputStreamReader(bais));

    try {
        for (int i = 0; i < expected.length; i++) {
            final String expectedResult = messageFileName + ":" + expected[i];
            final String actual = br.readLine();
            assertEquals("error message " + i, expectedResult, actual);
        }

        assertEquals("Check generated unexpected warning: " + br.readLine(), expected.length, foundErrorsCount);
        checker.destroy();
    } finally {
        br.close();
        bais.close();
    }
}
 
开发者ID:winterDroid,项目名称:droidcon_nyc,代码行数:25,代码来源:BaseCheckTestSupport.java

示例9: createChecker

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
protected Checker createChecker(final Configuration pCheckConfig)
    throws Exception
{
    final DefaultConfiguration dc = createCheckerConfig(pCheckConfig);
    final Checker c = 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;
    c.setLocaleCountry(locale.getCountry());
    c.setLocaleLanguage(locale.getLanguage());
    c.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    c.configure(dc);
    c.addListener(new BriefLogger(mStream));
    return c;
}
 
开发者ID:checkstyle-addons,项目名称:checkstyle-addons,代码行数:17,代码来源:BaseCheckTestSupport.java

示例10: CheckstyleValidator

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
/**
 * Constructor.
 * @param env Environment to use.
 */
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
public CheckstyleValidator(final Environment env) {
    this.checker = new Checker();
    this.checker.setClassLoader(env.classloader());
    this.checker.setModuleClassLoader(
        Thread.currentThread().getContextClassLoader()
    );
    try {
        this.checker.configure(this.configuration(env));
    } catch (final CheckstyleException ex) {
        throw new IllegalStateException("Failed to configure checker", ex);
    }
    this.listener = new CheckstyleListener(env);
    this.checker.addListener(this.listener);
}
 
开发者ID:teamed,项目名称:qulice,代码行数:20,代码来源:CheckstyleValidator.java

示例11: createChecker

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
/**
 * Creates {@link Checker} instance based on the given {@link Configuration} instance.
 * @param moduleConfig {@link Configuration} instance.
 * @return {@link Checker} instance based on the given {@link Configuration} instance.
 * @throws Exception if an exception occurs during checker configuration.
 */
public final Checker createChecker(Configuration moduleConfig)
        throws Exception {
    final String name = moduleConfig.getName();
    ModuleCreationOption moduleCreationOption = ModuleCreationOption.IN_CHECKER;

    for (Class<?> moduleClass : CHECKSTYLE_MODULES) {
        if (moduleClass.getSimpleName().equals(name)
                || moduleClass.getSimpleName().equals(name + "Check")) {
            if (ModuleReflectionUtils.isCheckstyleTreeWalkerCheck(moduleClass)
                    || ModuleReflectionUtils.isTreeWalkerFilterModule(moduleClass)) {
                moduleCreationOption = ModuleCreationOption.IN_TREEWALKER;
            }
            break;
        }
    }

    return createChecker(moduleConfig, moduleCreationOption);
}
 
开发者ID:checkstyle,项目名称:checkstyle,代码行数:25,代码来源:AbstractModuleTestSupport.java

示例12: verify

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
protected void verify(final Checker aC, final File[] aProcessedFiles, final String aMessageFileName, final String[] aExpected) throws Exception {
    this.mStream.flush();
    final List<File> theFiles = Lists.newArrayList();
    Collections.addAll(theFiles, aProcessedFiles);
    final int errs = aC.process(theFiles);

    // process each of the lines
    final ByteArrayInputStream bais = new ByteArrayInputStream(this.mBAOS.toByteArray());
    final LineNumberReader lnr = new LineNumberReader(new InputStreamReader(bais));

    for (int i = 0; i < aExpected.length; i++) {
        final String expected = aMessageFileName + ":" + aExpected[i];
        final String actual = lnr.readLine();
        Assert.assertEquals("error message " + i, expected, actual);
    }

    Assert.assertEquals("unexpected output: " + lnr.readLine(), aExpected.length, errs);
    aC.destroy();
}
 
开发者ID:shmc,项目名称:sonar-spring-rules-plugin,代码行数:20,代码来源:RequiredPropertyCheckTest.java

示例13: auditStarted

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */
public void auditStarted(AuditEvent aEvt)
{
    if (mInitialized) {
        final Log log = mLogFactory.getInstance(Checker.class);
        log.info("Audit started.");
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:CommonsLoggingListener.java

示例14: auditFinished

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */
public void auditFinished(AuditEvent aEvt)
{
    if (mInitialized) {
        final Log log = mLogFactory.getInstance(Checker.class);
        log.info("Audit finished.");
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:CommonsLoggingListener.java

示例15: fileStarted

import com.puppycrawl.tools.checkstyle.Checker; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.AuditListener */
public void fileStarted(AuditEvent aEvt)
{
    if (mInitialized) {
        final Log log = mLogFactory.getInstance(Checker.class);
        log.info("File \"" + aEvt.getFileName() + "\" started.");
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:CommonsLoggingListener.java


注:本文中的com.puppycrawl.tools.checkstyle.Checker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。