Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ as a Maven dependency:
Always check https://search.maven.org/artifact/org.microbean/microbean-construct
for up-to-date available versions.
-->
<version>0.0.4</version>
<version>0.0.5</version>
</dependency>
```

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/microbean/construct/DefaultDomain.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
*
* Copyright © 2024 microBean™.
* Copyright © 2024–2025 microBean™.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -320,7 +320,7 @@ public int hashCode() {

// (Convenience.)
@Override // Domain
public final UniversalElement javaLangObject() {
public UniversalElement javaLangObject() {
return UniversalElement.of(Domain.super.javaLangObject(), this);
}

Expand Down Expand Up @@ -421,6 +421,11 @@ public UniversalType primitiveType(TypeMirror t) {
}
}

@Override // Domain
public UniversalType rawType(final TypeMirror t) {
return UniversalType.of(Domain.super.rawType(t), this);
}

// (Canonical.)
@Override // Domain
public RecordComponentElement recordComponentElement(ExecutableElement e) {
Expand Down
66 changes: 52 additions & 14 deletions src/main/java/org/microbean/construct/Domain.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ public DeclaredType declaredType(final DeclaredType enclosingType,
* 10.1
*/
public default TypeMirror elementType(final TypeMirror t) {
return t.getKind() == TypeKind.ARRAY ? this.elementType(((ArrayType)t).getComponentType()) : t;
try (var lock = lock()) {
return t.getKind() == TypeKind.ARRAY ? this.elementType(((ArrayType)t).getComponentType()) : t;
}
}

/**
Expand Down Expand Up @@ -480,9 +482,11 @@ public default boolean generic(final Element e) {
* @exception NullPointerException if {@code e} is {@code null}
*/
public default boolean javaLangObject(final Element e) {
return
e.getKind() == ElementKind.CLASS &&
((QualifiedNameable)e).getQualifiedName().contentEquals("java.lang.Object");
try (var lock = this.lock()) {
return
e.getKind() == ElementKind.CLASS &&
((QualifiedNameable)e).getQualifiedName().contentEquals("java.lang.Object");
}
}

/**
Expand All @@ -499,9 +503,11 @@ public default boolean javaLangObject(final Element e) {
* @see #javaLangObject(Element)
*/
public default boolean javaLangObject(final TypeMirror t) {
return
t.getKind() == TypeKind.DECLARED &&
javaLangObject(((DeclaredType)t).asElement());
try (var lock = this.lock()) {
return
t.getKind() == TypeKind.DECLARED &&
javaLangObject(((DeclaredType)t).asElement());
}
}

/**
Expand Down Expand Up @@ -654,9 +660,11 @@ public default TypeElement javaLangObject() {
* @exception NullPointerException if {@code t} is {@code null}
*/
public default boolean parameterized(final TypeMirror t) {
return
t.getKind() == TypeKind.DECLARED &&
!((DeclaredType)t).getTypeArguments().isEmpty();
try (var lock = this.lock()) {
return
t.getKind() == TypeKind.DECLARED &&
!((DeclaredType)t).getTypeArguments().isEmpty();
}
}

/**
Expand Down Expand Up @@ -771,6 +779,34 @@ public default PrimitiveType primitiveType(final TypeElement e) {
// (Unboxing.)
public PrimitiveType primitiveType(final TypeMirror t);

/**
* A convenience method that returns {@code true} if and only if the supplied {@link TypeMirror} is a <dfn>raw
* type</dfn> according to <a href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8">the rules
* of the Java Language Specification</a>
*
* @param t a {@link TypeMirror}; must not be {@code null}
*
* @return {@code true} if and only if the supplied {@link TypeMirror} is a <dfn>raw type</dfn> according to <a
* href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8">the rules of the Java Language
* Specification</a>
*
* @exception NullPointerException if {@code t} is {@code null}
*
* @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8 Java Language Specification, section 4.8
*/
public default boolean raw(final TypeMirror t) {
try (var lock = this.lock()) {
return switch (t.getKind()) {
case ARRAY -> raw(elementType((ArrayType)t));
case DECLARED -> {
final DeclaredType dt = (DeclaredType)t;
yield generic(dt.asElement()) && dt.getTypeArguments().isEmpty();
}
default -> false;
};
}
}

/**
* A convenience method that returns the <dfn>raw type</dfn> corresponding to {@code t}, <strong>or {@code null} if
* {@code t} is <a href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8">incapable of yielding
Expand All @@ -789,10 +825,12 @@ public default PrimitiveType primitiveType(final TypeElement e) {
* @spec https://docs.oracle.com/javase/specs/jls/se23/html/jls-4.html#jls-4.8 Java Language Specification, section 4.8
*/
public default TypeMirror rawType(final TypeMirror t) {
return switch (t.getKind()) {
case ARRAY -> this.rawType(this.elementType(t)); // recursive
default -> this.parameterized(t) ? this.erasure(t) : null;
};
try (var lock = this.lock()) {
return switch (t.getKind()) {
case ARRAY -> this.rawType(this.elementType(t)); // recursive
default -> this.parameterized(t) ? this.erasure(t) : null;
};
}
}

/**
Expand Down
Loading