mirror of
https://codeberg.org/monocles/monocles_chat.git
synced 2025-01-15 22:22:22 +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.CaseFormat;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.ComparisonChain;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
import im.conversations.android.annotation.XmlElement;
|
import im.conversations.android.annotation.XmlElement;
|
||||||
import im.conversations.android.annotation.XmlPackage;
|
import im.conversations.android.annotation.XmlPackage;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.processing.AbstractProcessor;
|
import javax.annotation.processing.AbstractProcessor;
|
||||||
import javax.annotation.processing.Processor;
|
import javax.annotation.processing.Processor;
|
||||||
import javax.annotation.processing.RoundEnvironment;
|
import javax.annotation.processing.RoundEnvironment;
|
||||||
|
@ -38,7 +38,7 @@ public class XmlElementProcessor extends AbstractProcessor {
|
||||||
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
|
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
|
||||||
final Set<? extends Element> elements =
|
final Set<? extends Element> elements =
|
||||||
roundEnvironment.getElementsAnnotatedWith(XmlElement.class);
|
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) {
|
for (final Element element : elements) {
|
||||||
if (element instanceof final TypeElement typeElement) {
|
if (element instanceof final TypeElement typeElement) {
|
||||||
final Id id = of(typeElement);
|
final Id id = of(typeElement);
|
||||||
|
@ -160,7 +160,7 @@ public class XmlElementProcessor extends AbstractProcessor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Id {
|
public static class Id implements Comparable<Id> {
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String namespace;
|
public final String namespace;
|
||||||
|
|
||||||
|
@ -181,5 +181,13 @@ public class XmlElementProcessor extends AbstractProcessor {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(name, namespace);
|
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