alexandroid/decompiled/jadx/sources/com/squareup/javapoet/ClassName.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

247 lines
9.1 KiB
Java

package com.squareup.javapoet;
import com.amazon.deecomms.remoteConfig.ArcusConfig;
import defpackage.a$$ExternalSyntheticOutline0;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.lang.model.element.Element;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.SimpleElementVisitor8;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes9.dex */
public final class ClassName extends TypeName implements Comparable<ClassName> {
private static final String NO_PACKAGE = "";
public static final ClassName OBJECT = get((Class<?>) Object.class);
final String canonicalName;
final ClassName enclosingClassName;
final String packageName;
final String simpleName;
private List<String> simpleNames;
private ClassName(String str, ClassName className, String str2, List<AnnotationSpec> list) {
super(list);
Objects.requireNonNull(str, "packageName == null");
this.packageName = str;
this.enclosingClassName = className;
this.simpleName = str2;
if (className != null) {
str2 = a$$ExternalSyntheticOutline0.m(new StringBuilder(), className.canonicalName, '.', str2);
} else if (!str.isEmpty()) {
str2 = a$$ExternalSyntheticOutline0.m('.', str, str2);
}
this.canonicalName = str2;
}
public static ClassName bestGuess(String str) {
int i = 0;
while (true) {
boolean z = true;
if (i >= str.length() || !Character.isLowerCase(str.codePointAt(i))) {
break;
}
i = str.indexOf(46, i) + 1;
if (i == 0) {
z = false;
}
Util.checkArgument(z, "couldn't make a guess for %s", str);
}
String substring = i == 0 ? "" : str.substring(0, i - 1);
String[] split = str.substring(i).split(ArcusConfig.PATH_SEPARATOR, -1);
int length = split.length;
ClassName className = null;
int i2 = 0;
while (i2 < length) {
String str2 = split[i2];
Util.checkArgument(!str2.isEmpty() && Character.isUpperCase(str2.codePointAt(0)), "couldn't make a guess for %s", str);
i2++;
className = new ClassName(substring, className, str2);
}
return className;
}
private List<ClassName> enclosingClasses() {
ArrayList arrayList = new ArrayList();
while (this != null) {
arrayList.add(this);
this = this.enclosingClassName;
}
Collections.reverse(arrayList);
return arrayList;
}
public static ClassName get(Class<?> cls) {
Util.checkNotNull(cls, "clazz == null", new Object[0]);
Util.checkArgument(!cls.isPrimitive(), "primitive types cannot be represented as a ClassName", new Object[0]);
Util.checkArgument(!Void.TYPE.equals(cls), "'void' type cannot be represented as a ClassName", new Object[0]);
Util.checkArgument(!cls.isArray(), "array types cannot be represented as a ClassName", new Object[0]);
String str = "";
while (cls.isAnonymousClass()) {
str = cls.getName().substring(cls.getName().lastIndexOf(36)).concat(str);
cls = cls.getEnclosingClass();
}
String concat = cls.getSimpleName().concat(str);
if (cls.getEnclosingClass() != null) {
return get(cls.getEnclosingClass()).nestedClass(concat);
}
int lastIndexOf = cls.getName().lastIndexOf(46);
return new ClassName(lastIndexOf != -1 ? cls.getName().substring(0, lastIndexOf) : "", null, concat);
}
@Override // com.squareup.javapoet.TypeName
public ClassName annotated(List<AnnotationSpec> list) {
return new ClassName(this.packageName, this.enclosingClassName, this.simpleName, concatAnnotations(list));
}
public String canonicalName() {
return this.canonicalName;
}
@Override // java.lang.Comparable
public int compareTo(ClassName className) {
return this.canonicalName.compareTo(className.canonicalName);
}
@Override // com.squareup.javapoet.TypeName
public CodeWriter emit(CodeWriter codeWriter) throws IOException {
String str;
boolean z = false;
for (ClassName className : enclosingClasses()) {
if (z) {
codeWriter.emit(".");
str = className.simpleName;
} else if (className.isAnnotated() || className == this) {
str = codeWriter.lookupName(className);
int lastIndexOf = str.lastIndexOf(46);
if (lastIndexOf != -1) {
int i = lastIndexOf + 1;
codeWriter.emitAndIndent(str.substring(0, i));
str = str.substring(i);
z = true;
}
}
if (className.isAnnotated()) {
if (z) {
codeWriter.emit(" ");
}
className.emitAnnotations(codeWriter);
}
codeWriter.emit(str);
z = true;
}
return codeWriter;
}
public ClassName enclosingClassName() {
return this.enclosingClassName;
}
@Override // com.squareup.javapoet.TypeName
public boolean isAnnotated() {
if (super.isAnnotated()) {
return true;
}
ClassName className = this.enclosingClassName;
return className != null && className.isAnnotated();
}
public ClassName nestedClass(String str) {
return new ClassName(this.packageName, this, str);
}
public String packageName() {
return this.packageName;
}
public ClassName peerClass(String str) {
return new ClassName(this.packageName, this.enclosingClassName, str);
}
public String reflectionName() {
if (this.enclosingClassName != null) {
return this.enclosingClassName.reflectionName() + '$' + this.simpleName;
}
if (this.packageName.isEmpty()) {
return this.simpleName;
}
return this.packageName + '.' + this.simpleName;
}
public String simpleName() {
return this.simpleName;
}
public List<String> simpleNames() {
List<String> list = this.simpleNames;
if (list != null) {
return list;
}
if (this.enclosingClassName == null) {
this.simpleNames = Collections.singletonList(this.simpleName);
} else {
ArrayList arrayList = new ArrayList();
arrayList.addAll(enclosingClassName().simpleNames());
arrayList.add(this.simpleName);
this.simpleNames = Collections.unmodifiableList(arrayList);
}
return this.simpleNames;
}
public ClassName topLevelClassName() {
ClassName className = this.enclosingClassName;
return className != null ? className.topLevelClassName() : this;
}
@Override // com.squareup.javapoet.TypeName
public ClassName withoutAnnotations() {
if (!isAnnotated()) {
return this;
}
ClassName className = this.enclosingClassName;
return new ClassName(this.packageName, className != null ? className.withoutAnnotations() : null, this.simpleName);
}
@Override // com.squareup.javapoet.TypeName
public /* bridge */ /* synthetic */ TypeName annotated(List list) {
return annotated((List<AnnotationSpec>) list);
}
private ClassName(String str, ClassName className, String str2) {
this(str, className, str2, (List<AnnotationSpec>) Collections.EMPTY_LIST);
}
public static ClassName get(String str, String str2, String... strArr) {
ClassName className = new ClassName(str, null, str2);
for (String str3 : strArr) {
className = className.nestedClass(str3);
}
return className;
}
public static ClassName get(final TypeElement typeElement) {
Util.checkNotNull(typeElement, "element == null", new Object[0]);
final String obj = typeElement.getSimpleName().toString();
return (ClassName) typeElement.getEnclosingElement().accept(new SimpleElementVisitor8<ClassName, Void>() { // from class: com.squareup.javapoet.ClassName.1
public ClassName defaultAction(Element element, Void r3) {
throw new IllegalArgumentException("Unexpected type nesting: " + typeElement);
}
/* JADX WARN: Multi-variable type inference failed */
public ClassName visitPackage(PackageElement packageElement, Void r3) {
return new ClassName(packageElement.getQualifiedName().toString(), (ClassName) null, obj);
}
public ClassName visitType(TypeElement typeElement2, Void r2) {
return ClassName.get(typeElement2).nestedClass(obj);
}
public ClassName visitUnknown(Element element, Void r2) {
return ClassName.get("", obj, new String[0]);
}
}, (Object) null);
}
}