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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package Torello.JavaDoc.Annotations;

import Torello.Java.ReadOnly.ReadOnlyList;
import Torello.Java.ReadOnly.ReadOnlyArrayList;

import Torello.Java.StringParse;

import Torello.JavaDoc.Messager.Messager;
import Torello.JavaDoc.Messager.MsgPrintTools;
import Torello.JDUInternal.Miscellaneous.Where.JDUAnnotations;
import Torello.JavaDoc.Messager.Where_Am_I;

import static Torello.Java.C.BCYAN;
import static Torello.Java.C.BGREEN;
import static Torello.Java.C.BYELLOW;
import static Torello.Java.C.BRED;
import static Torello.Java.C.RESET;

import java.util.List;

import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.AssignmentTree;
import com.sun.source.tree.LiteralTree;


// EXPORTS:
//      public Background background() default Background.Blue;
//      public String title() default "";
//      public String divCSSClass() default "";
//      public String tableCSSClass() default "";
// 
// The following files are relatedf to this Annotation-Mirror Data-Class:
// 
// * Torello.JDUInternal.SimpleFeatures.IntoHTMLTableProc
//      This is the primary or "Work Horse" Method for Generating the HTML-Table that is inserted
//      into the Detail-Entry "description()" section.
// 
// * User-Annotations.css
//      For the CSS Color Choices/Options/Definitions
//      Since there are a suite of Color-Choices which have been presented to the user


/**
 * An internally used data-record class used for storing all user-supplied annotation data 
 * associated with a single use / application of the {@link IntoHTMLTable} annotation.
 * 
 * @see Torello.JavaDoc.Annotations.IntoHTMLTable
 */
@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="MIRROR_JDHBI")
public class IHTMirror implements AnnotationMirror
{
    // ********************************************************************************************
    // ********************************************************************************************
    // Static-Constant Fields
    // ********************************************************************************************
    // ********************************************************************************************


    // I usually don't do this, but this is used inside of switch-statement, and therefore using 
    // this becomes extremely cumbersome if it isn't in a shorter variable name.

    private static final Where_Am_I WHERE_AM_I = JDUAnnotations.IHTMirror;

    private static final ECData<Torello.JavaDoc.Annotations.IntoHTMLTable.Background> ecParser =
        new ECData<>(
            IntoHTMLTable.Background.class,

            // These are strictly needed for Error message which are being passed to the messager
            JDUAnnotations.IHTMirror,               // Where_Am_I 
            IntoHTMLTable.class.getSimpleName(),    // The name of the Annoation
            "background"                            // The Annotation-Element being processed
        );


    // ********************************************************************************************
    // ********************************************************************************************
    // interface AnnotationMirror
    // ********************************************************************************************
    // ********************************************************************************************


    // Stores the actual text of the @StaticFunctional annotation which was placed.
    // This is nothing more than the exact line that was originally inserted into the class.
    // The only reason this is even needed (in case you are wondering) is because the error 
    // checking & error printing code outputs this text when printing an error message.

    private final String annotationAsStr;

    /** {@inheritDoc} */ @Override
    public String getAnnotationAsString() { return annotationAsStr; }

    /** {@inheritDoc} */ @Override
    public String getAnnotationName() { return "IntoHTMLTable"; }


    // ********************************************************************************************
    // ********************************************************************************************
    // Public, Final, ReadOnly, Mirrored Fields
    // ********************************************************************************************
    // ********************************************************************************************


    /** Holds data extracted from {@link IntoHTMLTable#background()} */
    public final IntoHTMLTable.Background background;

    /** Holds data extracted from {@link IntoHTMLTable#title()} */
    public final String title;

    /** Holds data extracted from {@link IntoHTMLTable#divCSSClass()} */
    public final ReadOnlyList<String> divCSSClass;

    /** Holds data extracted from {@link IntoHTMLTable#tableCSSClass()} */
    public final ReadOnlyList<String> tableCSSClass;


    // ********************************************************************************************
    // ********************************************************************************************
    // Package-Private Constructor, Invoked by class "EntityAnnotationMirrors"
    // ********************************************************************************************
    // ********************************************************************************************


    IHTMirror(
            // The parsed arguments to to the Annotation
            final List<? extends ExpressionTree> arguments,


            // This is the Annotation, as a simple Java-String.  This is very useful for
            // Error-Printing with the Messager.  That's the only purpose of it

            final String annotationAsStr,


            // The Signature of the Detail-Entity onto which this "@LinkJavaSource" Annotation
            // was placed.  Very important for error messages

            final String signature
        )
    {
        IntoHTMLTable.Background    background          = null;
        String                      title               = null;
        String                      divCSSClassSTR      = null;
        String                      tableCSSClassSTR    = null;

        for (int i = 0; i < arguments.size(); i++)
        {
            final ExpressionTree expr = arguments.get(i);

            if (! (expr instanceof AssignmentTree)) Messager.assertFail(
                "Annotation Placed:\n" +
                "    " + BCYAN + annotationAsStr + RESET + '\n' +
                "While parsing the Arguments / Elements of an IHTMirror Annotation, the " +
                "Oracle-Parser (com.sun.source.tree) returned an instance of `ExpressionTree` " +
                "that was not an instance of `AssignmentTree`." +
                MsgPrintTools.annotationProcessingError(),
                WHERE_AM_I
            );

            final AssignmentTree assignExpr = (AssignmentTree) expr;

            // Extracting the left-hand side (LHS) and right-hand side (RHS)
            final ExpressionTree LHS = assignExpr.getVariable();
            final ExpressionTree RHS = assignExpr.getExpression();

            final String lhsStr = LHS.toString();

            final String rhsStr = (RHS instanceof LiteralTree) 
                ? ((LiteralTree) RHS).getValue().toString()
                : RHS.toString();

            switch (lhsStr)
            {
                case "background":

                    if (background != null) HELPER.dupErrorAE
                        (annotationAsStr, background, "background", rhsStr, WHERE_AM_I);
                    else
                        background = ecParser.valueOf(rhsStr, signature);

                    break;


                case "title":

                    if (title != null) HELPER.dupErrorAE
                        (annotationAsStr, title, "title", rhsStr, WHERE_AM_I);
                    else
                        title = rhsStr;

                    break;


                case "divCSSClass":

                    if (divCSSClassSTR != null) HELPER.dupErrorAE
                        (annotationAsStr, divCSSClassSTR,  "divCSSClass", rhsStr, WHERE_AM_I);
                    else
                        divCSSClassSTR = rhsStr;

                    break;


                case "tableCSSClass":

                    if (tableCSSClassSTR != null) HELPER.dupErrorAE
                        (annotationAsStr, tableCSSClassSTR, "tableCSSClass", rhsStr, WHERE_AM_I);
                    else 
                        tableCSSClassSTR = rhsStr;

                    break;


                default: Messager.userErrorContinue(
                    "While proessing a @IntoHTMLTable Annotation, the following " +
                    "Annotation-Element Name was found:\n" +
                    "    [" + lhsStr + "]\n" +
                    "This is not a valid Annotation-Argument.  This is not one of " +
                    "@IntoHTMLTable' Elements (sometimes called \"Arguements\")\n" +
                    "Valid Element-Names for this Annotation Include:\n" +
                    "    background, title, divCSSClass, and tableCSSClass" +
                    MsgPrintTools.annotationProcessingError(),
                    WHERE_AM_I
                );
            }
        }

        this.annotationAsStr    = annotationAsStr;
        this.background         = background;

        this.title = (title.length() == 0)
            ? null 
            : title;

        this.divCSSClass = ((divCSSClassSTR == null) || (divCSSClassSTR.length() == 0))
            ? ReadOnlyArrayList.emptyROAL()
            : new ReadOnlyArrayList<String>(divCSSClassSTR.split("\\s"));

        this.tableCSSClass = ((tableCSSClassSTR == null) || (tableCSSClassSTR.length() == 0))
            ? ReadOnlyArrayList.emptyROAL()
            : new ReadOnlyArrayList<String>(tableCSSClassSTR.split("\\s"));

        IHTErrorCheck.check(this, annotationAsStr, signature);
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // toString
    // ********************************************************************************************
    // ********************************************************************************************


    /** {@inheritDoc} */ @Override
    public String toString()
    {
        // 19 ==> Width of the Title Strings....  They are all 19 characters wide
        // 
        // public final Background              background;
        // public final String                  title;
        // public final ReadOnlyList<String>    divCSSClass;
        // public final ReadOnlyList<String>    tableCSSClass;

        return
            annotationAsStr + '\n' +
            "{\n" +
            "    background:    " + background.toString()                   + '\n' +
            "    title:         " + HELPER.TOSTR(this.title, 19)            + '\n' +
            "    divCSSClass:   " + HELPER.TOSTR(this.divCSSClass, 19)      + '\n' +
            "    tableCSSClass: " + HELPER.TOSTR(this.tableCSSClass, 19)    + '\n' +
            '}';
    }
}