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 | package Torello.JDUInternal.Annotations.EntityAnnotations.Mirror;
import Torello.Java.ReadOnly.ReadOnlyList;
import Torello.Java.ReadOnly.ReadOnlyArrayList;
import Torello.JavaDoc.IntoHTMLTable;
import Torello.JavaDoc.IntoHTMLTable.Background;
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 Torello.JDUInternal.Annotations.HELPER;
import Torello.JDUInternal.Annotations.ECData;
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;
// @IntoHTMLTable Annotation:
//
// 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
//
// * Torello.JavaDoc.IntoHTMLTable
// For the actual annotation definition.
// This is the actual @interface for the @IntoHTMLTable Annotation
//
// * Torello.JDUInternal.Annotations.EntityAnnotations.Mirror.IHTMirror
// The Data-Contents of the Annotation that has been placed by the User on the Entity
// (Entity: Method, Field, Constructor, Enum-Constant, Annotation-Element)
//
// * Torello.JDUInternal.Annotations.EntityAnnotations.Processor.IntoHTMLTableProcessor
// The Annotation-Processor that is invoked by 'javac' when compiling a class that uses the
// @IntoHTMLTable Annotation. It's a very minimalist processor that actually does very little
// There is no way to do very much meaningful Error-Checking when invoked by 'javac'
// Until the Java-Doc Upgrader is running, you cannot even identify errors.
public class IHTMirror
{
// 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.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
);
public final String annotationAsStr;
public final Background background;
public final String title;
public final ReadOnlyList<String> divCSSClass;
public final ReadOnlyList<String> tableCSSClass;
public 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
)
{
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);
}
public String toString()
{
return
annotationAsStr + ":\n" +
" background: " + background + '\n' +
" title: " + title + '\n' +
" divCSSClass: " + HELPER.TOSTR(divCSSClass) + '\n' +
" tableCSSClass: " + HELPER.TOSTR(tableCSSClass) + '\n';
}
}
|