Search in sources :

Example 1 with ParserInfo

use of com.twitter.common.args.apt.Configuration.ParserInfo in project commons by twitter.

the class CmdLineProcessor method getParsedTypes.

@Nullable
private Set<String> getParsedTypes(Set<? extends Element> parsers) {
    if (!isCheckLinkage) {
        return null;
    }
    Iterable<String> parsersFor = Optional.presentInstances(Iterables.transform(parsers, new Function<Element, Optional<String>>() {

        @Override
        public Optional<String> apply(Element parser) {
            TypeMirror parsedType = getTypeArgument(parser.asType(), typeElement(Parser.class));
            if (parsedType == null) {
                error("failed to find a type argument for Parser: %s", parser);
                return Optional.absent();
            }
            // Equals on TypeMirrors doesn't work - so we compare string representations :/
            return Optional.of(typeUtils.erasure(parsedType).toString());
        }
    }));
    parsersFor = Iterables.concat(parsersFor, Iterables.filter(Iterables.transform(this.persistedConfig.get().parserInfo(), new Function<ParserInfo, String>() {

        @Override
        @Nullable
        public String apply(ParserInfo parserInfo) {
            TypeElement typeElement = elementUtils.getTypeElement(parserInfo.parsedType);
            // long as the no Args in this round that are of the type.
            return (typeElement == null) ? null : typeUtils.erasure(typeElement.asType()).toString();
        }
    }), Predicates.notNull()));
    return ImmutableSet.copyOf(parsersFor);
}
Also used : Function(com.google.common.base.Function) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) ParserInfo(com.twitter.common.args.apt.Configuration.ParserInfo) ArgParser(com.twitter.common.args.ArgParser) Parser(com.twitter.common.args.Parser) Nullable(javax.annotation.Nullable)

Aggregations

Function (com.google.common.base.Function)1 ArgParser (com.twitter.common.args.ArgParser)1 Parser (com.twitter.common.args.Parser)1 ParserInfo (com.twitter.common.args.apt.Configuration.ParserInfo)1 Nullable (javax.annotation.Nullable)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1