Skip to content

Commit 74cff65

Browse files
committed
Adds interfaceIndex() to SupertypeList
Signed-off-by: Laird Nelson <[email protected]>
1 parent 89b8c20 commit 74cff65

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependency:
2727
<groupId>org.microbean</groupId>
2828
<artifactId>microbean-assign</artifactId>
2929
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-bean for up-to-date available versions. -->
30-
<version>0.0.1</version>
30+
<version>0.0.3</version>
3131
</dependency>
3232
```
3333

src/main/java/org/microbean/assign/SupertypeList.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@
2828
*/
2929
public final class SupertypeList extends AbstractList<TypeMirror> {
3030

31+
private final int interfaceIndex;
32+
3133
private final List<TypeMirror> sortedSupertypes;
3234

33-
SupertypeList(final List<? extends TypeMirror> sortedSupertypes) {
35+
SupertypeList(final List<? extends TypeMirror> sortedSupertypes, final int interfaceIndex) {
3436
super();
3537
if (sortedSupertypes.isEmpty()) {
3638
throw new IllegalArgumentException();
3739
}
3840
switch (sortedSupertypes) {
39-
case SupertypeList sl -> this.sortedSupertypes = sl.sortedSupertypes;
40-
default -> this.sortedSupertypes = List.copyOf(sortedSupertypes);
41+
case SupertypeList sl:
42+
this.sortedSupertypes = sl.sortedSupertypes;
43+
this.interfaceIndex = sl.interfaceIndex;
44+
break;
45+
default:
46+
this.sortedSupertypes = List.copyOf(sortedSupertypes);
47+
this.interfaceIndex = interfaceIndex;
4148
}
4249
}
4350

@@ -46,6 +53,17 @@ public final TypeMirror get(final int index) {
4653
return this.sortedSupertypes.get(index);
4754
}
4855

56+
/**
57+
* Returns the index of the first {@linkplain javax.lang.model.element.ElementKind#isInterface() interface type} this
58+
* {@link SupertypeList} contains, or a negative value if it contains no interface types.
59+
*
60+
* @return the index of the first {@linkplain javax.lang.model.element.ElementKind#isInterface() interface type} this
61+
* {@link SupertypeList} contains, or a negative value if it contains no interface types
62+
*/
63+
public final int interfaceIndex() {
64+
return this.interfaceIndex;
65+
}
66+
4967
@Override // AbstractList<TypeMirror>
5068
public final int size() {
5169
return this.sortedSupertypes.size();

src/main/java/org/microbean/assign/Types.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,12 @@ public final SupertypeList supertypes(final TypeMirror t, final Predicate<? supe
277277
supertypes(t, p, nonInterfaceTypes, interfaceTypes, newHashSet(13)); // arbitrary size
278278
nonInterfaceTypes.trimToSize();
279279
interfaceTypes.trimToSize();
280+
final int interfaceIndex = interfaceTypes.isEmpty() ? -1 : nonInterfaceTypes.size();
280281
return
281282
new SupertypeList(concat(nonInterfaceTypes.stream(), // non-interface supertypes are already sorted from most-specific to least
282283
interfaceTypes.stream().sorted(this.c)) // have to sort interfaces because you can extend them in any order
283-
.toList());
284+
.toList(),
285+
interfaceIndex);
284286
}
285287

286288
private final void supertypes(final TypeMirror t,

0 commit comments

Comments
 (0)