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 | package Torello.JavaDoc.Annotations;
import Torello.JavaDoc.Annotations.hidden.LJSRepeatable;
import java.util.Set;
import java.util.TreeSet;
// NOTE: This is a complete nightmare. Java-Sun-Oracle sort-of treated "Annotations" as kind of
// an "after-thought"... The classes needed to process an annotation are distributed
// across 5 or 6 different Java-Packages (all listed below).
//
// The "@StaticFunctional" Annotation began in the middle of Year-2021, and I have optimized-it
// and added comments ever since (to better explain what it is doing). It is almost the end of
// Year-2022 and I'm still optimizing this.
//
// The comments on the Annotation-Processors in this package are actually pretty good. I'm kind of
// ashamed to admit that I looked some of this up on "StackOverlow" - since the people on that site
// are so completely terrible... But I did ...
import javax.annotation.processing.Messager;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.AnnotationMirror;
import javax.tools.Diagnostic;
// Top-Level Dispatch Annotation-Processor for <I>both</I> JavaDoc-Upgrader Annotations.
public class JDUAnnotationProcessorDispatch extends AbstractProcessor
{
private javax.annotation.processing.Messager messager = null;
private javax.annotation.processing.Filer filer = null;
/**
* Method that is requuired by the {@code 'AbstractProcessor'} interface that allows this
* processor to initialize & receive the necessary environment variables.
*
* @param env This provides the instance-reference to the messaging-output tool.
*/
@Override
public synchronized void init(ProcessingEnvironment env)
{
this.messager = env.getMessager();
this.filer = env.getFiler();
}
/**
* Method required by {@code AbstractProcessor}
*
* @return The set of annotations supported by this processor. The {@code Set} that is
* returned contains just the name of the {@code StaticFunctional} class-name.
*/
@Override
public Set<String> getSupportedAnnotationTypes()
{
TreeSet<String> ret = new TreeSet<>();
ret.add(StaticFunctional.class.getCanonicalName());
ret.add(JDHeaderBackgroundImg.class.getCanonicalName());
ret.add(CSSLinks.class.getCanonicalName());
ret.add(JavaScriptImport.class.getCanonicalName());
ret.add(IntoHTMLTable.class.getCanonicalName());
ret.add(LinkJavaSource.class.getCanonicalName());
ret.add(LJSRepeatable.class.getCanonicalName());
// DO I NEED THIS?
//ret.add(LJSRepeatable.class.getCanonicalName());
return ret;
}
/**
* Method required by {@code AbstractProcessor}
* @return the Java version supported
*/
@Override
public SourceVersion getSupportedSourceVersion()
{ return SourceVersion.latestSupported(); }
/**
* This implements the processing for the Annotation @{@link StaticFunctional}. It does a lot
* of validity checks on the parameter input.
*/
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnv)
{
boolean errors = false;
// REMEMBER: There are **THREE** different classes/types for an Annotation:
//
// 1) The actual Annotation itself - which is the one the end-user is supposed to use.
//
// 2) The Processor (which is now three classes - to keep it all separated out)
//
// 3) The Annotation-Mirror (which is now one class - to keep it all together), which the
// JavaDoc Upgrader uses to retrieve the values of the Elements that the user provided
// so that it can react accordingly during the upgrader processing
//
// Annotations just feel like one giant Spaghetti Mess. I think they should have allowed
// all three of these concepts to reside INSIDE THE SAME CLASS: The processor, the mirror
// and the annotation itself... They should be on simple/single class, but Java will not
// allow it.
//
// Because they are so messy, Java-HTML doesn't use a lot of annotations. As of October
// 2022, there are only two in the entire JAR Library... Although "StaticFunctional" is
// used on almost every '.class' in the entire JAR.
//
// NOTE: AGAIN, the @StaticFunctional Annotation is really just used to say "This is not
// really an Object-Class, it is a standad '.c' File, and doesn't have any data"
//
// Just about every class in the Java-HTML JAR Library that is not a "Data Class"
// has had @StaticFunctional placed on it.
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Processor-Dispatch for @CSSStyleSheets
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// All the classes that are annotated with @CSSStyleSheets
for (Element ciet : roundEnv.getElementsAnnotatedWith(CSSLinks.class))
// There may be many annotations on that class (other than @CSSStyleSheets)
// This retrieves all of the mirrors on the class, even ones not about @JDHBI...
for (AnnotationMirror am : ciet.getAnnotationMirrors())
// If the annotation-mirror on that class (whose-mirrors are being iterated) is
// a @CSSStyleSheets data/value mirror (all the values that the user gave
// the annotation when he placed it on a class), then-and-only-then should it be
// processed.
if (am.getAnnotationType().toString().equals
("Torello.JavaDoc.Annotations.CSSLinks"))
// Do the @CSSStyleSheets Processing... For readability this has been
// placed in a separate-file. All this does is make sure the user didn't
// screw-up the values that he (may or may not have) given to the annotation.
// If there are no values assigned to the members, this method exists
// immediately.
errors |= CSSLProcessor.process(ciet, am, filer, this.messager);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Processor-Dispatch for @JDHeaderBackgroundImg
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
//
// NOTE: The next set of loops were **ALL** Block Copied from the first loop. This means
// that all applicable documentation-explanations are the exact same thing for these
// Annotations as well.
for (Element ciet : roundEnv.getElementsAnnotatedWith(JDHeaderBackgroundImg.class))
for (AnnotationMirror am : ciet.getAnnotationMirrors())
if (am.getAnnotationType().toString().equals
("Torello.JavaDoc.Annotations.JDHeaderBackgroundImg"))
errors |= JDHBIProcessor.process(ciet, am, this.messager);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Processor-Dispatch for @StaticFunctional
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
for (Element ciet : roundEnv.getElementsAnnotatedWith(StaticFunctional.class))
for (AnnotationMirror am : ciet.getAnnotationMirrors())
if (am.getAnnotationType().toString().equals
("Torello.JavaDoc.Annotations.StaticFunctional"))
errors |= SFProcessor.process(ciet, am, this.messager);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Processor-Dispatch for @LinkJavaSource
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
for (Element ciet : roundEnv.getElementsAnnotatedWith(LinkJavaSource.class))
for (AnnotationMirror am : ciet.getAnnotationMirrors())
if (am.getAnnotationType().toString().equals
("Torello.JavaDoc.Annotations.LinkJavaSource"))
errors |= LJSProcessor.process(ciet, am, this.messager);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Processor-Dispatch for @IntoHTMLTable
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
for (Element ciet : roundEnv.getElementsAnnotatedWith(IntoHTMLTable.class))
for (AnnotationMirror am : ciet.getAnnotationMirrors())
if (am.getAnnotationType().toString().equals
("Torello.JavaDoc.Annotations.IntoHTMLTable"))
errors |= IHTProcessor.process(ciet, am, this.messager);
return errors;
}
}
|