Search in sources :

Example 1 with AbstractJavadocCheck

use of com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck in project checkstyle by checkstyle.

the class XdocsPagesTest method fixCapturedProperties.

private static void fixCapturedProperties(String sectionName, Object instance, Class<?> clss, Set<String> properties) {
    // remove global properties that don't need documentation
    if (hasParentModule(sectionName)) {
        if (AbstractJavadocCheck.class.isAssignableFrom(clss)) {
            properties.removeAll(JAVADOC_CHECK_PROPERTIES);
            // override
            properties.add("violateExecutionOnNonTightHtml");
        } else if (AbstractCheck.class.isAssignableFrom(clss)) {
            properties.removeAll(CHECK_PROPERTIES);
        }
    }
    if (AbstractFileSetCheck.class.isAssignableFrom(clss)) {
        properties.removeAll(FILESET_PROPERTIES);
        // override
        properties.add("fileExtensions");
    }
    // remove undocumented properties
    new HashSet<>(properties).stream().filter(prop -> UNDOCUMENTED_PROPERTIES.contains(clss.getSimpleName() + "." + prop)).forEach(properties::remove);
    if (AbstractCheck.class.isAssignableFrom(clss)) {
        final AbstractCheck check = (AbstractCheck) instance;
        final int[] acceptableTokens = check.getAcceptableTokens();
        Arrays.sort(acceptableTokens);
        final int[] defaultTokens = check.getDefaultTokens();
        Arrays.sort(defaultTokens);
        final int[] requiredTokens = check.getRequiredTokens();
        Arrays.sort(requiredTokens);
        if (!Arrays.equals(acceptableTokens, defaultTokens) || !Arrays.equals(acceptableTokens, requiredTokens)) {
            properties.add("tokens");
        }
    }
    if (AbstractJavadocCheck.class.isAssignableFrom(clss)) {
        final AbstractJavadocCheck check = (AbstractJavadocCheck) instance;
        final int[] acceptableJavadocTokens = check.getAcceptableJavadocTokens();
        Arrays.sort(acceptableJavadocTokens);
        final int[] defaultJavadocTokens = check.getDefaultJavadocTokens();
        Arrays.sort(defaultJavadocTokens);
        final int[] requiredJavadocTokens = check.getRequiredJavadocTokens();
        Arrays.sort(requiredJavadocTokens);
        if (!Arrays.equals(acceptableJavadocTokens, defaultJavadocTokens) || !Arrays.equals(acceptableJavadocTokens, requiredJavadocTokens)) {
            properties.add("javadocTokens");
        }
    }
}
Also used : Arrays(java.util.Arrays) Array(java.lang.reflect.Array) PropertyUtils(org.apache.commons.beanutils.PropertyUtils) CheckUtil(com.puppycrawl.tools.checkstyle.internal.utils.CheckUtil) AbstractJavadocCheck(com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Document(org.w3c.dom.Document) Map(java.util.Map) TokenUtil(com.puppycrawl.tools.checkstyle.utils.TokenUtil) URI(java.net.URI) ConfigurationLoader(com.puppycrawl.tools.checkstyle.ConfigurationLoader) Path(java.nio.file.Path) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) AbstractCheck(com.puppycrawl.tools.checkstyle.api.AbstractCheck) Collection(java.util.Collection) AbstractFileSetCheck(com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck) Set(java.util.Set) Collectors(java.util.stream.Collectors) IgnoredModulesOptions(com.puppycrawl.tools.checkstyle.ConfigurationLoader.IgnoredModulesOptions) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) XdocUtil(com.puppycrawl.tools.checkstyle.internal.utils.XdocUtil) PropertyDescriptor(java.beans.PropertyDescriptor) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) IntStream(java.util.stream.IntStream) TestUtil(com.puppycrawl.tools.checkstyle.internal.utils.TestUtil) AccessModifierOption(com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption) XdocsPropertyType(com.puppycrawl.tools.checkstyle.XdocsPropertyType) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Node(org.w3c.dom.Node) NoSuchElementException(java.util.NoSuchElementException) XmlUtil(com.puppycrawl.tools.checkstyle.internal.utils.XmlUtil) InputSource(org.xml.sax.InputSource) Properties(java.util.Properties) NodeList(org.w3c.dom.NodeList) PropertiesExpander(com.puppycrawl.tools.checkstyle.PropertiesExpander) Iterator(java.util.Iterator) Files(java.nio.file.Files) ModuleFactory(com.puppycrawl.tools.checkstyle.ModuleFactory) IOException(java.io.IOException) Field(java.lang.reflect.Field) Integer.parseInt(java.lang.Integer.parseInt) File(java.io.File) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) StringReader(java.io.StringReader) ParameterizedType(java.lang.reflect.ParameterizedType) PropertyType(com.puppycrawl.tools.checkstyle.PropertyType) Paths(java.nio.file.Paths) Checker(com.puppycrawl.tools.checkstyle.Checker) BitSet(java.util.BitSet) Collections(java.util.Collections) AbstractJavadocCheck(com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck) AbstractCheck(com.puppycrawl.tools.checkstyle.api.AbstractCheck)

Example 2 with AbstractJavadocCheck

use of com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck in project checkstyle by checkstyle.

the class XdocsPagesTest method validatePropertySectionProperties.

private static void validatePropertySectionProperties(String fileName, String sectionName, Node table, Object instance, Set<String> properties) throws Exception {
    boolean skip = true;
    boolean didJavadocTokens = false;
    boolean didTokens = false;
    for (Node row : XmlUtil.getChildrenElements(table)) {
        final List<Node> columns = new ArrayList<>(XmlUtil.getChildrenElements(row));
        assertWithMessage(fileName + " section '" + sectionName + "' should have the requested columns").that(columns).hasSize(5);
        if (skip) {
            assertWithMessage(fileName + " section '" + sectionName + "' should have the specific title").that(columns.get(0).getTextContent()).isEqualTo("name");
            assertWithMessage(fileName + " section '" + sectionName + "' should have the specific title").that(columns.get(1).getTextContent()).isEqualTo("description");
            assertWithMessage(fileName + " section '" + sectionName + "' should have the specific title").that(columns.get(2).getTextContent()).isEqualTo("type");
            assertWithMessage(fileName + " section '" + sectionName + "' should have the specific title").that(columns.get(3).getTextContent()).isEqualTo("default value");
            assertWithMessage(fileName + " section '" + sectionName + "' should have the specific title").that(columns.get(4).getTextContent()).isEqualTo("since");
            skip = false;
            continue;
        }
        assertWithMessage(fileName + " section '" + sectionName + "' should have token properties last").that(didTokens).isFalse();
        final String propertyName = columns.get(0).getTextContent();
        assertWithMessage(fileName + " section '" + sectionName + "' should not contain the property: " + propertyName).that(properties.remove(propertyName)).isTrue();
        if ("tokens".equals(propertyName)) {
            final AbstractCheck check = (AbstractCheck) instance;
            validatePropertySectionPropertyTokens(fileName, sectionName, check, columns);
            didTokens = true;
        } else if ("javadocTokens".equals(propertyName)) {
            final AbstractJavadocCheck check = (AbstractJavadocCheck) instance;
            validatePropertySectionPropertyJavadocTokens(fileName, sectionName, check, columns);
            didJavadocTokens = true;
        } else {
            assertWithMessage(fileName + " section '" + sectionName + "' should have javadoc token properties next to last, before tokens").that(didJavadocTokens).isFalse();
            validatePropertySectionPropertyEx(fileName, sectionName, instance, columns, propertyName);
        }
        assertWithMessage("%s section '%s' should have a version for %s", fileName, sectionName, propertyName).that(columns.get(4).getTextContent().trim()).isNotEmpty();
        assertWithMessage("%s section '%s' should have a valid version for %s", fileName, sectionName, propertyName).that(columns.get(4).getTextContent().trim()).matches(VERSION);
    }
}
Also used : AbstractJavadocCheck(com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck) AbstractCheck(com.puppycrawl.tools.checkstyle.api.AbstractCheck) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Aggregations

AbstractCheck (com.puppycrawl.tools.checkstyle.api.AbstractCheck)2 AbstractJavadocCheck (com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck)2 ArrayList (java.util.ArrayList)2 Node (org.w3c.dom.Node)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 Checker (com.puppycrawl.tools.checkstyle.Checker)1 ConfigurationLoader (com.puppycrawl.tools.checkstyle.ConfigurationLoader)1 IgnoredModulesOptions (com.puppycrawl.tools.checkstyle.ConfigurationLoader.IgnoredModulesOptions)1 ModuleFactory (com.puppycrawl.tools.checkstyle.ModuleFactory)1 PropertiesExpander (com.puppycrawl.tools.checkstyle.PropertiesExpander)1 PropertyType (com.puppycrawl.tools.checkstyle.PropertyType)1 XdocsPropertyType (com.puppycrawl.tools.checkstyle.XdocsPropertyType)1 AbstractFileSetCheck (com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 AccessModifierOption (com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption)1 CheckUtil (com.puppycrawl.tools.checkstyle.internal.utils.CheckUtil)1 TestUtil (com.puppycrawl.tools.checkstyle.internal.utils.TestUtil)1 XdocUtil (com.puppycrawl.tools.checkstyle.internal.utils.XdocUtil)1 XmlUtil (com.puppycrawl.tools.checkstyle.internal.utils.XmlUtil)1