package com.ifpdos.udi.sdk.service.compile;

import com.ifpdos.udi.sdk.kotlin.comment.parser.CommentDetails;
import com.ifpdos.udi.sdk.service.doc.base.IClassWrapper;
import com.ifpdos.udi.sdk.service.doc.base.ICommentProvider;
import com.ifpdos.udi.sdk.service.doc.base.IFieldWrapper;
import com.ifpdos.udi.sdk.service.doc.base.Utils;
import io.netty.handler.codec.dns.DefaultDnsRecordDecoder;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.lang.model.util.Elements;
import kotlin.Metadata;
import kotlin.jvm.internal.o;
import kotlin.text.j;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0012\u0010\t\u001a\u0004\u0018\u00010\b2\u0006\u0010\n\u001a\u00020\u000bH\u0016J\u001a\u0010\t\u001a\u0004\u0018\u00010\b2\u0006\u0010\n\u001a\u00020\u000b2\u0006\u0010\f\u001a\u00020\rH\u0016J\u001a\u0010\u000e\u001a\u00020\u000f2\u0012\u0010\u0005\u001a\u000e\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\b0\u0006R\u001a\u0010\u0005\u001a\u000e\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\b0\u0006X\u0082.¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0010"}, d2 = {"Lcom/ifpdos/udi/sdk/service/compile/CommentProvider;", "Lcom/ifpdos/udi/sdk/service/doc/base/ICommentProvider;", "elementUtils", "Ljavax/lang/model/util/Elements;", "(Ljavax/lang/model/util/Elements;)V", "comments", "", "", "Lcom/ifpdos/udi/sdk/kotlin/comment/parser/CommentDetails;", "getComment", "clazz", "Lcom/ifpdos/udi/sdk/service/doc/base/IClassWrapper;", "field", "Lcom/ifpdos/udi/sdk/service/doc/base/IFieldWrapper;", "init", "", "compile"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class CommentProvider implements ICommentProvider {
    private Map<String, CommentDetails> comments;
    private final Elements elementUtils;

    public CommentProvider(Elements elements) {
        o.f(elements, "elementUtils");
        this.elementUtils = elements;
    }

    @Override // com.ifpdos.udi.sdk.service.doc.base.ICommentProvider
    public CommentDetails getComment(IClassWrapper clazz) {
        o.f(clazz, "clazz");
        String docComment = this.elementUtils.getDocComment(clazz.getElement());
        if (docComment != null) {
            return CommentDetails.INSTANCE.parseComment(docComment);
        }
        Map<String, CommentDetails> map = this.comments;
        if (map != null) {
            return map.get(Utils.INSTANCE.getGenericClassName(clazz.getFullName()));
        }
        o.n("comments");
        throw null;
    }

    @Override // com.ifpdos.udi.sdk.service.doc.base.ICommentProvider
    public CommentDetails getComment(IClassWrapper clazz, IFieldWrapper field) {
        String strSubstring;
        Map<String, List<String>> annotations;
        o.f(clazz, "clazz");
        o.f(field, "field");
        if (clazz.isEnum()) {
            String docComment = this.elementUtils.getDocComment(clazz.getElement());
            CommentDetails comment = docComment != null ? CommentDetails.INSTANCE.parseComment(docComment) : null;
            List<String> list = (comment == null || (annotations = comment.getAnnotations()) == null) ? null : annotations.get("@enum");
            if (list != null) {
                Iterator<T> it = list.iterator();
                while (it.hasNext()) {
                    List listG = j.G((String) it.next(), new String[]{" "}, false, 0, 6);
                    if (o.a(listG.get(0), field.getName())) {
                        return CommentDetails.INSTANCE.parseComment((String) listG.get(1));
                    }
                }
            }
        }
        String docComment2 = this.elementUtils.getDocComment(field.getElement());
        if (docComment2 != null) {
            return CommentDetails.INSTANCE.parseComment(docComment2);
        }
        String fullName = clazz.getFullName();
        if (j.d(fullName, "<", false, 2)) {
            String strSubstring2 = fullName.substring(0, j.n(fullName, "<", 0, false, 6));
            o.e(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
            strSubstring = strSubstring2.substring(0, j.r(strSubstring2, DefaultDnsRecordDecoder.ROOT, 0, false, 6));
            o.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        } else {
            strSubstring = "";
        }
        Map<String, CommentDetails> map = this.comments;
        if (map == null) {
            o.n("comments");
            throw null;
        }
        CommentDetails commentDetails = map.get(clazz.getFullName() + '.' + field.getRawName());
        if (commentDetails != null) {
            return commentDetails;
        }
        Map<String, CommentDetails> map2 = this.comments;
        if (map2 == null) {
            o.n("comments");
            throw null;
        }
        return map2.get(strSubstring + '.' + field.getRawName());
    }

    public final void init(Map<String, CommentDetails> comments) {
        o.f(comments, "comments");
        this.comments = comments;
    }
}
