Skip to content

Commit

Permalink
Issue checkstyle#4870: added UT to ensure multithread annotations on …
Browse files Browse the repository at this point in the history
…modules
  • Loading branch information
rnveach committed Jul 8, 2018
1 parent 5ff596b commit 9af2131
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ci/jsoref-spellchecker/whitelist.words
Expand Up @@ -798,6 +798,7 @@ MSITE
MSONAR
mstudman
MTAGLIST
multi
multicharacter
multiline
Multimap
Expand Down
Expand Up @@ -49,6 +49,7 @@
* checks at each each node.
*
*/
@FileStatefulCheck
public final class TreeWalker extends AbstractFileSetCheck implements ExternalResourceHolder {

/** Default distance between tab stops. */
Expand Down
Expand Up @@ -19,6 +19,7 @@

package com.puppycrawl.tools.checkstyle.checks.annotation;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
Expand All @@ -28,6 +29,7 @@
* The check does verifying that annotations are located on the same line with their targets.
* Verifying with this check is not good practice, but it is using by some style guides.
*/
@StatelessCheck
public class AnnotationOnSameLineCheck extends AbstractCheck {

/** A key is pointing to the warning message text in "messages.properties" file. */
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import java.util.regex.Pattern;

import com.puppycrawl.tools.checkstyle.FileStatefulCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
Expand Down Expand Up @@ -86,6 +87,7 @@
* </p>
*
*/
@FileStatefulCheck
public final class IllegalTypeCheck extends AbstractCheck {

/**
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.List;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
Expand Down Expand Up @@ -66,6 +67,7 @@
*
*
*/
@StatelessCheck
public class AtclauseOrderCheck extends AbstractJavadocCheck {

/**
Expand Down
Expand Up @@ -19,6 +19,7 @@

package com.puppycrawl.tools.checkstyle.checks.javadoc;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
Expand Down Expand Up @@ -69,6 +70,7 @@
* </pre>
*
*/
@StatelessCheck
public class JavadocParagraphCheck extends AbstractJavadocCheck {

/**
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
Expand All @@ -42,6 +43,7 @@
*
*
*/
@StatelessCheck
public class JavadocTagContinuationIndentationCheck extends AbstractJavadocCheck {

/**
Expand Down
Expand Up @@ -19,6 +19,7 @@

package com.puppycrawl.tools.checkstyle.checks.javadoc;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
import com.puppycrawl.tools.checkstyle.utils.JavadocUtil;
Expand All @@ -33,6 +34,7 @@
*
*
*/
@StatelessCheck
public class NonEmptyAtclauseDescriptionCheck extends AbstractJavadocCheck {

/**
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.stream.Collectors;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
Expand Down Expand Up @@ -55,6 +56,7 @@
*
*
*/
@StatelessCheck
public class SingleLineJavadocCheck extends AbstractJavadocCheck {

/**
Expand Down
Expand Up @@ -26,6 +26,7 @@
import java.util.regex.Pattern;

import com.google.common.base.CharMatcher;
import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.DetailNode;
import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
Expand Down Expand Up @@ -63,6 +64,7 @@
*
*
*/
@StatelessCheck
public class SummaryJavadocCheck extends AbstractJavadocCheck {

/**
Expand Down
Expand Up @@ -22,13 +22,15 @@
import java.io.File;
import java.util.regex.Pattern;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.FileText;

/**
* Implementation of a check that looks that matches across multiple lines in
* any file type.
*/
@StatelessCheck
public class RegexpMultilineCheck extends AbstractFileSetCheck {

/** The format of the regular expression to match. */
Expand Down
Expand Up @@ -21,12 +21,14 @@

import java.io.File;

import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.FileText;

/**
* Implementation of a check that looks for a single line in any file type.
*/
@StatelessCheck
public class RegexpSinglelineCheck extends AbstractFileSetCheck {

/** The format of the regular expression to match. */
Expand Down
Expand Up @@ -41,7 +41,10 @@
import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.FileStatefulCheck;
import com.puppycrawl.tools.checkstyle.GlobalStatefulCheck;
import com.puppycrawl.tools.checkstyle.ModuleFactory;
import com.puppycrawl.tools.checkstyle.StatelessCheck;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Configuration;
Expand Down Expand Up @@ -327,6 +330,25 @@ public void testRequiredTokensAreSubsetOfDefaultTokens() throws Exception {
}
}

@Test
public void testAllModulesHaveMultiThreadAnnotation() throws Exception {
for (Class<?> module : CheckUtil.getCheckstyleModules()) {
if (ModuleReflectionUtil.isRootModule(module)
|| ModuleReflectionUtil.isFilterModule(module)
|| ModuleReflectionUtil.isFileFilterModule(module)
|| ModuleReflectionUtil.isTreeWalkerFilterModule(module)) {
continue;
}

Assert.assertTrue(
"module '" + module.getSimpleName()
+ "' must contain a mutli-thread annotation",
module.isAnnotationPresent(GlobalStatefulCheck.class)
|| module.isAnnotationPresent(FileStatefulCheck.class)
|| module.isAnnotationPresent(StatelessCheck.class));
}
}

@Test
public void testAllModulesAreReferencedInConfigFile() throws Exception {
final Set<String> modulesReferencedInConfig = CheckUtil.getConfigCheckStyleModules();
Expand Down

0 comments on commit 9af2131

Please sign in to comment.