use of com.twitter.common.args.Parser in project commons by twitter.
the class CmdLineProcessor method processParsers.
private void processParsers(Set<? extends Element> elements) {
TypeElement parserType = typeElement(Parser.class);
for (Element element : elements) {
if (element.getKind() != ElementKind.CLASS) {
error("Found an @ArgParser annotation on a non-class %s", element);
} else {
TypeElement parser = (TypeElement) element;
if (!isAssignable(parser, Parser.class)) {
error("Found an @ArgParser annotation on a non-Parser %s", element);
return;
}
@Nullable String parsedType = getTypeArgument(parser, parserType);
if (parsedType != null) {
String parserClassName = getBinaryName(parser);
getBuilder(parserClassName).addParser(parsedType, getBinaryName(parser));
}
}
}
}
use of com.twitter.common.args.Parser 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);
}
Aggregations