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