Skip to content

Commit 0544960

Browse files
authored
Improves Domain and DefaultDomain classes (#13)
Signed-off-by: Laird Nelson <[email protected]>
1 parent 1e463cc commit 0544960

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ as a Maven dependency:
3131
Always check https://search.maven.org/artifact/org.microbean/microbean-construct
3232
for up-to-date available versions.
3333
-->
34-
<version>0.0.4</version>
34+
<version>0.0.5</version>
3535
</dependency>
3636
```
3737

src/main/java/org/microbean/construct/DefaultDomain.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
22
*
3-
* Copyright © 2024 microBean™.
3+
* Copyright © 2024–2025 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
@@ -320,7 +320,7 @@ public int hashCode() {
320320

321321
// (Convenience.)
322322
@Override // Domain
323-
public final UniversalElement javaLangObject() {
323+
public UniversalElement javaLangObject() {
324324
return UniversalElement.of(Domain.super.javaLangObject(), this);
325325
}
326326

@@ -421,6 +421,11 @@ public UniversalType primitiveType(TypeMirror t) {
421421
}
422422
}
423423

424+
@Override // Domain
425+
public UniversalType rawType(final TypeMirror t) {
426+
return UniversalType.of(Domain.super.rawType(t), this);
427+
}
428+
424429
// (Canonical.)
425430
@Override // Domain
426431
public RecordComponentElement recordComponentElement(ExecutableElement e) {

src/main/java/org/microbean/construct/Domain.java

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)