Search in sources :

Example 71 with ImmutableSet

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();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ImmutableSet(com.google.common.collect.ImmutableSet) TypeMirror(javax.lang.model.type.TypeMirror) AnnotationValue(javax.lang.model.element.AnnotationValue) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) DeclaredType(javax.lang.model.type.DeclaredType)

Example 72 with ImmutableSet

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ExecutableElement(javax.lang.model.element.ExecutableElement) Name(javax.lang.model.element.Name)

Example 73 with ImmutableSet

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());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) TestConsole(com.facebook.buck.testutil.TestConsole) Assert.assertFalse(org.junit.Assert.assertFalse) StringTokenizer(java.util.StringTokenizer) Platform(com.facebook.buck.util.environment.Platform) Assert.assertTrue(org.junit.Assert.assertTrue) Optional(java.util.Optional) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertEquals(org.junit.Assert.assertEquals) EnumSet(java.util.EnumSet) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 74 with ImmutableSet

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;
}
Also used : AccumulatorState(com.facebook.presto.spi.function.AccumulatorState) ImmutableSet(com.google.common.collect.ImmutableSet) Method(java.lang.reflect.Method)

Example 75 with ImmutableSet

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) ObjectId(org.locationtech.geogig.api.ObjectId) InputStream(java.io.InputStream) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) SymRef(org.locationtech.geogig.api.SymRef) HttpURLConnection(java.net.HttpURLConnection) ImmutableSet(com.google.common.collect.ImmutableSet) BufferedReader(java.io.BufferedReader)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)348 Set (java.util.Set)86 ImmutableList (com.google.common.collect.ImmutableList)73 Path (java.nio.file.Path)71 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)67 Optional (java.util.Optional)65 Map (java.util.Map)63 List (java.util.List)60 BuildTarget (com.facebook.buck.model.BuildTarget)58 Test (org.junit.Test)55 HashMap (java.util.HashMap)42 Collection (java.util.Collection)34 HashSet (java.util.HashSet)33 SourcePath (com.facebook.buck.rules.SourcePath)31 ArrayList (java.util.ArrayList)31 TargetNode (com.facebook.buck.rules.TargetNode)28 BuildRule (com.facebook.buck.rules.BuildRule)26 VisibleForTesting (com.google.common.annotations.VisibleForTesting)25 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)25