Class OneTopLevelClassCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class OneTopLevelClassCheck
    extends AbstractCheck
    Checks that each top-level class, interface or enum resides in a source file of its own.

    Official description of a 'top-level' term: 7.6. Top Level Type Declarations. If file doesn't contains public class, enum or interface, top-level type is the first type in file.

    An example of code with violations:

    
     public class Foo{
         //methods
     }
    
     class Foo2{
         //methods
     }
     

    An example of code without top-level public type:

    
     class Foo{ //top-level class
         //methods
     }
    
     class Foo2{
         //methods
     }
     

    An example of check's configuration:

     <module name="OneTopLevelClass"/>
     

    An example of code without violations:

    
     public class Foo{
         //methods
     }
     

    ATTENTION: This Check does not support customization of validated tokens, so do not use the "tokens" property.

    Author:
    maxvetrenko
    • Method Detail

      • getAcceptableTokens

        public int[] getAcceptableTokens()
        Description copied from class: AbstractCheck
        The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.
        Specified by:
        getAcceptableTokens in class AbstractCheck
        Returns:
        the token set this check is designed for.
        See Also:
        TokenTypes
      • beginTree

        public void beginTree​(DetailAST rootAST)
        Description copied from class: AbstractCheck
        Called before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.
        Overrides:
        beginTree in class AbstractCheck
        Parameters:
        rootAST - the root of the tree
      • finishTree

        public void finishTree​(DetailAST rootAST)
        Description copied from class: AbstractCheck
        Called after finished processing a tree. Ideal place to report on information collected whilst processing a tree.
        Overrides:
        finishTree in class AbstractCheck
        Parameters:
        rootAST - the root of the tree