Class NonStaticMethodCheck

  • All Implemented Interfaces:,

    public final class NonStaticMethodCheck
    Checks that non static method must contain at least one reference to this.

    If your method doesn't need this than why it is not static? The exception here is when method has @Override annotation. There's no concept of inheritance and polymorphism for static methods even if they don't need this to perform the actual work. Another exception is when method is abstract or native. Such methods don't have body so detection based on this doesn't make sense for them.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int[] getAcceptableTokens()  
      int[] getDefaultTokens()  
      int[] getRequiredTokens()  
      void setExcludeFileNamePattern​(String excl)
      Exclude files matching given pattern.
      void visitToken​( ast)  
      • Methods inherited from class

        beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
      • Methods inherited from class

        finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
      • Methods inherited from class

        configure, contextualize, getConfiguration, setupChild
    • Constructor Detail

      • NonStaticMethodCheck

        public NonStaticMethodCheck()
    • Method Detail

      • setExcludeFileNamePattern

        public void setExcludeFileNamePattern​(String excl)
        Exclude files matching given pattern.
        excl - Regexp of classes to exclude.
      • getDefaultTokens

        public int[] getDefaultTokens()
        Specified by:
        getDefaultTokens in class
      • getAcceptableTokens

        public int[] getAcceptableTokens()
        Specified by:
        getAcceptableTokens in class
      • getRequiredTokens

        public int[] getRequiredTokens()
        Specified by:
        getRequiredTokens in class
      • visitToken

        public void visitToken​( ast)
        visitToken in class