use of org.apache.flink.shaded.guava30.com.google.common.collect.Iterables.getOnlyElement in project error-prone by google.
the class FormatStringValidation method validate.
@Nullable
public static ValidationResult validate(Collection<? extends ExpressionTree> arguments, final VisitorState state) {
Deque<ExpressionTree> args = new ArrayDeque<>(arguments);
Stream<String> formatStrings = constValues(args.removeFirst());
if (formatStrings == null) {
return null;
}
// Bail out, since we don't know what the actual argument types are.
if (args.size() == 1) {
Type type = ASTHelpers.getType(Iterables.getOnlyElement(args));
if (type instanceof Type.ArrayType && ASTHelpers.isSameType(((Type.ArrayType) type).elemtype, state.getSymtab().objectType, state)) {
return null;
}
}
Iterable<Object> instances = Iterables.transform(args, new Function<ExpressionTree, Object>() {
@Override
public Object apply(ExpressionTree input) {
try {
return getInstance(input, state);
} catch (Throwable t) {
// ignore symbol completion failures
return null;
}
}
});
return formatStrings.map(formatString -> validate(formatString, instances)).filter(x -> x != null).findFirst().orElse(null);
}
use of org.apache.flink.shaded.guava30.com.google.common.collect.Iterables.getOnlyElement in project auto by google.
the class MoreTypesIsTypeOfTest method extractReturnTypeFromHolder.
// Utility methods for this test.
private TypeMirror extractReturnTypeFromHolder(TypeElement typeElement) {
Element element = Iterables.getOnlyElement(typeElement.getEnclosedElements());
TypeMirror arrayType = MoreElements.asExecutable(element).getReturnType();
return arrayType;
}
Aggregations