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 g.h0.c.l;
import g.i;
import g.m0.f;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.lang.model.util.Elements;

/* JADX INFO: compiled from: CommentProvider.kt */
/* JADX INFO: loaded from: classes.dex */
@i
public final class CommentProvider implements ICommentProvider {
    private Map<String, CommentDetails> comments;
    private final Elements elementUtils;

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

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

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

    @Override // com.ifpdos.udi.sdk.service.doc.base.ICommentProvider
    public CommentDetails getComment(IClassWrapper iClassWrapper, IFieldWrapper iFieldWrapper) {
        String strSubstring;
        Map<String, List<String>> annotations;
        l.f(iClassWrapper, "clazz");
        l.f(iFieldWrapper, "field");
        if (iClassWrapper.isEnum()) {
            String docComment = this.elementUtils.getDocComment(iClassWrapper.getElement());
            CommentDetails comment = docComment != null ? CommentDetails.Companion.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 listE = f.E((String) it.next(), new String[]{" "}, false, 0, 6);
                    if (l.a(listE.get(0), iFieldWrapper.getName())) {
                        return CommentDetails.Companion.parseComment((String) listE.get(1));
                    }
                }
            }
        }
        String docComment2 = this.elementUtils.getDocComment(iFieldWrapper.getElement());
        if (docComment2 != null) {
            return CommentDetails.Companion.parseComment(docComment2);
        }
        String type = iClassWrapper.getType();
        if (f.b(type, "<", false, 2)) {
            String strSubstring2 = type.substring(0, f.m(type, "<", 0, false, 6));
            l.e(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
            strSubstring = strSubstring2.substring(0, f.q(strSubstring2, ".", 0, false, 6));
            l.e(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
        } else {
            strSubstring = "";
        }
        Map<String, CommentDetails> map = this.comments;
        if (map == null) {
            l.m("comments");
            throw null;
        }
        CommentDetails commentDetails = map.get(iClassWrapper.getType() + '.' + iFieldWrapper.getRawName());
        if (commentDetails != null) {
            return commentDetails;
        }
        Map<String, CommentDetails> map2 = this.comments;
        if (map2 == null) {
            l.m("comments");
            throw null;
        }
        return map2.get(strSubstring + '.' + iFieldWrapper.getRawName());
    }
}
