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


Java CommonUtils类代码示例

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


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

示例1: testInvalidInfluenceFormat

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testInvalidInfluenceFormat() throws Exception {
    final DefaultConfiguration filterConfig =
        createModuleConfig(SuppressWithNearbyCommentFilter.class);
    filterConfig.addAttribute("influenceFormat", "a");

    try {
        final String[] suppressed = CommonUtils.EMPTY_STRING_ARRAY;
        verifySuppressed(filterConfig, suppressed);
        fail("Exception is expected");
    }
    catch (CheckstyleException ex) {
        final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
        assertEquals("Invalid exception message", "unable to parse influence"
            + " from 'SUPPRESS CHECKSTYLE MemberNameCheck' using a", cause.getMessage());
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:SuppressWithNearbyCommentFilterTest.java

示例2: verifyThreadsNumberParameter

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
/**
 * Verifies threads number CLI parameter value.
 * @param cmdLine a command line
 * @param result a resulting list of errors
 * @param cliParameterName a CLI parameter name
 * @param mustBeGreaterThanZeroMessage a message which should be reported
 *                                     if the number of threads is less than or equal to zero
 * @param invalidNumberMessage a message which should be reported if the passed value
 *                             is not a valid number
 */
private static void verifyThreadsNumberParameter(CommandLine cmdLine, List<String> result,
    String cliParameterName, String mustBeGreaterThanZeroMessage,
    String invalidNumberMessage) {
    if (cmdLine.hasOption(cliParameterName)) {
        final String checkerThreadsNumberStr =
            cmdLine.getOptionValue(cliParameterName);
        if (CommonUtils.isInt(checkerThreadsNumberStr)) {
            final int checkerThreadsNumber = Integer.parseInt(checkerThreadsNumberStr);
            if (checkerThreadsNumber < 1) {
                result.add(mustBeGreaterThanZeroMessage);
            }
        }
        else {
            result.add(invalidNumberMessage);
        }
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:28,代码来源:Main.java

示例3: testInvalidMessageFormat

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testInvalidMessageFormat() throws Exception {
    final DefaultConfiguration filterConfig =
        createModuleConfig(SuppressionCommentFilter.class);
    filterConfig.addAttribute("messageFormat", "e[l");

    try {
        final String[] suppressed = CommonUtils.EMPTY_STRING_ARRAY;
        verifySuppressed(filterConfig, suppressed);
        fail("Exception is expected");
    }
    catch (CheckstyleException ex) {
        final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
        assertEquals("Invalid exception message",
            "unable to parse expanded comment e[l", cause.getMessage());
    }

}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:SuppressionCommentFilterTest.java

示例4: testExcludedPackagesAllIgnored

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testExcludedPackagesAllIgnored() throws Exception {
    final DefaultConfiguration checkConfig =
        createModuleConfig(ClassFanOutComplexityCheck.class);

    checkConfig.addAttribute("max", "0");
    checkConfig.addAttribute("excludedPackages",
        "com.puppycrawl.tools.checkstyle.checks.metrics.classfanoutcomplexity.inputs.a.aa,"
            + "com.puppycrawl.tools.checkstyle.checks.metrics.classfanoutcomplexity."
                + "inputs.a.ab,"
            + "com.puppycrawl.tools.checkstyle.checks.metrics.classfanoutcomplexity.inputs.b,"
            + "com.puppycrawl.tools.checkstyle.checks.metrics.classfanoutcomplexity.inputs.c");

    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checkConfig,
        getPath("InputClassFanOutComplexityExcludedPackagesAllIgnored.java"), expected);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:ClassFanOutComplexityCheckTest.java

示例5: testTranslationFileWithLanguageCountryVariantArePresent

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testTranslationFileWithLanguageCountryVariantArePresent() throws Exception {
    final DefaultConfiguration checkConfig = createModuleConfig(TranslationCheck.class);
    checkConfig.addAttribute("requiredTranslations", "es, fr");

    final File[] propertyFiles = {
        new File(getPath("messages_home.properties")),
        new File(getPath("messages_home_es_US.properties")),
        new File(getPath("messages_home_fr_CA_UNIX.properties")),
        };

    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(
        createChecker(checkConfig),
        propertyFiles,
        getPath(""),
        expected);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:19,代码来源:TranslationCheckTest.java

示例6: testCacheWhenFileExternalResourceContentDoesNotChange

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testCacheWhenFileExternalResourceContentDoesNotChange() throws Exception {
    final DefaultConfiguration filterConfig = createModuleConfig(SuppressionXpathFilter.class);
    filterConfig.addAttribute("file", getPath("InputTreeWalkerSuppressionXpathFilter.xml"));
    final DefaultConfiguration treeWalkerConfig = createModuleConfig(TreeWalker.class);
    treeWalkerConfig.addChild(filterConfig);

    final DefaultConfiguration checkerConfig = createRootConfig(treeWalkerConfig);
    final File cacheFile = temporaryFolder.newFile();
    checkerConfig.addAttribute("cacheFile", cacheFile.getPath());

    final String filePath = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;

    verify(checkerConfig, filePath, expected);
    // One more time to use cache.
    verify(checkerConfig, filePath, expected);

    assertTrue("External resource is not present in cache",
            new String(Files7.readAllBytes(new Path(cacheFile)),
                    StandardCharsets.UTF_8).contains(
                            "InputTreeWalkerSuppressionXpathFilter.xml"));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:TreeWalkerTest.java

示例7: testSamePackageDepthNotInt

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testSamePackageDepthNotInt() throws Exception {
    final DefaultConfiguration checkConfig =
            createModuleConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("customImportOrderRules", "SAME_PACKAGE(INT_IS_REQUIRED_HERE)");
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true");

    try {
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;

        verify(checkConfig, getPath("InputCustomImportOrderDefault.java"), expected);
        fail("exception expected");
    }
    catch (CheckstyleException ex) {
        final String messageStart =
            "cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - "
                + "Cannot set property 'customImportOrderRules' to "
                + "'SAME_PACKAGE(INT_IS_REQUIRED_HERE)' in module";
        assertTrue("Invalid exception message, should start with: " + messageStart,
            ex.getMessage().startsWith(messageStart));
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:23,代码来源:CustomImportOrderCheckTest.java

示例8: testAnyNewlineAtEndOfFile

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testAnyNewlineAtEndOfFile() throws Exception {
    final DefaultConfiguration checkConfig =
        createModuleConfig(NewlineAtEndOfFileCheck.class);
    checkConfig.addAttribute("lineSeparator", LineSeparatorOption.LF_CR_CRLF.toString());
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(
        createChecker(checkConfig),
        getPath("InputNewlineAtEndOfFileCrlf.java"),
        expected);
    verify(
        createChecker(checkConfig),
        getPath("InputNewlineAtEndOfFileLf.java"),
        expected);
    verify(
        createChecker(checkConfig),
        getPath("InputNewlineAtEndOfFileCr.java"),
        expected);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:20,代码来源:NewlineAtEndOfFileCheckTest.java

示例9: testValidDoWhileWithChecker

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testValidDoWhileWithChecker()
        throws Exception {
    final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);

    checkConfig.addAttribute("arrayInitIndent", "4");
    checkConfig.addAttribute("basicOffset", "4");
    checkConfig.addAttribute("braceAdjustment", "0");
    checkConfig.addAttribute("caseIndent", "4");
    checkConfig.addAttribute("forceStrictCondition", "false");
    checkConfig.addAttribute("lineWrappingIndentation", "4");
    checkConfig.addAttribute("tabWidth", "4");
    checkConfig.addAttribute("throwsIndent", "4");
    final String fileName = getPath("InputIndentationValidDoWhileIndent.java");
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verifyWarns(checkConfig, fileName, expected);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:IndentationCheckTest.java

示例10: testGetDefaultTokens

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testGetDefaultTokens() {
    final ModifierOrderCheck modifierOrderCheckObj = new ModifierOrderCheck();
    final int[] actual = modifierOrderCheckObj.getDefaultTokens();
    final int[] expected = {TokenTypes.MODIFIERS};
    final int[] unexpectedArray = {
        TokenTypes.MODIFIERS,
        TokenTypes.OBJBLOCK,
    };
    assertArrayEquals("Default tokens are invalid", expected, actual);
    final int[] unexpectedEmptyArray = CommonUtils.EMPTY_INT_ARRAY;
    Assert.assertNotSame("Default tokens should not be empty array",
            unexpectedEmptyArray, actual);
    Assert.assertNotSame("Invalid default tokens", unexpectedArray, actual);
    Assert.assertNotNull("Default tokens should not be null", actual);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:17,代码来源:ModifierOrderCheckTest.java

示例11: log

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
/**
 * Helper method to log a LocalizedMessage.
 *
 * @param ast a node to get line id column numbers associated
 *             with the message
 * @param key key to locale message format
 * @param args arguments to format
 */
public final void log(DetailAST ast, String key, Object... args) {

    // CommonUtils.lengthExpandedTabs returns column number considering tabulation
    // characters, it takes line from the file by line number, ast column number and tab
    // width as arguments. Returned value is 0-based, but user must see column number starting
    // from 1, that is why result of the method CommonUtils.lengthExpandedTabs
    // is increased by one.

    final int col = 1 + CommonUtils.lengthExpandedTabs(
            getLines()[ast.getLineNo() - 1], ast.getColumnNo(), tabWidth);
    context.get().messages.add(
            new LocalizedMessage(
                    ast.getLineNo(),
                    col,
                    ast.getColumnNo(),
                    ast.getType(),
                    getMessageBundle(),
                    key,
                    args,
                    getSeverityLevel(),
                    getId(),
                    getClass(),
                    getCustomMessages().get(key)));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:33,代码来源:AbstractCheck.java

示例12: testStateIsClearedOnBeginTree1

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testStateIsClearedOnBeginTree1()
        throws Exception {
    final DefaultConfiguration checkConfig = createModuleConfig(RedundantImportCheck.class);
    final String inputWithWarnings = getPath("InputRedundantImportCheckClearState.java");
    final String inputWithoutWarnings = getPath("InputRedundantImportWithoutWarnings.java");
    final List<String> expectedFirstInput = Arrays.asList(
        "4:1: " + getCheckMessage(MSG_DUPLICATE, 3, "java.util.Arrays.asList"),
        "7:1: " + getCheckMessage(MSG_DUPLICATE, 6, "java.util.List")
    );
    final List<String> expectedSecondInput = Arrays.asList(CommonUtils.EMPTY_STRING_ARRAY);
    final File[] inputs = {new File(inputWithWarnings), new File(inputWithoutWarnings)};

    verify(createChecker(checkConfig), inputs, ImmutableMap.of(
        inputWithWarnings, expectedFirstInput,
        inputWithoutWarnings, expectedSecondInput));
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:18,代码来源:RedundantImportCheckTest.java

示例13: testGetRequiredTokens

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testGetRequiredTokens() {
    final MethodParamPadCheck checkObj = new MethodParamPadCheck();
    assertArrayEquals(
        "MethodParamPadCheck#getRequiredTockens should return empty array by default",
        CommonUtils.EMPTY_INT_ARRAY, checkObj.getRequiredTokens());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:8,代码来源:MethodParamPadCheckTest.java

示例14: testStaticMethodInInterface

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testStaticMethodInInterface()
        throws Exception {
    final DefaultConfiguration checkConfig =
            createModuleConfig(ConstantNameCheck.class);
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checkConfig, getPath("InputConstantNameStaticModifierInInterface.java"), expected);
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:9,代码来源:ConstantNameCheckTest.java

示例15: testGetRequiredTokens

import com.puppycrawl.tools.checkstyle.utils.CommonUtils; //导入依赖的package包/类
@Test
public void testGetRequiredTokens() {
    final AnnotationLocationCheck checkObj = new AnnotationLocationCheck();
    assertArrayEquals(
        "AnnotationLocationCheck#getRequiredTockens should return empty array by default",
        CommonUtils.EMPTY_INT_ARRAY, checkObj.getRequiredTokens());
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:8,代码来源:AnnotationLocationCheckTest.java


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