@@ -122,7 +122,7 @@ private static JsonArray convertToJsonArray(String @Nullable ... strings) {
122122 * @param syntaxInfo the syntax info element to generate the documentation object of
123123 * @return the JsonObject representing the documentation of the provided syntax element
124124 */
125- private static JsonObject generatedAnnotatedElement (SyntaxInfo <?> syntaxInfo ) {
125+ private JsonObject generatedAnnotatedElement (SyntaxInfo <?> syntaxInfo ) {
126126 Class <?> syntaxClass = syntaxInfo .type ();
127127 Name name = syntaxClass .getAnnotation (Name .class );
128128 if (name == null || syntaxClass .getAnnotation (NoDoc .class ) != null )
@@ -189,7 +189,7 @@ private static JsonObject generatedAnnotatedElement(SyntaxInfo<?> syntaxInfo) {
189189 * @param events The events annotation.
190190 * @return A json array with the formatted events value, or null if there is no annotation.
191191 */
192- private static @ Nullable JsonArray getAnnotatedEvents (Events events ) {
192+ private @ Nullable JsonArray getAnnotatedEvents (Events events ) {
193193 if (events == null || events .value () == null ) {
194194 return null ;
195195 }
@@ -199,8 +199,43 @@ private static JsonObject generatedAnnotatedElement(SyntaxInfo<?> syntaxInfo) {
199199 for (String event : events .value ()) {
200200 JsonObject object = new JsonObject ();
201201
202- object .addProperty ("id" , event );
203- object .addProperty ("name" , event );
202+ // determine candidate infos
203+ List <BukkitSyntaxInfos .Event <?>> candidates = new ArrayList <>();
204+ for (BukkitSyntaxInfos .Event <?> info : source .syntaxRegistry ().syntaxes (BukkitSyntaxInfos .Event .KEY )) {
205+ String infoName = info .name ().toLowerCase (Locale .ENGLISH );
206+ if (infoName .startsWith ("on " )) {
207+ infoName = infoName .substring (3 );
208+ }
209+ if (infoName .equals (event .toLowerCase (Locale .ENGLISH )) || info .id ().equals (event )) {
210+ candidates .add (info );
211+ } else if (event .equals (info .documentationId ())) { // should be unique, this is an exact match
212+ candidates .clear ();
213+ candidates .add (info );
214+ break ;
215+ }
216+ }
217+
218+ // determine id, name
219+ String id ;
220+ String name ;
221+ if (candidates .isEmpty ()) {
222+ throw new IllegalArgumentException ("No matching info found for event annotation: " + event );
223+ } else if (candidates .size () == 1 ) {
224+ var info = candidates .getFirst ();
225+ id = info .documentationId ();
226+ if (id == null ) {
227+ id = info .id ();
228+ }
229+ name = info .name ();
230+ } else {
231+ // TODO other options?
232+ throw new IllegalArgumentException ("Multiple matching info found for event annotation: " + event +
233+ "\n Differentiate by specifying a documentationId on the relevant event infos." );
234+ }
235+
236+ // add properties
237+ object .addProperty ("id" , id );
238+ object .addProperty ("name" , name );
204239
205240 array .add (object );
206241 }
@@ -216,10 +251,16 @@ private static JsonObject generatedAnnotatedElement(SyntaxInfo<?> syntaxInfo) {
216251 */
217252 private static @ NotNull JsonObject getExpressionReturnTypes (DefaultSyntaxInfos .Expression <?, ?> expression ) {
218253 ClassInfo <?> exact = Classes .getSuperClassInfo (expression .returnType ());
254+ String name = Objects .requireNonNullElse (exact .getDocName (), exact .getName ().getSingular ());
255+ if (name .equals (ClassInfo .NO_DOC )) { // undocumented type is not helpful
256+ // hopefully the supertype has something better...
257+ exact = Classes .getSuperClassInfo (expression .returnType ().getSuperclass ());
258+ name = Objects .requireNonNullElse (exact .getDocName (), exact .getName ().getSingular ());
259+ }
219260
220261 JsonObject object = new JsonObject ();
221262 object .addProperty ("id" , exact .getCodeName ());
222- object .addProperty ("name" , exact . getName (). getSingular () );
263+ object .addProperty ("name" , name );
223264 return object ;
224265 }
225266
@@ -338,7 +379,7 @@ private static boolean isCancellable(BukkitSyntaxInfos.Event<?> info) {
338379 * @param infos the structures to generate documentation for
339380 * @return a JsonArray containing the documentation JsonObjects for each structure
340381 */
341- private static <T extends SyntaxInfo <? extends Structure >> JsonArray generateStructureElementArray (Collection <T > infos ) {
382+ private <T extends SyntaxInfo <? extends Structure >> JsonArray generateStructureElementArray (Collection <T > infos ) {
342383 JsonArray syntaxArray = new JsonArray ();
343384 infos .forEach (info -> {
344385 if (info instanceof BukkitSyntaxInfos .Event <?> eventInfo ) {
@@ -358,7 +399,7 @@ private static <T extends SyntaxInfo<? extends Structure>> JsonArray generateStr
358399 * @param infos the syntax elements to generate documentation for
359400 * @return a JsonArray containing the documentation JsonObjects for each syntax element
360401 */
361- private static <T extends SyntaxInfo <? extends SyntaxElement >> JsonArray generateSyntaxElementArray (Collection <T > infos ) {
402+ private <T extends SyntaxInfo <? extends SyntaxElement >> JsonArray generateSyntaxElementArray (Collection <T > infos ) {
362403 JsonArray syntaxArray = new JsonArray ();
363404 infos .forEach (info -> {
364405 JsonObject syntaxJsonObject = generatedAnnotatedElement (info );
0 commit comments