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
package Torello.JDUInternal.Annotations.TypeAnnotations.Mirror;

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

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

import Torello.Java.StrCSV;

import Torello.JDUInternal.Annotations.HELPER;

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

import static com.sun.source.tree.Tree.Kind.ASSIGNMENT;

import java.util.List;


// @CSSLinks Annotation
// 
// EXPORTS:
//      public String[] FileNames();
// 
// * Torello.JavaDoc.CSSLinks
//      This is the actual User-Annotation that is part of the Upgrader-API.  A user may place the
//      @CSSLinks Annotation on a Type / CIET (Class, Interface, Enum, Annotation or
//      Rec) - And a CSS-File Link in the form of a <LINK REL=stylesheet TYPE=text/css HREF=...>
//      will be inserted for Class / Type / CIET that the user has annotated. 
// 
// * package Torello.JDUInternal.Features.USER_SUPPLIED_CSS_FILES
//      The classes in this package do the processing for inserting the '.css' Files which the user
//      has requested be placed into his Java-Doc '.html' Web-Page.  These '.css' Files must be
//      located in the '../upgrade-files/stylesheets/' directory.  These '.css' Files must either:
// 
//          1) obey the standard naming convention and have the exact same file-name as the
//          Java-Class which has been annotated by the @CSSLinks Annotation
// 
//          2) have a name equal to one of the names provided to the Annotation-Element "FileNames"
// 
// * Torello.JDUInternal.Annotations.TypeAnnotations.Processor.CSSLinksProcessor
//      This is the Annotation-Processsor that is / can-be invoked by the 'javac' (Java-Compiler) at
//      Compile-Time.  This Annotation-Processor does not do very much, but will check that the
//      names provided to the "FileNames" Annotation-Element are, indeed, valid Operating-System
//      File-Names - which exist and are accessible.
// 
// * Torello.JDUInternal.Annotations.TypeAnnotations.Mirror.CSSLMirror
//      After the JDU Detects that a CIET / Type has had the @CSSLinks Annotation placed upon
//      it, this class extracts the relevant information out of the Annotation using the AST
//      Library in 'com.sun.source.tree' and all of it's helper classes. 

public class CSSLMirror implements TypeAnnotationMirror
{
    public final ReadOnlyList<String> fileNames;

    private final String annotationAsStr;
    public String getAnnotationAsString()   { return annotationAsStr;   }
    public String getAnnotationName()       { return "CSSLinks";        }


    public CSSLMirror(
            final List<? extends ExpressionTree>    arguments,
            final String                            annotationAsStr
        )
    {
        this.annotationAsStr = annotationAsStr;

        ReadOnlyList<String> fileNames = null;

        if (arguments.size() == 0)
        {
            this.fileNames = ReadOnlyArrayList.emptyROAL();
            return;
        }

        for (ExpressionTree argument : arguments)
        {
            /*
            System.out.println(
                "argument:                            " + argument.toString() + '\n' +
                "argument.getKind():                  " + argument.getKind().toString() + '\n' +
                "argument.getClass().getSimpleName(): " + argument.getClass().getSimpleName()
            );
            */

            // System.out.println(argument);

            if (argument.getKind() != ASSIGNMENT) throw Messager.assertFail(
                "The ExpressionTree returned by the @CSSLinks arguments list was not of " +
                "type ASSIGNMENT, but rather " + argument.getKind() + '\n' +
                "ExpressionTree.toString(): " + argument.toString() + '\n' +
                "All Annotation Expressions: " + StrCSV.toCSV(arguments, true, true, null) + '\n' +
                MsgPrintTools.annotationProcessingError(),
                JDUAnnotations.CSSLMirror
            );

            String elemName             = ((AssignmentTree) argument).getVariable().toString();
            ExpressionTree elemValue    = ((AssignmentTree) argument).getExpression();

            /*
            System.out.println(
                "    elemName:             " + elemName + '\n' +
                "    elemValue.toString(): " + elemValue.toString() + '\n' +
                "    elemValue.getKind():  " + elemValue.getKind().toString() + '\n' +
                "    elemValue.getClass(): " + elemValue.getClass().getSimpleName() + '\n'
            );
            */

            if (elemName.equals("FileNames"))
            {
                if (fileNames != null) throw Messager.assertFail(
                    "There are apparently multiple instances of the Annotation-Element " +
                    "'FileNames' included with the @CSSLinks Annotation" + '\n' +
                    MsgPrintTools.annotationProcessingError(),
                    JDUAnnotations.CSSLMirror
                );

                fileNames =
                    HELPER.handleStringArray(elemValue, "FileNames", JDUAnnotations.CSSLMirror);
            }

            else throw Messager.assertFail(
                "There was an Expression Variable-Name that was not 'FileNames' but rather: " +
                elemName +
                MsgPrintTools.annotationProcessingError(),
                JDUAnnotations.CSSLMirror
            );
        }

        this.fileNames = fileNames;

        if (MsgVerbose.isVerbose()) MsgVerbose.println(
            "@CSSFiles Annotation-Processing Mirror Class:" +
            "    fileNames: " + StrCSV.toCSV(this.fileNames, true, false, null)
        );
    }

}