11/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
22 *
3- * Copyright © 2024 microBean™.
3+ * Copyright © 2024–2026 microBean™.
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
66 * the License. You may obtain a copy of the License at
8181import static org .microbean .construct .constant .ConstantDescs .CD_TypeParameterElement ;
8282import static org .microbean .construct .constant .ConstantDescs .CD_TypeMirror ;
8383import static org .microbean .construct .constant .ConstantDescs .CD_TypeVariable ;
84+ import static org .microbean .construct .constant .ConstantDescs .CD_VariableElement ;
8485import static org .microbean .construct .constant .ConstantDescs .CD_WildcardType ;
8586
8687/**
@@ -119,7 +120,7 @@ public static final Optional<? extends ConstantDesc> describe(final Name n, fina
119120 default -> (d instanceof Constable c ? c .describeConstable () : Optional .<ConstantDesc >empty ())
120121 .map (domainDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
121122 ofMethod (VIRTUAL ,
122- ClassDesc . of ( Domain .class .getName () ),
123+ Domain .class .describeConstable (). orElseThrow ( ),
123124 "name" ,
124125 MethodTypeDesc .of (CD_Name ,
125126 CD_CharSequence )),
@@ -218,7 +219,7 @@ public static final Optional<? extends ConstantDesc> describe(final ExecutableEl
218219 final ConstantDesc [] args = new ConstantDesc [5 + parameterCount ];
219220 args [0 ] =
220221 ofMethod (VIRTUAL ,
221- ClassDesc . of ( Domain .class .getName () ),
222+ Domain .class .describeConstable (). orElseThrow ( ),
222223 "executableElement" ,
223224 MethodTypeDesc .of (CD_ExecutableElement ,
224225 CD_TypeElement ,
@@ -271,7 +272,7 @@ public static final Optional<? extends ConstantDesc> describe(final ModuleElemen
271272 default -> describe (e .getQualifiedName (), d ) // getQualifiedName() does not cause symbol completion
272273 .map (nameDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
273274 ofMethod (VIRTUAL ,
274- ClassDesc . of ( Domain .class .getName () ),
275+ Domain .class .describeConstable (). orElseThrow ( ),
275276 "moduleElement" ,
276277 MethodTypeDesc .of (CD_ModuleElement ,
277278 CD_CharSequence )),
@@ -300,7 +301,7 @@ public static final Optional<? extends ConstantDesc> describe(final PackageEleme
300301 default -> describe (e .getQualifiedName (), d ) // getQualifiedName() does not cause symbol completion
301302 .map (nameDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
302303 ofMethod (VIRTUAL ,
303- ClassDesc . of ( Domain .class .getName () ),
304+ Domain .class .describeConstable (). orElseThrow ( ),
304305 "packageElement" ,
305306 MethodTypeDesc .of (CD_PackageElement ,
306307 CD_CharSequence )),
@@ -329,7 +330,7 @@ public static final Optional<? extends ConstantDesc> describe(final TypeElement
329330 default -> describe (e .getQualifiedName (), d ) // getQualifiedName() does not cause symbol completion
330331 .map (nameDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
331332 ofMethod (VIRTUAL ,
332- ClassDesc . of ( Domain .class .getName () ),
333+ Domain .class .describeConstable (). orElseThrow ( ),
333334 "typeElement" ,
334335 MethodTypeDesc .of (CD_TypeElement ,
335336 CD_CharSequence )),
@@ -361,7 +362,7 @@ yield describe(e.getEnclosingElement(), d)
361362 .flatMap (parameterizableDesc -> describe (e .getSimpleName (), d )
362363 .map (nameDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
363364 ofMethod (VIRTUAL ,
364- ClassDesc . of ( Domain .class .getName () ),
365+ Domain .class .describeConstable (). orElseThrow ( ),
365366 "typeParameterElement" ,
366367 MethodTypeDesc .of (CD_TypeParameterElement ,
367368 CD_Parameterizable ,
@@ -396,7 +397,7 @@ public static final Optional<? extends ConstantDesc> describe(final RecordCompon
396397 yield describe ((TypeElement )e .getEnclosingElement (), d )
397398 .map (executableDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
398399 ofMethod (VIRTUAL ,
399- ClassDesc . of ( Domain .class .getName () ),
400+ Domain .class .describeConstable (). orElseThrow ( ),
400401 "recordComponentElement" ,
401402 MethodTypeDesc .of (CD_RecordComponentElement ,
402403 CD_ExecutableElement )),
@@ -430,11 +431,13 @@ yield describe(e.getSimpleName(), d)
430431 .flatMap (nameDesc -> describe (e .getEnclosingElement (), d )
431432 .map (enclosingElementDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
432433 ofMethod (VIRTUAL ,
433- ClassDesc . of ( Domain .class .getName () ),
434+ Domain .class .describeConstable (). orElseThrow ( ),
434435 "variableElement" ,
435- MethodTypeDesc .of (CD_Element ,
436+ MethodTypeDesc .of (CD_VariableElement ,
437+ CD_Element ,
436438 CD_CharSequence )),
437439 ((Constable )d ).describeConstable ().orElseThrow (),
440+ enclosingElementDesc ,
438441 nameDesc )));
439442 }
440443 }
@@ -498,7 +501,7 @@ public static final Optional<? extends ConstantDesc> describe(final ArrayType t,
498501 yield describe (t .getComponentType (), d )
499502 .map (componentTypeDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
500503 ofMethod (VIRTUAL ,
501- ClassDesc . of ( Domain .class .getName () ),
504+ Domain .class .describeConstable (). orElseThrow ( ),
502505 "arrayTypeOf" ,
503506 MethodTypeDesc .of (CD_ArrayType ,
504507 CD_TypeMirror )),
@@ -540,7 +543,7 @@ yield switch (t.getKind()) {
540543 final TypeMirror enclosingType = t .getEnclosingType ();
541544 // Call
542545 args [0 ] = ofMethod (VIRTUAL ,
543- ClassDesc . of ( Domain .class .getName () ),
546+ Domain .class .describeConstable (). orElseThrow ( ),
544547 "declaredType" ,
545548 MethodTypeDesc .of (CD_DeclaredType ,
546549 CD_DeclaredType ,
@@ -597,7 +600,7 @@ public static final Optional<? extends ConstantDesc> describe(final NoType t, fi
597600 yield t .getKind ().describeConstable ()
598601 .map (typeKindDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
599602 ofMethod (VIRTUAL ,
600- ClassDesc . of ( Domain .class .getName () ),
603+ Domain .class .describeConstable (). orElseThrow ( ),
601604 "noType" ,
602605 MethodTypeDesc .of (CD_NoType ,
603606 CD_TypeKind )),
@@ -628,7 +631,7 @@ public static final Optional<? extends ConstantDesc> describe(final NullType t,
628631 default -> (d instanceof Constable c ? c .describeConstable () : Optional .<ConstantDesc >empty ())
629632 .map (domainDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
630633 ofMethod (VIRTUAL ,
631- ClassDesc . of ( Domain .class .getName () ),
634+ Domain .class .describeConstable (). orElseThrow ( ),
632635 "nullType" ,
633636 MethodTypeDesc .of (CD_NullType )),
634637 domainDesc ));
@@ -661,7 +664,7 @@ public static final Optional<? extends ConstantDesc> describe(final PrimitiveTyp
661664 yield t .getKind ().describeConstable ()
662665 .map (typeKindDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
663666 ofMethod (VIRTUAL ,
664- ClassDesc . of ( Domain .class .getName () ),
667+ Domain .class .describeConstable (). orElseThrow ( ),
665668 "primitiveType" ,
666669 MethodTypeDesc .of (CD_PrimitiveType ,
667670 CD_TypeKind )),
@@ -703,7 +706,7 @@ public static final Optional<? extends ConstantDesc> describe(final TypeVariable
703706 final String name = d .toString (e .getSimpleName ());
704707 yield Optional .of (DynamicConstantDesc .of (BSM_INVOKE ,
705708 ofMethod (VIRTUAL ,
706- ClassDesc . of ( Domain .class .getName () ),
709+ Domain .class .describeConstable (). orElseThrow ( ),
707710 "typeVariable" ,
708711 MethodTypeDesc .of (CD_TypeVariable ,
709712 CD_Parameterizable ,
@@ -740,7 +743,7 @@ yield describe(t.getExtendsBound(), d)
740743 .flatMap (extendsBoundDesc -> describe (t .getSuperBound (), d )
741744 .map (superBoundDesc -> DynamicConstantDesc .of (BSM_INVOKE ,
742745 ofMethod (VIRTUAL ,
743- ClassDesc . of ( Domain .class .getName () ),
746+ Domain .class .describeConstable (). orElseThrow ( ),
744747 "wildcardType" ,
745748 MethodTypeDesc .of (CD_WildcardType ,
746749 CD_TypeMirror ,
@@ -754,10 +757,8 @@ yield describe(t.getExtendsBound(), d)
754757 }
755758
756759 /**
757- * Returns a nominal descriptor for the supplied {@link List}, or an {@linkplain Optional#empty() empty} {@link
758- * Optional} if the supplied {@link List} cannot be described.
759- *
760- * @param <E> the supplied {@code list}'s element type
760+ * Returns a non-{@code null} nominal descriptor for the supplied {@link List}, or an {@linkplain Optional#empty()
761+ * empty} {@link Optional} if the supplied {@link List} cannot be described.
761762 *
762763 * @param list a {@link List} to be described; may be {@code null}; if non-{@code null} <strong>must be immutable and
763764 * must not contain {@code null} elements</strong> or undefined behavior will result
@@ -766,10 +767,10 @@ yield describe(t.getExtendsBound(), d)
766767 *
767768 * @see #describe(List, Function)
768769 */
769- public static final < E > Optional <? extends ConstantDesc > describe (final List <? extends E > list ) {
770+ public static final Optional <? extends ConstantDesc > describe (final List <?> list ) {
770771 return describe (list , e -> e instanceof Constable c ? c .describeConstable () : Optional .empty ());
771772 }
772-
773+
773774 /**
774775 * Returns a nominal descriptor for the supplied {@link List}, or an {@linkplain Optional#empty() empty} {@link
775776 * Optional} if the supplied {@link List} cannot be described.
@@ -814,14 +815,14 @@ public static final <E> Optional<? extends ConstantDesc> describe(final List<? e
814815 // After 10 parameters, List.of() falls back to varargs.
815816 ofMethodTypeDesc = MethodTypeDesc .of (CD_List , CD_Object .arrayType ());
816817 }
817- final ConstantDesc [] args = new ConstantDesc [++ size ];
818+ final ConstantDesc [] args = new ConstantDesc [size + 1 ];
818819 args [0 ] = ofMethod (INTERFACE_STATIC , CD_List , "of" , ofMethodTypeDesc );
819- for (int i = 1 ; i < size ; i ++) {
820+ for (int i = 0 ; i < size ; i ++) {
820821 final ConstantDesc eDesc = f .apply (list .get (i )).orElse (null );
821822 if (eDesc == null ) {
822823 yield Optional .empty ();
823824 }
824- args [i ] = eDesc ;
825+ args [i + 1 ] = eDesc ;
825826 }
826827 yield Optional .of (DynamicConstantDesc .of (BSM_INVOKE , args ));
827828 }
@@ -879,7 +880,7 @@ public static <K, V> Optional<? extends ConstantDesc> describe(final Map<? exten
879880 // After 20 parameters, Map.of() falls back to varargs.
880881 ofMethodTypeDesc = MethodTypeDesc .of (CD_Map , CD_Object .arrayType ());
881882 }
882- final ConstantDesc [] args = new ConstantDesc [++ size ];
883+ final ConstantDesc [] args = new ConstantDesc [size + 1 ];
883884 args [0 ] = ofMethod (INTERFACE_STATIC , CD_Map , "of" , ofMethodTypeDesc );
884885 int i = 1 ;
885886 for (final Entry <? extends K , ? extends V > e : map .entrySet ()) {
@@ -891,9 +892,8 @@ public static <K, V> Optional<? extends ConstantDesc> describe(final Map<? exten
891892 if (vDesc == null ) {
892893 yield Optional .empty ();
893894 }
894- args [i ] = kDesc ;
895- args [++i ] = vDesc ;
896- ++i ;
895+ args [i ++] = kDesc ;
896+ args [i ++] = vDesc ;
897897 }
898898 yield Optional .of (DynamicConstantDesc .of (BSM_INVOKE , args ));
899899 }
0 commit comments