use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project auto by google.
the class AutoValueProcessor method getFieldOfClasses.
/**
* Returns the contents of a {@code Class[]}-typed field in an annotation.
*
* <p>This method is needed because directly reading the value of such a field from an
* AnnotationMirror throws: <pre>
* javax.lang.model.type.MirroredTypeException: Attempt to access Class object for TypeMirror Foo.
* </pre>
*
* @param element The element on which the annotation is present. e.g. the class being processed
* by AutoValue.
* @param annotation The class of the annotation to read from., e.g. {@link
* AutoValue.CopyAnnotations}.
* @param fieldName The name of the field to read, e.g. "exclude".
* @return a set of fully-qualified names of classes appearing in 'fieldName' on 'annotation' on
* 'element'.
*/
private ImmutableSet<String> getFieldOfClasses(Element element, Class<? extends Annotation> annotation, String fieldName, Elements elementUtils) {
TypeElement annotationElement = elementUtils.getTypeElement(annotation.getCanonicalName());
if (annotationElement == null) {
// This can happen if the annotation is on the -processorpath but not on the -classpath.
return ImmutableSet.of();
}
TypeMirror annotationMirror = annotationElement.asType();
for (AnnotationMirror annot : element.getAnnotationMirrors()) {
if (!typeUtils.isSameType(annot.getAnnotationType(), annotationMirror)) {
continue;
}
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annot.getElementValues().entrySet()) {
if (fieldName.contentEquals(entry.getKey().getSimpleName())) {
ImmutableSet.Builder<String> result = ImmutableSet.builder();
@SuppressWarnings("unchecked") List<AnnotationValue> annotationsToCopy = (List<AnnotationValue>) entry.getValue().getValue();
for (AnnotationValue annotationValue : annotationsToCopy) {
String qualifiedName = ((TypeElement) ((DeclaredType) annotationValue.getValue()).asElement()).getQualifiedName().toString();
result.add(qualifiedName);
}
return result.build();
}
}
}
return ImmutableSet.of();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project auto by google.
the class AutoValueProcessor method abstractMethodsIn.
private ImmutableSet<ExecutableElement> abstractMethodsIn(ImmutableSet<ExecutableElement> methods) {
Set<Name> noArgMethods = Sets.newHashSet();
ImmutableSet.Builder<ExecutableElement> abstracts = ImmutableSet.builder();
for (ExecutableElement method : methods) {
if (method.getModifiers().contains(Modifier.ABSTRACT)) {
boolean hasArgs = !method.getParameters().isEmpty();
if (hasArgs || noArgMethods.add(method.getSimpleName())) {
// If an abstract method with the same signature is inherited on more than one path,
// we only add it once. At the moment we only do this check for no-arg methods. All
// methods that AutoValue will implement are either no-arg methods or equals(Object).
// The former is covered by this check and the latter will lead to vars.equals being
// set to true, regardless of how many times it appears. So the only case that is
// covered imperfectly here is that of a method that is inherited on more than one path
// and that will be consumed by an extension. We could check parameters as well, but that
// can be a bit tricky if any of the parameters are generic.
abstracts.add(method);
}
}
}
return abstracts.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class ProcessExecutorTest method testProcessTimeoutHandlerThrowsException.
@Test
public void testProcessTimeoutHandlerThrowsException() throws IOException, InterruptedException {
@SuppressWarnings("PMD.PrematureDeclaration") ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole(Verbosity.ALL));
String cmd = (Platform.detect() == Platform.WINDOWS) ? "ping -n 50 0.0.0.0" : "sleep 50";
ProcessExecutorParams params = ProcessExecutorParams.ofCommand(makeCommandArray(cmd));
ProcessExecutor.Result result = executor.launchAndExecute(params, /* options */
ImmutableSet.<ProcessExecutor.Option>builder().build(), /* stdin */
Optional.empty(), /* timeOutMs */
Optional.of((long) 100), /* timeOutHandler */
Optional.of(ignored -> {
throw new RuntimeException("This shouldn't fail the test!");
}));
assertTrue("process was reported as timed out", result.isTimedOut());
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project presto by prestodb.
the class AggregationCompiler method getStateClasses.
private static Set<Class<?>> getStateClasses(Class<?> clazz) {
ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder();
for (Method inputFunction : findPublicStaticMethodsWithAnnotation(clazz, InputFunction.class)) {
checkArgument(inputFunction.getParameterTypes().length > 0, "Input function has no parameters");
Class<?> stateClass = findAggregationStateParamType(inputFunction);
checkArgument(AccumulatorState.class.isAssignableFrom(stateClass), "stateClass is not a subclass of AccumulatorState");
builder.add(stateClass);
}
ImmutableSet<Class<?>> stateClasses = builder.build();
checkArgument(!stateClasses.isEmpty(), "No input functions found");
return stateClasses;
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project GeoGig by boundlessgeo.
the class HttpMappedRemoteRepo method listRefs.
/**
* List the mapped versions of the remote's {@link Ref refs}. For example, if the remote ref
* points to commit A, the returned ref will point to the commit that A is mapped to.
*
* @param getHeads whether to return refs in the {@code refs/heads} namespace
* @param getTags whether to return refs in the {@code refs/tags} namespace
* @return an immutable set of refs from the remote
*/
@Override
public ImmutableSet<Ref> listRefs(boolean getHeads, boolean getTags) {
HttpURLConnection connection = null;
ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
try {
String expanded = repositoryURL.toString() + "/repo/manifest";
connection = (HttpURLConnection) new URL(expanded).openConnection();
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.setDoOutput(true);
// Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
try {
while ((line = rd.readLine()) != null) {
if ((getHeads && line.startsWith("refs/heads")) || (getTags && line.startsWith("refs/tags"))) {
Ref remoteRef = HttpUtils.parseRef(line);
Ref newRef = remoteRef;
if (!(newRef instanceof SymRef) && localRepository.graphDatabase().exists(remoteRef.getObjectId())) {
ObjectId mappedCommit = localRepository.graphDatabase().getMapping(remoteRef.getObjectId());
if (mappedCommit != null) {
newRef = new Ref(remoteRef.getName(), mappedCommit);
}
}
builder.add(newRef);
}
}
} finally {
rd.close();
}
} catch (Exception e) {
throw Throwables.propagate(e);
} finally {
HttpUtils.consumeErrStreamAndCloseConnection(connection);
}
return builder.build();
}
Aggregations