163 lines
6.6 KiB
Java
163 lines
6.6 KiB
Java
package com.squareup.leakcanary;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Collections;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class ExcludedRefs implements Serializable {
|
|
public final Map<String, Exclusion> classNames;
|
|
public final Map<String, Map<String, Exclusion>> fieldNameByClassName;
|
|
public final Map<String, Map<String, Exclusion>> staticFieldNameByClassName;
|
|
public final Map<String, Exclusion> threadNames;
|
|
|
|
public interface Builder {
|
|
ExcludedRefs build();
|
|
|
|
BuilderWithParams clazz(String str);
|
|
|
|
BuilderWithParams instanceField(String str, String str2);
|
|
|
|
BuilderWithParams staticField(String str, String str2);
|
|
|
|
BuilderWithParams thread(String str);
|
|
}
|
|
|
|
public static final class BuilderWithParams implements Builder {
|
|
private ParamsBuilder lastParams;
|
|
private final Map<String, Map<String, ParamsBuilder>> fieldNameByClassName = new LinkedHashMap();
|
|
private final Map<String, Map<String, ParamsBuilder>> staticFieldNameByClassName = new LinkedHashMap();
|
|
private final Map<String, ParamsBuilder> threadNames = new LinkedHashMap();
|
|
private final Map<String, ParamsBuilder> classNames = new LinkedHashMap();
|
|
|
|
BuilderWithParams() {
|
|
}
|
|
|
|
public BuilderWithParams alwaysExclude() {
|
|
this.lastParams.alwaysExclude = true;
|
|
return this;
|
|
}
|
|
|
|
@Override // com.squareup.leakcanary.ExcludedRefs.Builder
|
|
public ExcludedRefs build() {
|
|
return new ExcludedRefs(this);
|
|
}
|
|
|
|
@Override // com.squareup.leakcanary.ExcludedRefs.Builder
|
|
public BuilderWithParams clazz(String str) {
|
|
Preconditions.checkNotNull(str, "className");
|
|
this.lastParams = new ParamsBuilder("any subclass of " + str);
|
|
this.classNames.put(str, this.lastParams);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.squareup.leakcanary.ExcludedRefs.Builder
|
|
public BuilderWithParams instanceField(String str, String str2) {
|
|
Preconditions.checkNotNull(str, "className");
|
|
Preconditions.checkNotNull(str2, "fieldName");
|
|
Map<String, ParamsBuilder> map = this.fieldNameByClassName.get(str);
|
|
if (map == null) {
|
|
map = new LinkedHashMap<>();
|
|
this.fieldNameByClassName.put(str, map);
|
|
}
|
|
this.lastParams = new ParamsBuilder("field " + str + "#" + str2);
|
|
map.put(str2, this.lastParams);
|
|
return this;
|
|
}
|
|
|
|
public BuilderWithParams named(String str) {
|
|
this.lastParams.name = str;
|
|
return this;
|
|
}
|
|
|
|
public BuilderWithParams reason(String str) {
|
|
this.lastParams.reason = str;
|
|
return this;
|
|
}
|
|
|
|
@Override // com.squareup.leakcanary.ExcludedRefs.Builder
|
|
public BuilderWithParams staticField(String str, String str2) {
|
|
Preconditions.checkNotNull(str, "className");
|
|
Preconditions.checkNotNull(str2, "fieldName");
|
|
Map<String, ParamsBuilder> map = this.staticFieldNameByClassName.get(str);
|
|
if (map == null) {
|
|
map = new LinkedHashMap<>();
|
|
this.staticFieldNameByClassName.put(str, map);
|
|
}
|
|
this.lastParams = new ParamsBuilder("static field " + str + "#" + str2);
|
|
map.put(str2, this.lastParams);
|
|
return this;
|
|
}
|
|
|
|
@Override // com.squareup.leakcanary.ExcludedRefs.Builder
|
|
public BuilderWithParams thread(String str) {
|
|
Preconditions.checkNotNull(str, "threadName");
|
|
this.lastParams = new ParamsBuilder("any threads named " + str);
|
|
this.threadNames.put(str, this.lastParams);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
static final class ParamsBuilder {
|
|
boolean alwaysExclude;
|
|
final String matching;
|
|
String name;
|
|
String reason;
|
|
|
|
ParamsBuilder(String str) {
|
|
this.matching = str;
|
|
}
|
|
}
|
|
|
|
ExcludedRefs(BuilderWithParams builderWithParams) {
|
|
this.fieldNameByClassName = unmodifiableRefStringMap(builderWithParams.fieldNameByClassName);
|
|
this.staticFieldNameByClassName = unmodifiableRefStringMap(builderWithParams.staticFieldNameByClassName);
|
|
this.threadNames = unmodifiableRefMap(builderWithParams.threadNames);
|
|
this.classNames = unmodifiableRefMap(builderWithParams.classNames);
|
|
}
|
|
|
|
public static Builder builder() {
|
|
return new BuilderWithParams();
|
|
}
|
|
|
|
private Map<String, Exclusion> unmodifiableRefMap(Map<String, ParamsBuilder> map) {
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (Map.Entry<String, ParamsBuilder> entry : map.entrySet()) {
|
|
linkedHashMap.put(entry.getKey(), new Exclusion(entry.getValue()));
|
|
}
|
|
return Collections.unmodifiableMap(linkedHashMap);
|
|
}
|
|
|
|
private Map<String, Map<String, Exclusion>> unmodifiableRefStringMap(Map<String, Map<String, ParamsBuilder>> map) {
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (Map.Entry<String, Map<String, ParamsBuilder>> entry : map.entrySet()) {
|
|
linkedHashMap.put(entry.getKey(), unmodifiableRefMap(entry.getValue()));
|
|
}
|
|
return Collections.unmodifiableMap(linkedHashMap);
|
|
}
|
|
|
|
public String toString() {
|
|
String str = "";
|
|
for (Map.Entry<String, Map<String, Exclusion>> entry : this.fieldNameByClassName.entrySet()) {
|
|
String key = entry.getKey();
|
|
for (Map.Entry<String, Exclusion> entry2 : entry.getValue().entrySet()) {
|
|
str = str + "| Field: " + key + "." + entry2.getKey() + (entry2.getValue().alwaysExclude ? " (always)" : "") + "\n";
|
|
}
|
|
}
|
|
for (Map.Entry<String, Map<String, Exclusion>> entry3 : this.staticFieldNameByClassName.entrySet()) {
|
|
String key2 = entry3.getKey();
|
|
for (Map.Entry<String, Exclusion> entry4 : entry3.getValue().entrySet()) {
|
|
str = str + "| Static field: " + key2 + "." + entry4.getKey() + (entry4.getValue().alwaysExclude ? " (always)" : "") + "\n";
|
|
}
|
|
}
|
|
for (Map.Entry<String, Exclusion> entry5 : this.threadNames.entrySet()) {
|
|
str = str + "| Thread:" + entry5.getKey() + (entry5.getValue().alwaysExclude ? " (always)" : "") + "\n";
|
|
}
|
|
for (Map.Entry<String, Exclusion> entry6 : this.classNames.entrySet()) {
|
|
str = str + "| Class:" + entry6.getKey() + (entry6.getValue().alwaysExclude ? " (always)" : "") + "\n";
|
|
}
|
|
return str;
|
|
}
|
|
}
|