All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jbock.convert.match.ListMatcher Maven / Gradle / Ivy

There is a newer version: 5.18
Show newest version
package net.jbock.convert.match;

import net.jbock.annotated.Item;
import net.jbock.common.SafeElements;
import net.jbock.common.TypeTool;

import javax.lang.model.type.TypeMirror;
import java.util.Optional;

import static net.jbock.model.Multiplicity.REPEATABLE;

final class ListMatcher extends Matcher {

    private final SafeElements elements;
    private final TypeTool tool;

    ListMatcher(
            TypeTool tool) {
        this.elements = tool.elements();
        this.tool = tool;
    }

    @Override
    
    Optional> tryMatch(M item) {
        if (item.isParameter()) {
            return Optional.empty(); // Not a VarargsParameter, so definitely not repeatable.
        }
        TypeMirror returnType = item.returnType();
        return elements.getTypeElement("java.util.List")
                .flatMap(utilList -> tool.getSingleTypeArgument(returnType, utilList))
                .map(typeArg -> Match.create(typeArg, REPEATABLE, item));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy