Skip to content

Commit 7c98dc1

Browse files
authored
Adds generic(TypeMirror) method to Domain (#16)
Signed-off-by: Laird Nelson <[email protected]>
1 parent aa84a7f commit 7c98dc1

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
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.5</version>
34+
<version>0.0.8</version>
3535
</dependency>
3636
```
3737

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,44 @@ yield switch (e.getKind()) {
514514
};
515515
}
516516

517+
/**
518+
* A convenience method that returns {@code true} if and only if the supplied {@link TypeMirror} is declared by an
519+
* {@link Element} that {@linkplain #generic(Element) is generic}.
520+
*
521+
* @param t a {@link TypeMirror}; must not be {@code null}
522+
*
523+
* @return {@code true} if and only if the supplied {@link TypeMirror} is declared by an {@link Element} that
524+
* {@linkplain #generic(Element) is generic}
525+
*
526+
* @exception NullPointerException if {@code t} is {@code null}
527+
*
528+
* @see #generic(Element)
529+
*
530+
* @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-8.html#jls-8.1.2 Java Language Specification, section
531+
* 8.1.2
532+
*
533+
* @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-8.html#jls-8.4.4 Java Language Specification, section
534+
* 8.4.4
535+
*
536+
* @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-8.html#jls-8.8.4 Java Language Specification, section
537+
* 8.8.4
538+
*
539+
* @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-9.html#jls-9.1.2 Java Language Specification, section
540+
* 9.1.2
541+
*/
542+
public default boolean generic(final TypeMirror t) {
543+
return switch (t) {
544+
case null -> throw new NullPointerException("t");
545+
case UniversalType ut -> ut.generic();
546+
default -> {
547+
try (var lock = this.lock()) {
548+
final Element e = this.asElement(t);
549+
yield e != null && this.generic(e);
550+
}
551+
}
552+
};
553+
}
554+
517555
/**
518556
* A convenience method that returns {@code true} if and only if the supplied {@link Element} represents the (essentially
519557
* primordial) {@code java.lang.Object} {@link Element}.

src/main/java/org/microbean/construct/type/UniversalType.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ public final UniversalType erasure() {
159159
return t;
160160
}
161161

162+
/**
163+
* Returns {@code true} if and only if this {@link UniversalType} is declared by a {@linkplain
164+
* UniversalElement#generic() generic declaration}.
165+
*
166+
* @return {@code true} if and only if this {@link UniversalType} is declared by a {@linkplain
167+
* UniversalElement#generic() generic declaration}
168+
*
169+
* @see UniversalElement#generic()
170+
*
171+
* @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-8.html#jls-8.1.2 Java Language Specification, section
172+
* 8.1.2
173+
*/
174+
public final boolean generic() {
175+
final UniversalElement e = this.asElement();
176+
return e != null && e.generic();
177+
}
178+
162179
@Override // UnionType
163180
public final List<? extends UniversalType> getAlternatives() {
164181
return switch (this.getKind()) {

0 commit comments

Comments
 (0)