mirror of
https://codeberg.org/monocles/monocles_chat.git
synced 2025-01-15 14:12:21 +01:00
use sorted map in annotation processor
(cherry picked from commit 37f51949fda2f04cd64eab76a1cc91343695f52e)
This commit is contained in:
parent
0e6471c567
commit
f20b088ff9
1 changed files with 13 additions and 5 deletions
|
@ -4,17 +4,17 @@ import com.google.auto.service.AutoService;
|
|||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import im.conversations.android.annotation.XmlElement;
|
||||
import im.conversations.android.annotation.XmlPackage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.Processor;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
|
@ -38,7 +38,7 @@ public class XmlElementProcessor extends AbstractProcessor {
|
|||
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
|
||||
final Set<? extends Element> elements =
|
||||
roundEnvironment.getElementsAnnotatedWith(XmlElement.class);
|
||||
final ImmutableMap.Builder<Id, String> builder = ImmutableMap.builder();
|
||||
final ImmutableSortedMap.Builder<Id, String> builder = ImmutableSortedMap.naturalOrder();
|
||||
for (final Element element : elements) {
|
||||
if (element instanceof final TypeElement typeElement) {
|
||||
final Id id = of(typeElement);
|
||||
|
@ -160,7 +160,7 @@ public class XmlElementProcessor extends AbstractProcessor {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static class Id {
|
||||
public static class Id implements Comparable<Id> {
|
||||
public final String name;
|
||||
public final String namespace;
|
||||
|
||||
|
@ -181,5 +181,13 @@ public class XmlElementProcessor extends AbstractProcessor {
|
|||
public int hashCode() {
|
||||
return Objects.hashCode(name, namespace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@Nonnull Id id) {
|
||||
return ComparisonChain.start()
|
||||
.compare(namespace, id.namespace)
|
||||
.compare(name, id.name)
|
||||
.result();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue