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


Java Configuration类代码示例

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


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

示例1: setupChild

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
/**
 * Instantiates, configures and registers a Check that is specified
 * in the provided configuration.
 * @see com.puppycrawl.tools.checkstyle.api.AutomaticBean
 */
public void setupChild(Configuration aChildConf)
    throws CheckstyleException
{
    // TODO: improve the error handing
    final String name = aChildConf.getName();
    final Object module = mModuleFactory.createModule(name);
    if (!(module instanceof AbstractCheckVisitor)) {
        throw new CheckstyleException(
            "ClassFileSet is not allowed as a parent of " + name);
    }
    final AbstractCheckVisitor c = (AbstractCheckVisitor) module;
    c.contextualize(mChildContext);
    c.configure(aChildConf);
    c.init();

    registerCheck(c);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:ClassFileSetCheck.java

示例2: getCheckstyleConfiguration

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void getCheckstyleConfiguration() throws Exception {
    fileSystem.setEncoding(StandardCharsets.UTF_8);
    final Settings settings = new Settings(new PropertyDefinitions(
            new CheckstylePlugin().getExtensions()));
    settings.setProperty(CheckstyleConstants.CHECKER_FILTERS_KEY,
            CheckstyleConstants.CHECKER_FILTERS_DEFAULT_VALUE);

    final RulesProfile profile = RulesProfile.create("sonar way", "java");

    final Rule rule = Rule.create("checkstyle", "CheckStyleRule1", "checkstyle rule one");
    rule.setConfigKey("checkstyle/rule1");
    profile.activateRule(rule, null);

    final CheckstyleConfiguration configuration = new CheckstyleConfiguration(settings,
            new CheckstyleProfileExporter(settings), profile, fileSystem);
    final Configuration checkstyleConfiguration = configuration.getCheckstyleConfiguration();
    assertThat(checkstyleConfiguration).isNotNull();
    assertThat(checkstyleConfiguration.getAttribute("charset")).isEqualTo("UTF-8");
    final File xmlFile = new File("checkstyle.xml");
    assertThat(xmlFile.exists()).isTrue();

    FileUtils.forceDelete(xmlFile);
}
 
开发者ID:checkstyle,项目名称:sonar-checkstyle,代码行数:26,代码来源:CheckstyleConfigurationTest.java

示例3: testEmptyForLoop

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testEmptyForLoop() throws Exception {

    final Class<NoWhitespaceBeforeCheck> clazz = NoWhitespaceBeforeCheck.class;
    final String messageKeyPreceded = "ws.preceded";

    final String[] expected = {
        "12:23: " + getCheckMessage(clazz, messageKeyPreceded, ";"),
        "18:31: " + getCheckMessage(clazz, messageKeyPreceded, ";"),
    };
    final Configuration checkConfig = getModuleConfig("NoWhitespaceBefore");
    final String filePath = getPath("InputNoWhitespaceBeforeEmptyForLoop.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:NoWhitespaceBeforeTest.java

示例4: testExternalResourceIsSavedInCache

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testExternalResourceIsSavedInCache() throws Exception {
    final Configuration config = new DefaultConfiguration("myName");
    final String filePath = temporaryFolder.newFile().getPath();
    final PropertyCacheFile cache = new PropertyCacheFile(config, filePath);

    cache.load();

    final Set<String> resources = new HashSet<String>();
    final String pathToResource = getPath("InputPropertyCacheFileExternal.properties");
    resources.add(pathToResource);
    cache.putExternalResources(resources);

    final MessageDigest digest = MessageDigest.getInstance("SHA-1");
    final URI uri = CommonUtils.getUriByFilename(pathToResource);
    final byte[] input =
            ByteStreams.toByteArray(new BufferedInputStream(uri.toURL().openStream()));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(out);
    oos.writeObject(input);
    digest.update(out.toByteArray());
    final String expected = BaseEncoding.base16().upperCase().encode(digest.digest());

    assertEquals("Hashes are not equal", expected,
            cache.get("module-resource*?:" + pathToResource));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:27,代码来源:PropertyCacheFileTest.java

示例5: testEmptyBlockCatch

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testEmptyBlockCatch() throws Exception {

    final String[] expected = {
        "28: " + getCheckMessage(EmptyCatchBlockCheck.class, "catch.block.empty"),
        "49: " + getCheckMessage(EmptyCatchBlockCheck.class, "catch.block.empty"),
        "71: " + getCheckMessage(EmptyCatchBlockCheck.class, "catch.block.empty"),
        "79: " + getCheckMessage(EmptyCatchBlockCheck.class, "catch.block.empty"),
        "83: " + getCheckMessage(EmptyCatchBlockCheck.class, "catch.block.empty"),
    };

    final Configuration checkConfig = getModuleConfig("EmptyCatchBlock");
    final String filePath = getPath("InputEmptyBlockCatch.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:EmptyCatchBlockTest.java

示例6: createChecker

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的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

示例7: testFlushAndCloseCacheFileOutputStream

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testFlushAndCloseCacheFileOutputStream() throws IOException {
    mockStatic(Closeables.class);
    doNothing().when(Closeables.class);
    Closeables.close(any(FileOutputStream.class), Matchers.eq(false));
    mockStatic(Flushables.class);
    doNothing().when(Flushables.class);
    Flushables.flush(any(FileOutputStream.class), Matchers.eq(false));

    final Configuration config = new DefaultConfiguration("myName");
    final PropertyCacheFile cache = new PropertyCacheFile(config,
        temporaryFolder.newFile().getPath());

    cache.put("CheckedFileName.java", System.currentTimeMillis());
    cache.persist();

    verifyStatic(times(1));
    Closeables.close(any(FileOutputStream.class), Matchers.eq(false));
    verifyStatic(times(1));
    Flushables.flush(any(FileOutputStream.class), Matchers.eq(false));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:22,代码来源:PropertyCacheFileTest.java

示例8: testClassDefault

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testClassDefault() throws Exception {
    final Configuration configuration = getModuleConfig("ClassTypeParameterName");
    final String format = configuration.getAttribute("format");

    final String[] expected = {
        "5:31: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "t", format),
        "13:14: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "foo", format),
        "27:24: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "$foo", format),
    };

    final String filePath = getPath("InputClassTypeParameterName.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(configuration, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:ClassTypeParameterNameTest.java

示例9: testInterfaceDefault

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testInterfaceDefault() throws Exception {
    final Configuration configuration = getModuleConfig("InterfaceTypeParameterName");
    final String format = configuration.getAttribute("format");

    final String[] expected = {
        "48:15: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "Input", format),
        "76:25: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "Request", format),
        "80:25: " + getCheckMessage(configuration.getMessages(), MSG_KEY, "TRequest", format),
    };

    final String filePath = getPath("InputInterfaceTypeParameterName.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(configuration, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:InterfaceTypeParameterNameTest.java

示例10: testEmptyLineSeparator

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testEmptyLineSeparator() throws Exception {

    final Class<EmptyLineSeparatorCheck> clazz = EmptyLineSeparatorCheck.class;
    final String messageKey = "empty.line.separator";

    final String[] expected = {
        "19: " + getCheckMessage(clazz, messageKey, "package"),
        "20: " + getCheckMessage(clazz, messageKey, "import"),
        "33: " + getCheckMessage(clazz, messageKey, "CLASS_DEF"),
        "37: " + getCheckMessage(clazz, messageKey, "STATIC_INIT"),
        "66: " + getCheckMessage(clazz, messageKey, "METHOD_DEF"),
        "75: " + getCheckMessage(clazz, messageKey, "INTERFACE_DEF"),
        "82: " + getCheckMessage(clazz, messageKey, "INSTANCE_INIT"),
        "113: " + getCheckMessage(clazz, messageKey, "CLASS_DEF"),
        "119: " + getCheckMessage(clazz, messageKey, "VARIABLE_DEF"),
    };

    final Configuration checkConfig = getModuleConfig("EmptyLineSeparator");
    final String filePath = getPath("InputEmptyLineSeparator.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:25,代码来源:EmptyLineSeparatorTest.java

示例11: testBadPackageName

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testBadPackageName() throws Exception {

    final String packagePath =
            "com.google.checkstyle.test.chapter5naming.rule521packageNamesCamelCase";
    final Configuration checkConfig = getModuleConfig("PackageName");
    final String format = checkConfig.getAttribute("format");
    final String msg = getCheckMessage(checkConfig.getMessages(), MSG_KEY, packagePath, format);

    final String[] expected = {
        "1:9: " + msg,
    };

    final String filePath = getPath("packageNamesCamelCase", "InputPackageNameBad.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:PackageNameTest.java

示例12: testBadPackageName2

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testBadPackageName2() throws Exception {

    final String packagePath = "com.google.checkstyle.test.chapter5naming.rule521_packagenames";
    final Configuration checkConfig = getModuleConfig("PackageName");
    final String format = checkConfig.getAttribute("format");
    final String msg = getCheckMessage(checkConfig.getMessages(), MSG_KEY, packagePath, format);

    final String[] expected = {
        "1:9: " + msg,
    };

    final String filePath = getPath("_packagenames", "InputBadPackageName2.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:PackageNameTest.java

示例13: testBadPackageName3

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testBadPackageName3() throws Exception {

    final String packagePath = "com.google.checkstyle.test.chapter5naming.rule521$packagenames";
    final Configuration checkConfig = getModuleConfig("PackageName");
    final String format = checkConfig.getAttribute("format");
    final String msg = getCheckMessage(checkConfig.getMessages(), MSG_KEY, packagePath, format);

    final String[] expected = {
        "1:9: " + msg,
    };

    final String filePath = getPath("$packagenames", "InputPackageBadName3.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:PackageNameTest.java

示例14: testCustomMessages

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testCustomMessages() throws Exception {
    final Properties props = new Properties();
    props.setProperty("checkstyle.basedir", "basedir");

    final DefaultConfiguration config =
        (DefaultConfiguration) loadConfiguration(
            "InputConfigurationLoaderCustomMessages.xml", props);

    final Configuration[] children = config.getChildren();
    final Configuration[] grandchildren = children[0].getChildren();

    final String expectedKey = "name.invalidPattern";
    assertTrue("Messages should contain key: " + expectedKey,
        grandchildren[0].getMessages()
        .containsKey(expectedKey));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:ConfigurationLoaderTest.java

示例15: testUnicodeEscapes

import com.puppycrawl.tools.checkstyle.api.Configuration; //导入依赖的package包/类
@Test
public void testUnicodeEscapes() throws Exception {

    final String[] expected = {
        "5: " + getCheckMessage(AvoidEscapedUnicodeCharactersCheck.class, MSG_KEY),
        "15: " + getCheckMessage(AvoidEscapedUnicodeCharactersCheck.class, MSG_KEY),
        "25: " + getCheckMessage(AvoidEscapedUnicodeCharactersCheck.class, MSG_KEY),
        "33: " + getCheckMessage(AvoidEscapedUnicodeCharactersCheck.class, MSG_KEY),
        "35: " + getCheckMessage(AvoidEscapedUnicodeCharactersCheck.class, MSG_KEY),
        "36: " + getCheckMessage(AvoidEscapedUnicodeCharactersCheck.class, MSG_KEY),
    };

    final Configuration checkConfig = getModuleConfig("AvoidEscapedUnicodeCharacters");
    final String filePath = getPath("InputAvoidEscapedUnicodeCharacters.java");

    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:AvoidEscapedUnicodeCharactersTest.java


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