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 @@ -27,7 +27,7 @@ dependency:
<groupId>org.microbean</groupId>
<artifactId>microbean-assign</artifactId>
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-bean for up-to-date available versions. -->
<version>0.0.1</version>
<version>0.0.3</version>
</dependency>
```

Expand Down
24 changes: 21 additions & 3 deletions src/main/java/org/microbean/assign/SupertypeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@
*/
public final class SupertypeList extends AbstractList<TypeMirror> {

private final int interfaceIndex;

private final List<TypeMirror> 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;
}
}

Expand All @@ -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<TypeMirror>
public final int size() {
return this.sortedSupertypes.size();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/microbean/assign/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down