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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
package Torello.HTML.Tools.JavaDoc;

import java.util.*;

import Torello.HTML.*;

import Torello.Java.Shell.C;

/**
 * <CODE>StatelessClassess - Documentation.</CODE><BR /><BR />
 * <EMBED CLASS="external-html" DATA-FILE-ID="STATELESSCL">
 */
@StaticFunctional
public class StatelessClasses
{
    // No Public Constructor
    private StatelessClasses() { }

    /**
     * Inserts a notice into any class that has been tagged with the {@code StaticFunctional}
     * Annotation.
     * 
     * @param pr The parameters.
     */
    public static void run(CommonParamRecord pr)
    {
        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.");
    }
}