Class StatelessClasses


  • public class StatelessClasses
    extends java.lang.Object
    StatelessClassess - Documentation.

    For classes in which a "Statless Class" analysis has been requested, this processor checks for non-static fields inside of the class.




Stateless Class: This class neither contains any program-state, nor can it be instantiated.
The @StaticFunctional Annotation may also be called 'The Spaghetti Report'
  • 1 Constructor(s), 1 declared private, zero-argument constructor
  • 1 Method(s), 1 declared static
  • 0 Field(s)


    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method
      static void run​(CommonParamRecord pr)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • run

        public static void run​(CommonParamRecord pr)
        Inserts a notice into any class that has been tagged with the StaticFunctional Annotation.
        Parameters:
        pr - The parameters.
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        33
        34
        35
        36
        37
        38
        39
        40
        41
        42
        43
        44
        45
        46
        47
        48
        49
        50
        51
        52
        53
        54
        55
        56
        57
        58
        59
        60
        61
        62
        63
        64
        65
        66
        67
        68
        69
        70
        71
        72
        73
        74
        75
        76
        77
        78
        79
        80
        81
        82
        83
         if (! pr.jscf.staticFunctionalAnnotation) return;
        
         // The methods, fields and constructor - as declared in the "Java Source Code File"
         // which was parsed by JavaParser - so it should be an accurate list.
         Method[]        mArr = pr.jscf.getMethods();
         Field[]         fArr = pr.jscf.getFields();
         Constructor[]   cArr = pr.jscf.getConstructors();
        
         // These "counts" determine whether a method is static-functional
         int             numStaticMethods        = 0;
         int             numStaticFields         = 0;
         int             numFinalFields          = 0;
         int             numPrivateConstructors  = 0;
        
         // Compute the counts
         for (Method m : mArr)       if (m.hasModifier("static"))    numStaticMethods++;
         for (Field f : fArr)        if (f.hasModifier("static"))    numStaticFields++;
         for (Field f : fArr)        if (f.hasModifier("final"))     numFinalFields++;
         for (Constructor c : cArr)  if (c.hasModifier("private"))   numPrivateConstructors++;
        
         boolean zeroArgConstructor = (cArr.length == 1) && (cArr[0].numParameters() == 0);
                    
         // Create the HTML for the CIET Java Doc Documentation page.
         StringBuilder htmlSB = new StringBuilder();
        
         htmlSB.append(
             "<DIV ID=STATELESSCLASS>\n" +
             "<SPAN CLASS=staticFunctional>Stateless Class:</SPAN>\n" +
             "This class neither contains any program-state, nor can it be instantiated.<BR />\n" +
             "The <CODE>@StaticFunctional</CODE> Annotation may also be called 'The Spaghetti Report'<BR />\n" +
             "<UL CLASS=JDUL>\n" +
             "\t<LI><B>" + cArr.length + "</B> Constructor(s), <B>" +
                 numPrivateConstructors + "</B> declared private" +
                 (zeroArgConstructor ? ", <I>zero-argument constructor</I>" : "") +
                 "</LI>\n" +
             "\t<LI><B>" + mArr.length + "</B> Method(s)" +
                 ((mArr.length > 0)
                     ?
                     (", <B>" + numStaticMethods + "</B> declared static")
                     : "") +
                 "</LI>\n" +
             "\t<LI><B>" + fArr.length + "</B> Field(s)" +
                 ((fArr.length > 0)
                     ?
                     (", <B>" + numStaticFields + "</B> declared static, <B>" +
                     numFinalFields + " </B> declared final")
                     : "") +
                 "</LI>\n"
         );
        
         if (pr.jscf.excuses == null)
             htmlSB.append("</UL>\n</DIV>\n<BR />\n<BR />\n");
         else
         {
             htmlSB.append(
                 "\t<LI>Fields excused from <B>final</B> modifier (with explanation):\n" +
                 "\t\t<TABLE>\n"
             );
        
             for (int i=0; i < pr.jscf.excuses.size(); i++)
                 htmlSB.append(
                     "\t\t<TR>\n\t\t\t<TD>Field '" + pr.jscf.excused.elementAt(i).toString() + "' is not " +
                     "final.</TD>\n\t\t\t<TD>Reason: " + pr.jscf.excuses.elementAt(i) + "</TD>\n\t\t</TR>\n"
                 );
        
             htmlSB.append("\t\t</TABLE>\n\t</LI>\n</UL>\n</DIV>\n<BR />\n<BR />\n");
         }
        
        
         // Insert the page into the top (yellow-section)
         DotPair dp = TopDescription.descriptionAtTop(pr.fileVec);
        
         if (dp != null)
             pr.fileVec.addAll(dp.end, HTMLPage.getPageTokens(htmlSB.toString(), false));
         else
             throw new UpgradeException(
                 "Unable to insert Static Functional API Notice.  No Insertion Point was " +
                 "identified.  Currently Processing File:\n" +
                 pr.jdFileName
             );
        
         if (pr.sw != null) pr.sw.println(
             "\tInserted " + C.BCYAN + "@StaticFunctional" + C.RESET + " notice table.");