Search in sources :

Example 31 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class ScalarFnReflectorTest method testGetApplyMethod.

@Test
// If result is null, test will fail as expected.
@SuppressWarnings("nullness")
public void testGetApplyMethod() throws InvocationTargetException, IllegalAccessException {
    IncrementFn incrementFn = new IncrementFn();
    Method method = ScalarFnReflector.getApplyMethod(incrementFn);
    @Nullable Object result = method.invoke(incrementFn, Long.valueOf(24L));
    assertEquals(Long.valueOf(25L), result);
}
Also used : Method(java.lang.reflect.Method) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Test(org.junit.Test)

Example 32 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class ScalarFnReflectorTest method testGetApplyMethodOverride.

@Test
// If result is null, test will fail as expected.
@SuppressWarnings("nullness")
public void testGetApplyMethodOverride() throws InvocationTargetException, IllegalAccessException {
    IncrementFnChild incrementFn = new IncrementFnChild();
    Method method = ScalarFnReflector.getApplyMethod(incrementFn);
    @Nullable Object result = method.invoke(incrementFn, Long.valueOf(24L));
    assertEquals(Long.valueOf(26L), result);
}
Also used : Method(java.lang.reflect.Method) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Test(org.junit.Test)

Example 33 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class ScalarFnReflectorTest method testGetApplyMethodStatic.

@Test
// If result is null, test will fail as expected.
@SuppressWarnings("nullness")
public void testGetApplyMethodStatic() throws InvocationTargetException, IllegalAccessException {
    Method method = ScalarFnReflector.getApplyMethod(new IncrementFnWithStaticMethod());
    @Nullable Object result = method.invoke(null, Long.valueOf(24L));
    assertEquals(Long.valueOf(25L), result);
}
Also used : Method(java.lang.reflect.Method) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Test(org.junit.Test)

Example 34 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class PubsubGrpcClient method pull.

@Override
public List<IncomingMessage> pull(long requestTimeMsSinceEpoch, SubscriptionPath subscription, int batchSize, boolean returnImmediately) throws IOException {
    PullRequest request = PullRequest.newBuilder().setSubscription(subscription.getPath()).setReturnImmediately(returnImmediately).setMaxMessages(batchSize).build();
    PullResponse response = subscriberStub().pull(request);
    if (response.getReceivedMessagesCount() == 0) {
        return ImmutableList.of();
    }
    List<IncomingMessage> incomingMessages = new ArrayList<>(response.getReceivedMessagesCount());
    for (ReceivedMessage message : response.getReceivedMessagesList()) {
        PubsubMessage pubsubMessage = message.getMessage();
        @Nullable Map<String, String> attributes = pubsubMessage.getAttributes();
        // Timestamp.
        long timestampMsSinceEpoch;
        if (Strings.isNullOrEmpty(timestampAttribute)) {
            Timestamp timestampProto = pubsubMessage.getPublishTime();
            checkArgument(timestampProto != null, "Pubsub message is missing timestamp proto");
            timestampMsSinceEpoch = timestampProto.getSeconds() * 1000 + timestampProto.getNanos() / 1000L / 1000L;
        } else {
            timestampMsSinceEpoch = extractTimestampAttribute(timestampAttribute, attributes);
        }
        // Ack id.
        String ackId = message.getAckId();
        checkState(!Strings.isNullOrEmpty(ackId));
        // Record id, if any.
        @Nullable String recordId = null;
        if (idAttribute != null && attributes != null) {
            recordId = attributes.get(idAttribute);
        }
        if (Strings.isNullOrEmpty(recordId)) {
            // Fall back to the Pubsub provided message id.
            recordId = pubsubMessage.getMessageId();
        }
        incomingMessages.add(IncomingMessage.of(pubsubMessage, timestampMsSinceEpoch, requestTimeMsSinceEpoch, ackId, recordId));
    }
    return incomingMessages;
}
Also used : PullResponse(com.google.pubsub.v1.PullResponse) PullRequest(com.google.pubsub.v1.PullRequest) ArrayList(java.util.ArrayList) ReceivedMessage(com.google.pubsub.v1.ReceivedMessage) Timestamp(com.google.protobuf.Timestamp) PubsubMessage(com.google.pubsub.v1.PubsubMessage) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 35 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project beam by apache.

the class FieldValueTypeInformation method getNameOverride.

public static <T extends AnnotatedElement & Member> String getNameOverride(String original, T member) {
    @Nullable SchemaFieldName fieldName = member.getAnnotation(SchemaFieldName.class);
    @Nullable SchemaCaseFormat caseFormatAnnotation = member.getAnnotation(SchemaCaseFormat.class);
    @Nullable SchemaCaseFormat classCaseFormatAnnotation = member.getDeclaringClass().getAnnotation(SchemaCaseFormat.class);
    if (fieldName != null) {
        if (caseFormatAnnotation != null) {
            throw new RuntimeException(String.format("Cannot define both @SchemaFieldName and @SchemaCaseFormat. From member '%s'.", member.getName()));
        }
        return fieldName.value();
    } else if (caseFormatAnnotation != null) {
        return CaseFormat.LOWER_CAMEL.to(caseFormatAnnotation.value(), original);
    } else if (classCaseFormatAnnotation != null) {
        return CaseFormat.LOWER_CAMEL.to(classCaseFormatAnnotation.value(), original);
    } else {
        return original;
    }
}
Also used : SchemaFieldName(org.apache.beam.sdk.schemas.annotations.SchemaFieldName) SchemaCaseFormat(org.apache.beam.sdk.schemas.annotations.SchemaCaseFormat) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

Nullable (org.checkerframework.checker.nullness.qual.Nullable)289 ArrayList (java.util.ArrayList)30 TypeElement (javax.lang.model.element.TypeElement)23 Map (java.util.Map)22 IOException (java.io.IOException)21 List (java.util.List)19 ExecutableElement (javax.lang.model.element.ExecutableElement)19 ServerLevel (net.minecraft.server.level.ServerLevel)19 Instant (org.joda.time.Instant)16 HashMap (java.util.HashMap)15 VariableElement (javax.lang.model.element.VariableElement)15 Optional (java.util.Optional)14 Element (javax.lang.model.element.Element)13 TreePath (com.sun.source.util.TreePath)12 BlockPos (net.minecraft.core.BlockPos)12 Method (java.lang.reflect.Method)11 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)10 VariableTree (com.sun.source.tree.VariableTree)8 ClassTree (com.sun.source.tree.ClassTree)7