@@ -358,7 +358,9 @@ public DeclaredType declaredType(final DeclaredType enclosingType,
358358 * 10.1
359359 */
360360 public default TypeMirror elementType (final TypeMirror t ) {
361- return t .getKind () == TypeKind .ARRAY ? this .elementType (((ArrayType )t ).getComponentType ()) : t ;
361+ try (var lock = lock ()) {
362+ return t .getKind () == TypeKind .ARRAY ? this .elementType (((ArrayType )t ).getComponentType ()) : t ;
363+ }
362364 }
363365
364366 /**
@@ -480,9 +482,11 @@ public default boolean generic(final Element e) {
480482 * @exception NullPointerException if {@code e} is {@code null}
481483 */
482484 public default boolean javaLangObject (final Element e ) {
483- return
484- e .getKind () == ElementKind .CLASS &&
485- ((QualifiedNameable )e ).getQualifiedName ().contentEquals ("java.lang.Object" );
485+ try (var lock = this .lock ()) {
486+ return
487+ e .getKind () == ElementKind .CLASS &&
488+ ((QualifiedNameable )e ).getQualifiedName ().contentEquals ("java.lang.Object" );
489+ }
486490 }
487491
488492 /**
@@ -499,9 +503,11 @@ public default boolean javaLangObject(final Element e) {
499503 * @see #javaLangObject(Element)
500504 */
501505 public default boolean javaLangObject (final TypeMirror t ) {
502- return
503- t .getKind () == TypeKind .DECLARED &&
504- javaLangObject (((DeclaredType )t ).asElement ());
506+ try (var lock = this .lock ()) {
507+ return
508+ t .getKind () == TypeKind .DECLARED &&
509+ javaLangObject (((DeclaredType )t ).asElement ());
510+ }
505511 }
506512
507513 /**
@@ -654,9 +660,11 @@ public default TypeElement javaLangObject() {
654660 * @exception NullPointerException if {@code t} is {@code null}
655661 */
656662 public default boolean parameterized (final TypeMirror t ) {
657- return
658- t .getKind () == TypeKind .DECLARED &&
659- !((DeclaredType )t ).getTypeArguments ().isEmpty ();
663+ try (var lock = this .lock ()) {
664+ return
665+ t .getKind () == TypeKind .DECLARED &&
666+ !((DeclaredType )t ).getTypeArguments ().isEmpty ();
667+ }
660668 }
661669
662670 /**
@@ -771,6 +779,34 @@ public default PrimitiveType primitiveType(final TypeElement e) {
771779 // (Unboxing.)
772780 public PrimitiveType primitiveType (final TypeMirror t );
773781
782+ /**
783+ * A convenience method that returns {@code true} if and only if the supplied {@link TypeMirror} is a <dfn>raw
784+ * type</dfn> according to <a href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8">the rules
785+ * of the Java Language Specification</a>
786+ *
787+ * @param t a {@link TypeMirror}; must not be {@code null}
788+ *
789+ * @return {@code true} if and only if the supplied {@link TypeMirror} is a <dfn>raw type</dfn> according to <a
790+ * href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8">the rules of the Java Language
791+ * Specification</a>
792+ *
793+ * @exception NullPointerException if {@code t} is {@code null}
794+ *
795+ * @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8 Java Language Specification, section 4.8
796+ */
797+ public default boolean raw (final TypeMirror t ) {
798+ try (var lock = this .lock ()) {
799+ return switch (t .getKind ()) {
800+ case ARRAY -> raw (elementType ((ArrayType )t ));
801+ case DECLARED -> {
802+ final DeclaredType dt = (DeclaredType )t ;
803+ yield generic (dt .asElement ()) && dt .getTypeArguments ().isEmpty ();
804+ }
805+ default -> false ;
806+ };
807+ }
808+ }
809+
774810 /**
775811 * A convenience method that returns the <dfn>raw type</dfn> corresponding to {@code t}, <strong>or {@code null} if
776812 * {@code t} is <a href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8">incapable of yielding
@@ -789,10 +825,12 @@ public default PrimitiveType primitiveType(final TypeElement e) {
789825 * @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8 Java Language Specification, section 4.8
790826 */
791827 public default TypeMirror rawType (final TypeMirror t ) {
792- return switch (t .getKind ()) {
793- case ARRAY -> this .rawType (this .elementType (t )); // recursive
794- default -> this .parameterized (t ) ? this .erasure (t ) : null ;
795- };
828+ try (var lock = this .lock ()) {
829+ return switch (t .getKind ()) {
830+ case ARRAY -> this .rawType (this .elementType (t )); // recursive
831+ default -> this .parameterized (t ) ? this .erasure (t ) : null ;
832+ };
833+ }
796834 }
797835
798836 /**
0 commit comments