001package Torello.JavaDoc.Annotations;
002
003import static Torello.Java.C.RESET;
004import static Torello.Java.C.BCYAN;
005
006import Torello.JavaDoc.Messager.Messager;
007import Torello.JavaDoc.Messager.MsgPrintTools;
008import Torello.JavaDoc.Messager.MsgVerbose;
009
010import Torello.JDUInternal.Miscellaneous.Where.JDUAnnotations;
011
012import Torello.Java.ReadOnly.ReadOnlyList;
013import Torello.Java.ReadOnly.ReadOnlyArrayList;
014
015import Torello.Java.StrCSV;
016
017import com.sun.source.tree.ExpressionTree;
018import com.sun.source.tree.AssignmentTree;
019
020import java.util.List;
021
022
023/**
024 * An internally used data-record class used for storing all user-supplied annotation data 
025 * associated with a single use / application of the {@link JavaScriptImport} annotation.
026 * 
027 * @see Torello.JavaDoc.Annotations.JavaScriptImport
028 */
029@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="MIRROR_JDHBI")
030public class JSIMirror implements AnnotationMirror
031{
032    // ********************************************************************************************
033    // ********************************************************************************************
034    // Public, Final, ReadOnly, Mirrored Fields
035    // ********************************************************************************************
036    // ********************************************************************************************
037
038
039    /** Holds data extracted from {@link JavaScriptImport#FileNames()}*/
040    public final ReadOnlyList<String> fileNames;
041
042    /** Holds data extracted from {@link JavaScriptImport#FullPathFileNames()} */
043    public final ReadOnlyList<String> fullPathFileNames;
044
045
046    // ********************************************************************************************
047    // ********************************************************************************************
048    // interface AnnotationMirror
049    // ********************************************************************************************
050    // ********************************************************************************************
051
052
053    // Stores the actual text of the @StaticFunctional annotation which was placed.
054    // This is nothing more than the exact line that was originally inserted into the class.
055    // The only reason this is even needed (in case you are wondering) is because the error 
056    // checking & error printing code outputs this text when printing an error message.
057
058    private final String annotationAsStr;
059
060    /** {@inheritDoc} */ @Override
061    public String getAnnotationAsString() { return annotationAsStr; }
062
063    /** {@inheritDoc} */ @Override
064    public String getAnnotationName() { return "JavaScriptImport"; }
065
066
067    // ********************************************************************************************
068    // ********************************************************************************************
069    // Package-Private Constructor, Invoked by class "TypeAnnotationMirrors"
070    // ********************************************************************************************
071    // ********************************************************************************************
072
073
074    JSIMirror(
075            final List<? extends ExpressionTree>    arguments,
076            final String                            annotationAsStr
077        )
078    {
079        this.annotationAsStr = annotationAsStr;
080
081        ReadOnlyList<String> fileNames          = null;
082        ReadOnlyList<String> fullPathFileNames  = null;
083
084        if (arguments.size() == 0)
085        {
086            this.fileNames          = ReadOnlyArrayList.emptyROAL();;
087            this.fullPathFileNames  = ReadOnlyArrayList.emptyROAL();
088            return;
089        }
090
091        for (ExpressionTree argument : arguments)
092        {
093            /*
094            System.out.println(
095                "argument:                            " + argument.toString() + '\n' +
096                "argument.getKind():                  " + argument.getKind().toString() + '\n' +
097                "argument.getClass().getSimpleName(): " + argument.getClass().getSimpleName()
098            );
099            */
100
101            // System.out.println(argument);
102
103            if (! (argument instanceof AssignmentTree)) Messager.assertFail(
104                "Annotation Placed:\n" +
105                "    " + BCYAN + annotationAsStr + RESET + '\n' +
106                "While parsing the Arguments / Elements of an JSIMirror Annotation, the " +
107                "Oracle-Parser (com.sun.source.tree) returned an instance of `ExpressionTree` " +
108                "that was not an instance of `AssignmentTree`.\n" +
109                "ExpressionTree.toString():  " + argument.toString() + '\n' +
110                "All Annotation Expressions: " + StrCSV.toCSV(arguments, true, true, null) + '\n' +
111                MsgPrintTools.annotationProcessingError(),
112                JDUAnnotations.JSIMirror
113            );
114
115            String          elemName    = ((AssignmentTree) argument).getVariable().toString();
116            ExpressionTree  elemValue   = ((AssignmentTree) argument).getExpression();
117
118            /*
119            System.out.println(
120                "    elemName:             " + elemName + '\n' +
121                "    elemValue.toString(): " + elemValue.toString() + '\n' +
122                "    elemValue.getKind():  " + elemValue.getKind().toString() + '\n' +
123                "    elemValue.getClass(): " + elemValue.getClass().getSimpleName() + '\n'
124            );
125            */
126
127            if (elemName.equals("FileNames"))
128            {
129                if (fileNames != null) throw Messager.assertFail(
130                    "Annotation Placed:\n" +
131                    "    " + BCYAN + annotationAsStr + RESET + '\n' +
132                    "There are apparently multiple instances of the Annotation-Element " +
133                    "'FileNames' included with the @CSSLinks Annotation\n" +
134                    MsgPrintTools.annotationProcessingError(),
135                    JDUAnnotations.JSIMirror
136                );
137
138                fileNames =
139                    HELPER.handleStringArray(elemValue, "FileNames", JDUAnnotations.JSIMirror);
140            }
141
142            else if (elemName.equals("FullPathFileNames"))
143            {
144                if (fullPathFileNames != null) throw Messager.assertFail(
145                    "Annotation Placed:\n" +
146                    "    " + BCYAN + annotationAsStr + RESET + '\n' +
147                    "There are apparently multiple instances of the Annotation-Element " +
148                    "'FullPathFileNames' included with the @CSSLinks Annotation\n" +
149                    MsgPrintTools.annotationProcessingError(),
150                    JDUAnnotations.JSIMirror
151                );
152
153                fullPathFileNames = HELPER.handleStringArray
154                    (elemValue, "FullPathFileNames", JDUAnnotations.JSIMirror);
155            }
156
157            else throw Messager.assertFail(
158                "Annotation Placed:\n" +
159                "    " + BCYAN + annotationAsStr + RESET + '\n' +
160                "There was an Expression Variable-Name that was neither 'FileNames' nor " +
161                "'FullPathFileNames', but rather: " + elemName + '\n' +
162                MsgPrintTools.annotationProcessingError(),
163                JDUAnnotations.JSIMirror
164            );
165        }
166
167        this.fileNames          = fileNames;
168        this.fullPathFileNames  = fullPathFileNames;
169
170        if (MsgVerbose.isVerbose()) MsgVerbose.println(
171            "@JavaScriptImport Annotation-Processing Mirror Class:" +
172            "    FileNames: " + StrCSV.toCSV(this.fileNames, true, false, null) + '\n' +
173            "    FullPathFileNames: " + StrCSV.toCSV(this.fullPathFileNames, true, false, null)
174        );
175    }
176
177    // ********************************************************************************************
178    // ********************************************************************************************
179    // toString
180    // ********************************************************************************************
181    // ********************************************************************************************
182
183
184    /** {@inheritDoc} */ @Override
185    public String toString()
186    {
187        return "This annotation isn't fully functioning yet.  soon, but not right now.";
188    }
189}