tmap/smali_classes3/com/google/common/eventbus/SubscriberRegistry.smali
2022-06-10 21:38:30 +09:00

792 lines
22 KiB
Smali

.class final Lcom/google/common/eventbus/SubscriberRegistry;
.super Ljava/lang/Object;
.source "SubscriberRegistry.java"
# annotations
.annotation runtime Lcom/google/common/eventbus/ElementTypesAreNonnullByDefault;
.end annotation
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lcom/google/common/eventbus/SubscriberRegistry$MethodIdentifier;
}
.end annotation
# static fields
.field private static final flattenHierarchyCache:Lcom/google/common/cache/LoadingCache;
.annotation system Ldalvik/annotation/Signature;
value = {
"Lcom/google/common/cache/LoadingCache<",
"Ljava/lang/Class<",
"*>;",
"Lcom/google/common/collect/ImmutableSet<",
"Ljava/lang/Class<",
"*>;>;>;"
}
.end annotation
.end field
.field private static final subscriberMethodsCache:Lcom/google/common/cache/LoadingCache;
.annotation system Ldalvik/annotation/Signature;
value = {
"Lcom/google/common/cache/LoadingCache<",
"Ljava/lang/Class<",
"*>;",
"Lcom/google/common/collect/ImmutableList<",
"Ljava/lang/reflect/Method;",
">;>;"
}
.end annotation
.end field
# instance fields
.field private final bus:Lcom/google/common/eventbus/EventBus;
.annotation build Lcom/google/j2objc/annotations/Weak;
.end annotation
.end field
.field private final subscribers:Ljava/util/concurrent/ConcurrentMap;
.annotation system Ldalvik/annotation/Signature;
value = {
"Ljava/util/concurrent/ConcurrentMap<",
"Ljava/lang/Class<",
"*>;",
"Ljava/util/concurrent/CopyOnWriteArraySet<",
"Lcom/google/common/eventbus/Subscriber;",
">;>;"
}
.end annotation
.end field
# direct methods
.method public static constructor <clinit>()V
.locals 2
.line 1
invoke-static {}, Lcom/google/common/cache/CacheBuilder;->newBuilder()Lcom/google/common/cache/CacheBuilder;
move-result-object v0
.line 2
invoke-virtual {v0}, Lcom/google/common/cache/CacheBuilder;->weakKeys()Lcom/google/common/cache/CacheBuilder;
move-result-object v0
new-instance v1, Lcom/google/common/eventbus/SubscriberRegistry$1;
invoke-direct {v1}, Lcom/google/common/eventbus/SubscriberRegistry$1;-><init>()V
.line 3
invoke-virtual {v0, v1}, Lcom/google/common/cache/CacheBuilder;->build(Lcom/google/common/cache/CacheLoader;)Lcom/google/common/cache/LoadingCache;
move-result-object v0
sput-object v0, Lcom/google/common/eventbus/SubscriberRegistry;->subscriberMethodsCache:Lcom/google/common/cache/LoadingCache;
.line 4
invoke-static {}, Lcom/google/common/cache/CacheBuilder;->newBuilder()Lcom/google/common/cache/CacheBuilder;
move-result-object v0
.line 5
invoke-virtual {v0}, Lcom/google/common/cache/CacheBuilder;->weakKeys()Lcom/google/common/cache/CacheBuilder;
move-result-object v0
new-instance v1, Lcom/google/common/eventbus/SubscriberRegistry$2;
invoke-direct {v1}, Lcom/google/common/eventbus/SubscriberRegistry$2;-><init>()V
.line 6
invoke-virtual {v0, v1}, Lcom/google/common/cache/CacheBuilder;->build(Lcom/google/common/cache/CacheLoader;)Lcom/google/common/cache/LoadingCache;
move-result-object v0
sput-object v0, Lcom/google/common/eventbus/SubscriberRegistry;->flattenHierarchyCache:Lcom/google/common/cache/LoadingCache;
return-void
.end method
.method public constructor <init>(Lcom/google/common/eventbus/EventBus;)V
.locals 1
.line 1
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 2
invoke-static {}, Lcom/google/common/collect/Maps;->newConcurrentMap()Ljava/util/concurrent/ConcurrentMap;
move-result-object v0
iput-object v0, p0, Lcom/google/common/eventbus/SubscriberRegistry;->subscribers:Ljava/util/concurrent/ConcurrentMap;
.line 3
invoke-static {p1}, Lcom/google/common/base/Preconditions;->checkNotNull(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object p1
check-cast p1, Lcom/google/common/eventbus/EventBus;
iput-object p1, p0, Lcom/google/common/eventbus/SubscriberRegistry;->bus:Lcom/google/common/eventbus/EventBus;
return-void
.end method
.method public static synthetic access$000(Ljava/lang/Class;)Lcom/google/common/collect/ImmutableList;
.locals 0
.line 1
invoke-static {p0}, Lcom/google/common/eventbus/SubscriberRegistry;->getAnnotatedMethodsNotCached(Ljava/lang/Class;)Lcom/google/common/collect/ImmutableList;
move-result-object p0
return-object p0
.end method
.method private findAllSubscribers(Ljava/lang/Object;)Lcom/google/common/collect/Multimap;
.locals 5
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/lang/Object;",
")",
"Lcom/google/common/collect/Multimap<",
"Ljava/lang/Class<",
"*>;",
"Lcom/google/common/eventbus/Subscriber;",
">;"
}
.end annotation
.line 1
invoke-static {}, Lcom/google/common/collect/HashMultimap;->create()Lcom/google/common/collect/HashMultimap;
move-result-object v0
.line 2
invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;
move-result-object v1
.line 3
invoke-static {v1}, Lcom/google/common/eventbus/SubscriberRegistry;->getAnnotatedMethods(Ljava/lang/Class;)Lcom/google/common/collect/ImmutableList;
move-result-object v1
invoke-virtual {v1}, Lcom/google/common/collect/ImmutableList;->iterator()Lcom/google/common/collect/UnmodifiableIterator;
move-result-object v1
:goto_0
invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z
move-result v2
if-eqz v2, :cond_0
invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v2
check-cast v2, Ljava/lang/reflect/Method;
.line 4
invoke-virtual {v2}, Ljava/lang/reflect/Method;->getParameterTypes()[Ljava/lang/Class;
move-result-object v3
const/4 v4, 0x0
.line 5
aget-object v3, v3, v4
.line 6
iget-object v4, p0, Lcom/google/common/eventbus/SubscriberRegistry;->bus:Lcom/google/common/eventbus/EventBus;
invoke-static {v4, p1, v2}, Lcom/google/common/eventbus/Subscriber;->create(Lcom/google/common/eventbus/EventBus;Ljava/lang/Object;Ljava/lang/reflect/Method;)Lcom/google/common/eventbus/Subscriber;
move-result-object v2
invoke-interface {v0, v3, v2}, Lcom/google/common/collect/Multimap;->put(Ljava/lang/Object;Ljava/lang/Object;)Z
goto :goto_0
:cond_0
return-object v0
.end method
.method public static flattenHierarchy(Ljava/lang/Class;)Lcom/google/common/collect/ImmutableSet;
.locals 1
.annotation build Lcom/google/common/annotations/VisibleForTesting;
.end annotation
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/lang/Class<",
"*>;)",
"Lcom/google/common/collect/ImmutableSet<",
"Ljava/lang/Class<",
"*>;>;"
}
.end annotation
.line 1
:try_start_0
sget-object v0, Lcom/google/common/eventbus/SubscriberRegistry;->flattenHierarchyCache:Lcom/google/common/cache/LoadingCache;
invoke-interface {v0, p0}, Lcom/google/common/cache/LoadingCache;->getUnchecked(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object p0
check-cast p0, Lcom/google/common/collect/ImmutableSet;
:try_end_0
.catch Lcom/google/common/util/concurrent/UncheckedExecutionException; {:try_start_0 .. :try_end_0} :catch_0
return-object p0
:catch_0
move-exception p0
.line 2
invoke-virtual {p0}, Ljava/lang/RuntimeException;->getCause()Ljava/lang/Throwable;
move-result-object p0
invoke-static {p0}, Lcom/google/common/base/Throwables;->propagate(Ljava/lang/Throwable;)Ljava/lang/RuntimeException;
move-result-object p0
throw p0
.end method
.method private static getAnnotatedMethods(Ljava/lang/Class;)Lcom/google/common/collect/ImmutableList;
.locals 1
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/lang/Class<",
"*>;)",
"Lcom/google/common/collect/ImmutableList<",
"Ljava/lang/reflect/Method;",
">;"
}
.end annotation
.line 1
:try_start_0
sget-object v0, Lcom/google/common/eventbus/SubscriberRegistry;->subscriberMethodsCache:Lcom/google/common/cache/LoadingCache;
invoke-interface {v0, p0}, Lcom/google/common/cache/LoadingCache;->getUnchecked(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object p0
check-cast p0, Lcom/google/common/collect/ImmutableList;
:try_end_0
.catch Lcom/google/common/util/concurrent/UncheckedExecutionException; {:try_start_0 .. :try_end_0} :catch_0
return-object p0
:catch_0
move-exception p0
.line 2
invoke-virtual {p0}, Ljava/lang/RuntimeException;->getCause()Ljava/lang/Throwable;
move-result-object v0
invoke-static {v0}, Lcom/google/common/base/Throwables;->throwIfUnchecked(Ljava/lang/Throwable;)V
.line 3
throw p0
.end method
.method private static getAnnotatedMethodsNotCached(Ljava/lang/Class;)Lcom/google/common/collect/ImmutableList;
.locals 11
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/lang/Class<",
"*>;)",
"Lcom/google/common/collect/ImmutableList<",
"Ljava/lang/reflect/Method;",
">;"
}
.end annotation
.line 1
invoke-static {p0}, Lcom/google/common/reflect/TypeToken;->of(Ljava/lang/Class;)Lcom/google/common/reflect/TypeToken;
move-result-object p0
invoke-virtual {p0}, Lcom/google/common/reflect/TypeToken;->getTypes()Lcom/google/common/reflect/TypeToken$TypeSet;
move-result-object p0
invoke-virtual {p0}, Lcom/google/common/reflect/TypeToken$TypeSet;->rawTypes()Ljava/util/Set;
move-result-object p0
.line 2
invoke-static {}, Lcom/google/common/collect/Maps;->newHashMap()Ljava/util/HashMap;
move-result-object v0
.line 3
invoke-interface {p0}, Ljava/util/Set;->iterator()Ljava/util/Iterator;
move-result-object p0
:cond_0
invoke-interface {p0}, Ljava/util/Iterator;->hasNext()Z
move-result v1
if-eqz v1, :cond_3
invoke-interface {p0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Ljava/lang/Class;
.line 4
invoke-virtual {v1}, Ljava/lang/Class;->getDeclaredMethods()[Ljava/lang/reflect/Method;
move-result-object v1
array-length v2, v1
const/4 v3, 0x0
move v4, v3
:goto_0
if-ge v4, v2, :cond_0
aget-object v5, v1, v4
.line 5
const-class v6, Lcom/google/common/eventbus/Subscribe;
invoke-virtual {v5, v6}, Ljava/lang/reflect/Method;->isAnnotationPresent(Ljava/lang/Class;)Z
move-result v6
if-eqz v6, :cond_2
invoke-virtual {v5}, Ljava/lang/reflect/Method;->isSynthetic()Z
move-result v6
if-nez v6, :cond_2
.line 6
invoke-virtual {v5}, Ljava/lang/reflect/Method;->getParameterTypes()[Ljava/lang/Class;
move-result-object v6
.line 7
array-length v7, v6
const/4 v8, 0x1
if-ne v7, v8, :cond_1
move v7, v8
goto :goto_1
:cond_1
move v7, v3
:goto_1
array-length v9, v6
const-string v10, "Method %s has @Subscribe annotation but has %s parameters. Subscriber methods must have exactly 1 parameter."
invoke-static {v7, v10, v5, v9}, Lcom/google/common/base/Preconditions;->checkArgument(ZLjava/lang/String;Ljava/lang/Object;I)V
.line 8
aget-object v7, v6, v3
.line 9
invoke-virtual {v7}, Ljava/lang/Class;->isPrimitive()Z
move-result v7
xor-int/2addr v7, v8
aget-object v8, v6, v3
.line 10
invoke-virtual {v8}, Ljava/lang/Class;->getName()Ljava/lang/String;
move-result-object v8
aget-object v6, v6, v3
.line 11
invoke-static {v6}, Lcom/google/common/primitives/Primitives;->wrap(Ljava/lang/Class;)Ljava/lang/Class;
move-result-object v6
invoke-virtual {v6}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;
move-result-object v6
const-string v9, "@Subscribe method %s\'s parameter is %s. Subscriber methods cannot accept primitives. Consider changing the parameter to %s."
.line 12
invoke-static {v7, v9, v5, v8, v6}, Lcom/google/common/base/Preconditions;->checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
.line 13
new-instance v6, Lcom/google/common/eventbus/SubscriberRegistry$MethodIdentifier;
invoke-direct {v6, v5}, Lcom/google/common/eventbus/SubscriberRegistry$MethodIdentifier;-><init>(Ljava/lang/reflect/Method;)V
.line 14
invoke-interface {v0, v6}, Ljava/util/Map;->containsKey(Ljava/lang/Object;)Z
move-result v7
if-nez v7, :cond_2
.line 15
invoke-interface {v0, v6, v5}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
:cond_2
add-int/lit8 v4, v4, 0x1
goto :goto_0
.line 16
:cond_3
invoke-interface {v0}, Ljava/util/Map;->values()Ljava/util/Collection;
move-result-object p0
invoke-static {p0}, Lcom/google/common/collect/ImmutableList;->copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;
move-result-object p0
return-object p0
.end method
# virtual methods
.method public getSubscribers(Ljava/lang/Object;)Ljava/util/Iterator;
.locals 3
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/lang/Object;",
")",
"Ljava/util/Iterator<",
"Lcom/google/common/eventbus/Subscriber;",
">;"
}
.end annotation
.line 1
invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;
move-result-object p1
invoke-static {p1}, Lcom/google/common/eventbus/SubscriberRegistry;->flattenHierarchy(Ljava/lang/Class;)Lcom/google/common/collect/ImmutableSet;
move-result-object p1
.line 2
invoke-virtual {p1}, Ljava/util/AbstractCollection;->size()I
move-result v0
invoke-static {v0}, Lcom/google/common/collect/Lists;->newArrayListWithCapacity(I)Ljava/util/ArrayList;
move-result-object v0
.line 3
invoke-virtual {p1}, Lcom/google/common/collect/ImmutableSet;->iterator()Lcom/google/common/collect/UnmodifiableIterator;
move-result-object p1
:cond_0
:goto_0
invoke-interface {p1}, Ljava/util/Iterator;->hasNext()Z
move-result v1
if-eqz v1, :cond_1
invoke-interface {p1}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Ljava/lang/Class;
.line 4
iget-object v2, p0, Lcom/google/common/eventbus/SubscriberRegistry;->subscribers:Ljava/util/concurrent/ConcurrentMap;
invoke-interface {v2, v1}, Ljava/util/concurrent/ConcurrentMap;->get(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v1
check-cast v1, Ljava/util/concurrent/CopyOnWriteArraySet;
if-eqz v1, :cond_0
.line 5
invoke-virtual {v1}, Ljava/util/concurrent/CopyOnWriteArraySet;->iterator()Ljava/util/Iterator;
move-result-object v1
invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z
goto :goto_0
.line 6
:cond_1
invoke-interface {v0}, Ljava/util/List;->iterator()Ljava/util/Iterator;
move-result-object p1
invoke-static {p1}, Lcom/google/common/collect/Iterators;->concat(Ljava/util/Iterator;)Ljava/util/Iterator;
move-result-object p1
return-object p1
.end method
.method public getSubscribersForTesting(Ljava/lang/Class;)Ljava/util/Set;
.locals 1
.annotation build Lcom/google/common/annotations/VisibleForTesting;
.end annotation
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/lang/Class<",
"*>;)",
"Ljava/util/Set<",
"Lcom/google/common/eventbus/Subscriber;",
">;"
}
.end annotation
.line 1
iget-object v0, p0, Lcom/google/common/eventbus/SubscriberRegistry;->subscribers:Ljava/util/concurrent/ConcurrentMap;
invoke-interface {v0, p1}, Ljava/util/concurrent/ConcurrentMap;->get(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object p1
check-cast p1, Ljava/util/AbstractCollection;
invoke-static {}, Lcom/google/common/collect/ImmutableSet;->of()Lcom/google/common/collect/ImmutableSet;
move-result-object v0
invoke-static {p1, v0}, Lcom/google/common/base/MoreObjects;->firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
move-result-object p1
check-cast p1, Ljava/util/Set;
return-object p1
.end method
.method public register(Ljava/lang/Object;)V
.locals 4
.line 1
invoke-direct {p0, p1}, Lcom/google/common/eventbus/SubscriberRegistry;->findAllSubscribers(Ljava/lang/Object;)Lcom/google/common/collect/Multimap;
move-result-object p1
.line 2
invoke-interface {p1}, Lcom/google/common/collect/Multimap;->asMap()Ljava/util/Map;
move-result-object p1
invoke-interface {p1}, Ljava/util/Map;->entrySet()Ljava/util/Set;
move-result-object p1
invoke-interface {p1}, Ljava/util/Set;->iterator()Ljava/util/Iterator;
move-result-object p1
:goto_0
invoke-interface {p1}, Ljava/util/Iterator;->hasNext()Z
move-result v0
if-eqz v0, :cond_1
invoke-interface {p1}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v0
check-cast v0, Ljava/util/Map$Entry;
.line 3
invoke-interface {v0}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;
move-result-object v1
check-cast v1, Ljava/lang/Class;
.line 4
invoke-interface {v0}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;
move-result-object v0
check-cast v0, Ljava/util/Collection;
.line 5
iget-object v2, p0, Lcom/google/common/eventbus/SubscriberRegistry;->subscribers:Ljava/util/concurrent/ConcurrentMap;
invoke-interface {v2, v1}, Ljava/util/concurrent/ConcurrentMap;->get(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v2
check-cast v2, Ljava/util/concurrent/CopyOnWriteArraySet;
if-nez v2, :cond_0
.line 6
new-instance v2, Ljava/util/concurrent/CopyOnWriteArraySet;
invoke-direct {v2}, Ljava/util/concurrent/CopyOnWriteArraySet;-><init>()V
.line 7
iget-object v3, p0, Lcom/google/common/eventbus/SubscriberRegistry;->subscribers:Ljava/util/concurrent/ConcurrentMap;
.line 8
invoke-interface {v3, v1, v2}, Ljava/util/concurrent/ConcurrentMap;->putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v1
check-cast v1, Ljava/util/concurrent/CopyOnWriteArraySet;
invoke-static {v1, v2}, Lcom/google/common/base/MoreObjects;->firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v1
move-object v2, v1
check-cast v2, Ljava/util/concurrent/CopyOnWriteArraySet;
.line 9
:cond_0
invoke-virtual {v2, v0}, Ljava/util/concurrent/CopyOnWriteArraySet;->addAll(Ljava/util/Collection;)Z
goto :goto_0
:cond_1
return-void
.end method
.method public unregister(Ljava/lang/Object;)V
.locals 4
.line 1
invoke-direct {p0, p1}, Lcom/google/common/eventbus/SubscriberRegistry;->findAllSubscribers(Ljava/lang/Object;)Lcom/google/common/collect/Multimap;
move-result-object v0
.line 2
invoke-interface {v0}, Lcom/google/common/collect/Multimap;->asMap()Ljava/util/Map;
move-result-object v0
invoke-interface {v0}, Ljava/util/Map;->entrySet()Ljava/util/Set;
move-result-object v0
invoke-interface {v0}, Ljava/util/Set;->iterator()Ljava/util/Iterator;
move-result-object v0
:goto_0
invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z
move-result v1
if-eqz v1, :cond_1
invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;
move-result-object v1
check-cast v1, Ljava/util/Map$Entry;
.line 3
invoke-interface {v1}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;
move-result-object v2
check-cast v2, Ljava/lang/Class;
.line 4
invoke-interface {v1}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;
move-result-object v1
check-cast v1, Ljava/util/Collection;
.line 5
iget-object v3, p0, Lcom/google/common/eventbus/SubscriberRegistry;->subscribers:Ljava/util/concurrent/ConcurrentMap;
invoke-interface {v3, v2}, Ljava/util/concurrent/ConcurrentMap;->get(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v2
check-cast v2, Ljava/util/concurrent/CopyOnWriteArraySet;
if-eqz v2, :cond_0
.line 6
invoke-virtual {v2, v1}, Ljava/util/concurrent/CopyOnWriteArraySet;->removeAll(Ljava/util/Collection;)Z
move-result v1
if-eqz v1, :cond_0
goto :goto_0
.line 7
:cond_0
new-instance v0, Ljava/lang/IllegalArgumentException;
invoke-static {p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;
move-result-object p1
invoke-virtual {p1}, Ljava/lang/String;->length()I
move-result v1
add-int/lit8 v1, v1, 0x41
const-string v2, "missing event subscriber for an annotated method. Is "
const-string v3, " registered?"
invoke-static {v1, v2, p1, v3}, Lcom/google/android/gms/ads/internal/a;->a(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
move-result-object p1
invoke-direct {v0, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw v0
:cond_1
return-void
.end method