package com.ifpdos.udi.sdk.kotlin.comment.parser;

import java.io.File;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.Metadata;
import kotlin.collections.MapsKt;
import kotlin.jvm.internal.Intrinsics;

/* JADX INFO: compiled from: CommentParser.kt */
/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0002\u0018\u0002\n\u0002\b\u0002\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u000e\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u0006J(\u0010\u0007\u001a\u000e\u0012\u0004\u0012\u00020\t\u0012\u0004\u0012\u00020\n0\b2\u0012\u0010\u000b\u001a\u000e\u0012\u0004\u0012\u00020\t\u0012\u0004\u0012\u00020\t0\bH\u0002¨\u0006\f"}, d2 = {"Lcom/ifpdos/udi/sdk/kotlin/comment/parser/CommentParser;", "", "()V", "parser", "Lcom/ifpdos/udi/sdk/kotlin/comment/parser/Comment;", "source", "Ljava/io/File;", "parserElementComments", "", "", "Lcom/ifpdos/udi/sdk/kotlin/comment/parser/CommentDetails;", "comments", "kotlin-comment-parser"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class CommentParser {
    public static final CommentParser INSTANCE = new CommentParser();

    private CommentParser() {
    }

    public final Comment parser(File source) throws Exception {
        Intrinsics.checkNotNullParameter(source, "source");
        List<Token> listAnalyse = new LexicalAnalyzer().analyse(source);
        SyntacticAnalyzer syntacticAnalyzer = new SyntacticAnalyzer();
        syntacticAnalyzer.analyse(listAnalyse);
        String documentComment = syntacticAnalyzer.getDocumentComment();
        if (documentComment == null) {
            throw new Exception("need @name comment for ProtocolDefine.kt to define service name");
        }
        return new Comment(CommentDetails.INSTANCE.parseComment(documentComment), INSTANCE.parserElementComments(syntacticAnalyzer.getElementComments()));
    }

    private final Map<String, CommentDetails> parserElementComments(Map<String, String> comments) {
        LinkedHashMap linkedHashMap = new LinkedHashMap(MapsKt.mapCapacity(comments.size()));
        Iterator<T> it = comments.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            linkedHashMap.put(entry.getKey(), CommentDetails.INSTANCE.parseComment((String) entry.getValue()));
        }
        return linkedHashMap;
    }
}
