diff --git a/README.md b/README.md
index 5eaa63b..f38c512 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@ dependency:
org.microbean
microbean-assign
- 0.0.1
+ 0.0.3
```
diff --git a/src/main/java/org/microbean/assign/SupertypeList.java b/src/main/java/org/microbean/assign/SupertypeList.java
index c503c6e..4405ec5 100644
--- a/src/main/java/org/microbean/assign/SupertypeList.java
+++ b/src/main/java/org/microbean/assign/SupertypeList.java
@@ -28,16 +28,23 @@
*/
public final class SupertypeList extends AbstractList {
+ private final int interfaceIndex;
+
private final List sortedSupertypes;
- SupertypeList(final List extends TypeMirror> sortedSupertypes) {
+ SupertypeList(final List extends TypeMirror> sortedSupertypes, final int interfaceIndex) {
super();
if (sortedSupertypes.isEmpty()) {
throw new IllegalArgumentException();
}
switch (sortedSupertypes) {
- case SupertypeList sl -> this.sortedSupertypes = sl.sortedSupertypes;
- default -> this.sortedSupertypes = List.copyOf(sortedSupertypes);
+ case SupertypeList sl:
+ this.sortedSupertypes = sl.sortedSupertypes;
+ this.interfaceIndex = sl.interfaceIndex;
+ break;
+ default:
+ this.sortedSupertypes = List.copyOf(sortedSupertypes);
+ this.interfaceIndex = interfaceIndex;
}
}
@@ -46,6 +53,17 @@ public final TypeMirror get(final int index) {
return this.sortedSupertypes.get(index);
}
+ /**
+ * Returns the index of the first {@linkplain javax.lang.model.element.ElementKind#isInterface() interface type} this
+ * {@link SupertypeList} contains, or a negative value if it contains no interface types.
+ *
+ * @return the index of the first {@linkplain javax.lang.model.element.ElementKind#isInterface() interface type} this
+ * {@link SupertypeList} contains, or a negative value if it contains no interface types
+ */
+ public final int interfaceIndex() {
+ return this.interfaceIndex;
+ }
+
@Override // AbstractList
public final int size() {
return this.sortedSupertypes.size();
diff --git a/src/main/java/org/microbean/assign/Types.java b/src/main/java/org/microbean/assign/Types.java
index d86b53e..8d32f95 100644
--- a/src/main/java/org/microbean/assign/Types.java
+++ b/src/main/java/org/microbean/assign/Types.java
@@ -277,10 +277,12 @@ public final SupertypeList supertypes(final TypeMirror t, final Predicate supe
supertypes(t, p, nonInterfaceTypes, interfaceTypes, newHashSet(13)); // arbitrary size
nonInterfaceTypes.trimToSize();
interfaceTypes.trimToSize();
+ final int interfaceIndex = interfaceTypes.isEmpty() ? -1 : nonInterfaceTypes.size();
return
new SupertypeList(concat(nonInterfaceTypes.stream(), // non-interface supertypes are already sorted from most-specific to least
interfaceTypes.stream().sorted(this.c)) // have to sort interfaces because you can extend them in any order
- .toList());
+ .toList(),
+ interfaceIndex);
}
private final void supertypes(final TypeMirror t,