001package Torello.HTML.Tools.JavaDoc;
002
003import java.util.*;
004
005import Torello.HTML.*;
006
007import Torello.Java.Shell.C;
008
009/**
010 * <CODE>StatelessClassess - Documentation.</CODE><BR /><BR />
011 * <EMBED CLASS="external-html" DATA-FILE-ID="STATELESSCL">
012 */
013@StaticFunctional
014public class StatelessClasses
015{
016    // No Public Constructor
017    private StatelessClasses() { }
018
019    /**
020     * Inserts a notice into any class that has been tagged with the {@code StaticFunctional}
021     * Annotation.
022     * 
023     * @param pr The parameters.
024     */
025    public static void run(CommonParamRecord pr)
026    {
027        if (! pr.jscf.staticFunctionalAnnotation) return;
028
029        // The methods, fields and constructor - as declared in the "Java Source Code File"
030        // which was parsed by JavaParser - so it should be an accurate list.
031        Method[]        mArr = pr.jscf.getMethods();
032        Field[]         fArr = pr.jscf.getFields();
033        Constructor[]   cArr = pr.jscf.getConstructors();
034
035        // These "counts" determine whether a method is static-functional
036        int             numStaticMethods        = 0;
037        int             numStaticFields         = 0;
038        int             numFinalFields          = 0;
039        int             numPrivateConstructors  = 0;
040
041        // Compute the counts
042        for (Method m : mArr)       if (m.hasModifier("static"))    numStaticMethods++;
043        for (Field f : fArr)        if (f.hasModifier("static"))    numStaticFields++;
044        for (Field f : fArr)        if (f.hasModifier("final"))     numFinalFields++;
045        for (Constructor c : cArr)  if (c.hasModifier("private"))   numPrivateConstructors++;
046
047        boolean zeroArgConstructor = (cArr.length == 1) && (cArr[0].numParameters() == 0);
048            
049        // Create the HTML for the CIET Java Doc Documentation page.
050        StringBuilder htmlSB = new StringBuilder();
051
052        htmlSB.append(
053            "<DIV ID=STATELESSCLASS>\n" +
054            "<SPAN CLASS=staticFunctional>Stateless Class:</SPAN>\n" +
055            "This class neither contains any program-state, nor can it be instantiated.<BR />\n" +
056            "The <CODE>@StaticFunctional</CODE> Annotation may also be called 'The Spaghetti Report'<BR />\n" +
057            "<UL CLASS=JDUL>\n" +
058            "\t<LI><B>" + cArr.length + "</B> Constructor(s), <B>" +
059                numPrivateConstructors + "</B> declared private" +
060                (zeroArgConstructor ? ", <I>zero-argument constructor</I>" : "") +
061                "</LI>\n" +
062            "\t<LI><B>" + mArr.length + "</B> Method(s)" +
063                ((mArr.length > 0)
064                    ?
065                    (", <B>" + numStaticMethods + "</B> declared static")
066                    : "") +
067                "</LI>\n" +
068            "\t<LI><B>" + fArr.length + "</B> Field(s)" +
069                ((fArr.length > 0)
070                    ?
071                    (", <B>" + numStaticFields + "</B> declared static, <B>" +
072                    numFinalFields + " </B> declared final")
073                    : "") +
074                "</LI>\n"
075        );
076
077        if (pr.jscf.excuses == null)
078            htmlSB.append("</UL>\n</DIV>\n<BR />\n<BR />\n");
079        else
080        {
081            htmlSB.append(
082                "\t<LI>Fields excused from <B>final</B> modifier (with explanation):\n" +
083                "\t\t<TABLE>\n"
084            );
085
086            for (int i=0; i < pr.jscf.excuses.size(); i++)
087                htmlSB.append(
088                    "\t\t<TR>\n\t\t\t<TD>Field '" + pr.jscf.excused.elementAt(i).toString() + "' is not " +
089                    "final.</TD>\n\t\t\t<TD>Reason: " + pr.jscf.excuses.elementAt(i) + "</TD>\n\t\t</TR>\n"
090                );
091
092            htmlSB.append("\t\t</TABLE>\n\t</LI>\n</UL>\n</DIV>\n<BR />\n<BR />\n");
093        }
094
095
096        // Insert the page into the top (yellow-section)
097        DotPair dp = TopDescription.descriptionAtTop(pr.fileVec);
098
099        if (dp != null)
100            pr.fileVec.addAll(dp.end, HTMLPage.getPageTokens(htmlSB.toString(), false));
101        else
102            throw new UpgradeException(
103                "Unable to insert Static Functional API Notice.  No Insertion Point was " +
104                "identified.  Currently Processing File:\n" +
105                pr.jdFileName
106            );
107
108        if (pr.sw != null) pr.sw.println(
109            "\tInserted " + C.BCYAN + "@StaticFunctional" + C.RESET + " notice table.");
110    }
111}