aboutsummaryrefslogtreecommitdiff
path: root/factory/src/test
diff options
context:
space:
mode:
authorronshapiro <ronshapiro@google.com>2018-01-25 09:42:20 -0800
committerRon Shapiro <shapiro.rd@gmail.com>2018-01-25 19:42:02 -0500
commit4d6df145e34a6db1e9ac23aac3e974e13e8cb4e2 (patch)
tree0386de4eec46c3971930a4f78bcd02ec2f3d58bf /factory/src/test
parentd61a9697dc27acb42c4a6c4452218ab5bf7d2a70 (diff)
downloadauto-4d6df145e34a6db1e9ac23aac3e974e13e8cb4e2.tar.gz
Add support for type-annotations and CheckerFramework nullable types to @AutoFactory
RELNOTES=Add support for type-annotations and CheckerFramework nullable types to @AutoFactory ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183251433
Diffstat (limited to 'factory/src/test')
-rw-r--r--factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java9
-rw-r--r--factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java58
-rw-r--r--factory/src/test/resources/good/CheckerFrameworkNullable.java31
3 files changed, 98 insertions, 0 deletions
diff --git a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
index 9e59c372..b3d977eb 100644
--- a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
+++ b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
@@ -378,6 +378,15 @@ public class AutoFactoryProcessorTest {
.generatesSources(loadExpectedFile("expected/CustomNullableFactory.java"));
}
+ @Test public void checkerFrameworkNullableType() {
+ assertAbout(javaSource())
+ .that(JavaFileObjects.forResource("good/CheckerFrameworkNullable.java"))
+ .processedWith(new AutoFactoryProcessor())
+ .compilesWithoutError()
+ .and()
+ .generatesSources(loadExpectedFile("expected/CheckerFrameworkNullableFactory.java"));
+ }
+
@Test public void multipleProvidedParamsWithSameKey() {
assertAbout(javaSource())
.that(JavaFileObjects.forResource("good/MultipleProvidedParamsSameKey.java"))
diff --git a/factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java b/factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java
new file mode 100644
index 00000000..bc18d84e
--- /dev/null
+++ b/factory/src/test/resources/expected/CheckerFrameworkNullableFactory.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2016 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests;
+
+import javax.annotation.processing.Generated;
+import javax.inject.Inject;
+import javax.inject.Provider;
+import org.checkerframework.checker.nullness.compatqual.NullableDecl;
+import org.checkerframework.checker.nullness.compatqual.NullableType;
+
+@Generated(
+ value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+ comments = "https://github.com/google/auto/tree/master/factory"
+)
+final class CheckerFrameworkNullableFactory {
+
+ private final Provider<String> providedNullableDeclProvider;
+ private final Provider<String> providedNullableTypeProvider;
+
+ @Inject
+ CheckerFrameworkNullableFactory(
+ Provider<String> providedNullableDeclProvider,
+ Provider<String> providedNullableTypeProvider) {
+ this.providedNullableDeclProvider = checkNotNull(providedNullableDeclProvider, 1);
+ this.providedNullableTypeProvider = checkNotNull(providedNullableTypeProvider, 2);
+ }
+
+ CheckerFrameworkNullable create(
+ @NullableDecl String nullableDecl, @NullableType String nullableType) {
+ return new CheckerFrameworkNullable(
+ nullableDecl,
+ providedNullableDeclProvider.get(),
+ nullableType,
+ providedNullableTypeProvider.get());
+ }
+
+ private static <T> T checkNotNull(T reference, int argumentIndex) {
+ if (reference == null) {
+ throw new NullPointerException(
+ "@AutoFactory method argument is null but is not marked @Nullable. Argument index: "
+ + argumentIndex);
+ }
+ return reference;
+ }
+}
diff --git a/factory/src/test/resources/good/CheckerFrameworkNullable.java b/factory/src/test/resources/good/CheckerFrameworkNullable.java
new file mode 100644
index 00000000..abd91d1a
--- /dev/null
+++ b/factory/src/test/resources/good/CheckerFrameworkNullable.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests;
+
+import com.google.auto.factory.AutoFactory;
+import com.google.auto.factory.Provided;
+import org.checkerframework.checker.nullness.compatqual.NullableDecl;
+import org.checkerframework.checker.nullness.compatqual.NullableType;
+
+@AutoFactory
+final class CheckerFrameworkNullable {
+
+ CheckerFrameworkNullable(
+ @NullableDecl String nullableDecl,
+ @Provided @NullableDecl String providedNullableDecl,
+ @NullableType String nullableType,
+ @Provided @NullableType String providedNullableType) {}
+}