aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2022-03-04 20:20:55 -0800
committerColin Cross <ccross@android.com>2022-03-04 20:20:55 -0800
commit85e5c17a9a61aed9f989ebf0c17507cec66e4c39 (patch)
tree6d8fcf60826daaf24143400633fe8d5dfee49033 /service
parentbb49451a269af9506039d0d22b5fb26f2aae298d (diff)
parent04ebf9cf9acd8b92a6460bebccc8d4cfb30b938e (diff)
downloadauto-85e5c17a9a61aed9f989ebf0c17507cec66e4c39.tar.gz
Merge commit 'auto-value-1.8.2^'
Bug: 219098645 Test: m checkbuild Change-Id: I64e22d75b4f077b3e4cdfb13b42239d95ae9e86c
Diffstat (limited to 'service')
-rw-r--r--service/pom.xml14
-rw-r--r--service/processor/pom.xml2
-rw-r--r--service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java128
-rw-r--r--service/processor/src/main/java/com/google/auto/service/processor/ServicesFiles.java4
-rw-r--r--service/processor/src/main/java/com/google/auto/service/processor/package-info.java2
-rw-r--r--service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java138
-rw-r--r--service/processor/src/test/resources/META-INF/services/test.AnotherServiceMulti1
-rw-r--r--service/processor/src/test/resources/META-INF/services/test.SomeServiceMulti1
-rw-r--r--service/processor/src/test/resources/test/AnotherService.java2
-rw-r--r--service/processor/src/test/resources/test/AnotherServiceProvider.java2
-rw-r--r--service/processor/src/test/resources/test/Enclosing.java4
-rw-r--r--service/processor/src/test/resources/test/EnclosingGeneric.java31
-rw-r--r--service/processor/src/test/resources/test/GenericService.java22
-rw-r--r--service/processor/src/test/resources/test/GenericServiceProvider.java25
-rw-r--r--service/processor/src/test/resources/test/GenericServiceProviderSuppressWarnings.java26
-rw-r--r--service/processor/src/test/resources/test/SomeService.java2
-rw-r--r--service/processor/src/test/resources/test/SomeServiceProvider1.java2
-rw-r--r--service/processor/src/test/resources/test/SomeServiceProvider2.java2
18 files changed, 313 insertions, 95 deletions
diff --git a/service/pom.xml b/service/pom.xml
index a64ca050..e29bdc37 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -37,8 +37,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
- <guava.version>27.0.1-jre</guava.version>
- <truth.version>1.0.1</truth.version>
+ <guava.version>30.1.1-jre</guava.version>
+ <truth.version>1.1.3</truth.version>
</properties>
<scm>
@@ -90,7 +90,7 @@
<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
- <version>0.18</version>
+ <version>0.19</version>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
@@ -100,7 +100,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.12</version>
+ <version>4.13.2</version>
</dependency>
</dependencies>
</dependencyManagement>
@@ -111,7 +111,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.7.0</version>
+ <version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -123,14 +123,14 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-java</artifactId>
- <version>0.9.4</version>
+ <version>1.0.7</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <version>3.0.2</version>
+ <version>3.2.0</version>
</plugin>
</plugins>
</pluginManagement>
diff --git a/service/processor/pom.xml b/service/processor/pom.xml
index 22fc20e9..262493a9 100644
--- a/service/processor/pom.xml
+++ b/service/processor/pom.xml
@@ -49,7 +49,7 @@
<dependency>
<groupId>com.google.auto</groupId>
<artifactId>auto-common</artifactId>
- <version>0.10</version>
+ <version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
diff --git a/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java b/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java
index 3bf42d91..f12299a5 100644
--- a/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java
+++ b/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java
@@ -17,8 +17,10 @@ package com.google.auto.service.processor;
import static com.google.auto.common.AnnotationMirrors.getAnnotationValue;
import static com.google.auto.common.MoreElements.getAnnotationMirror;
-import static com.google.common.collect.ImmutableSet.toImmutableSet;
+import static com.google.auto.common.MoreStreams.toImmutableSet;
+import static com.google.common.base.Throwables.getStackTraceAsString;
+import com.google.auto.common.MoreElements;
import com.google.auto.common.MoreTypes;
import com.google.auto.service.AutoService;
import com.google.common.annotations.VisibleForTesting;
@@ -28,8 +30,7 @@ import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -57,10 +58,11 @@ import javax.tools.StandardLocation;
* configuration files described in {@link java.util.ServiceLoader}.
* <p>
* Processor Options:<ul>
- * <li>debug - turns on debug statements</li>
+ * <li>{@code -Adebug} - turns on debug statements</li>
+ * <li>{@code -Averify=true} - turns on extra verification</li>
* </ul>
*/
-@SupportedOptions({ "debug", "verify" })
+@SupportedOptions({"debug", "verify"})
public class AutoServiceProcessor extends AbstractProcessor {
@VisibleForTesting
@@ -74,7 +76,7 @@ public class AutoServiceProcessor extends AbstractProcessor {
* {@code "com.google.apphosting.LocalRpcService" ->
* "com.google.apphosting.datastore.LocalDatastoreService"}
*/
- private Multimap<String, String> providers = HashMultimap.create();
+ private final Multimap<String, String> providers = HashMultimap.create();
@Override
public ImmutableSet<String> getSupportedAnnotationTypes() {
@@ -104,28 +106,24 @@ public class AutoServiceProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
- return processImpl(annotations, roundEnv);
- } catch (Exception e) {
+ processImpl(annotations, roundEnv);
+ } catch (RuntimeException e) {
// We don't allow exceptions of any kind to propagate to the compiler
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- fatalError(writer.toString());
- return true;
+ fatalError(getStackTraceAsString(e));
}
+ return false;
}
- private boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ private void processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
generateConfigFiles();
} else {
processAnnotations(annotations, roundEnv);
}
-
- return true;
}
- private void processAnnotations(Set<? extends TypeElement> annotations,
- RoundEnvironment roundEnv) {
+ private void processAnnotations(
+ Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(AutoService.class);
@@ -134,7 +132,7 @@ public class AutoServiceProcessor extends AbstractProcessor {
for (Element e : elements) {
// TODO(gak): check for error trees?
- TypeElement providerImplementer = (TypeElement) e;
+ TypeElement providerImplementer = MoreElements.asType(e);
AnnotationMirror annotationMirror = getAnnotationMirror(e, AutoService.class).get();
Set<DeclaredType> providerInterfaces = getValueFieldOfClasses(annotationMirror);
if (providerInterfaces.isEmpty()) {
@@ -147,12 +145,14 @@ public class AutoServiceProcessor extends AbstractProcessor {
log("provider interface: " + providerType.getQualifiedName());
log("provider implementer: " + providerImplementer.getQualifiedName());
- if (checkImplementer(providerImplementer, providerType)) {
+ if (checkImplementer(providerImplementer, providerType, annotationMirror)) {
providers.put(getBinaryName(providerType), getBinaryName(providerImplementer));
} else {
- String message = "ServiceProviders must implement their service provider interface. "
- + providerImplementer.getQualifiedName() + " does not implement "
- + providerType.getQualifiedName();
+ String message =
+ "ServiceProviders must implement their service provider interface. "
+ + providerImplementer.getQualifiedName()
+ + " does not implement "
+ + providerType.getQualifiedName();
error(message, e, annotationMirror);
}
}
@@ -172,8 +172,8 @@ public class AutoServiceProcessor extends AbstractProcessor {
// before we attempt to get the resource in case the behavior
// of filer.getResource does change to match the spec, but there's
// no good way to resolve CLASS_OUTPUT without first getting a resource.
- FileObject existingFile = filer.getResource(StandardLocation.CLASS_OUTPUT, "",
- resourceFile);
+ FileObject existingFile =
+ filer.getResource(StandardLocation.CLASS_OUTPUT, "", resourceFile);
log("Looking for existing resource file at " + existingFile.toUri());
Set<String> oldServices = ServicesFiles.readServiceFile(existingFile.openInputStream());
log("Existing service entries: " + oldServices);
@@ -187,19 +187,18 @@ public class AutoServiceProcessor extends AbstractProcessor {
log("Resource file did not already exist.");
}
- Set<String> newServices = new HashSet<String>(providers.get(providerInterface));
- if (allServices.containsAll(newServices)) {
+ Set<String> newServices = new HashSet<>(providers.get(providerInterface));
+ if (!allServices.addAll(newServices)) {
log("No new service entries being added.");
- return;
+ continue;
}
- allServices.addAll(newServices);
log("New service file contents: " + allServices);
- FileObject fileObject = filer.createResource(StandardLocation.CLASS_OUTPUT, "",
- resourceFile);
- OutputStream out = fileObject.openOutputStream();
- ServicesFiles.writeServiceFile(allServices, out);
- out.close();
+ FileObject fileObject =
+ filer.createResource(StandardLocation.CLASS_OUTPUT, "", resourceFile);
+ try (OutputStream out = fileObject.openOutputStream()) {
+ ServicesFiles.writeServiceFile(allServices, out);
+ }
log("Wrote to: " + fileObject.toUri());
} catch (IOException e) {
fatalError("Unable to create " + resourceFile + ", " + e);
@@ -209,14 +208,17 @@ public class AutoServiceProcessor extends AbstractProcessor {
}
/**
- * Verifies {@link ServiceProvider} constraints on the concrete provider class.
- * Note that these constraints are enforced at runtime via the ServiceLoader,
- * we're just checking them at compile time to be extra nice to our users.
+ * Verifies {@link ServiceProvider} constraints on the concrete provider class. Note that these
+ * constraints are enforced at runtime via the ServiceLoader, we're just checking them at compile
+ * time to be extra nice to our users.
*/
- private boolean checkImplementer(TypeElement providerImplementer, TypeElement providerType) {
+ private boolean checkImplementer(
+ TypeElement providerImplementer,
+ TypeElement providerType,
+ AnnotationMirror annotationMirror) {
String verify = processingEnv.getOptions().get("verify");
- if (verify == null || !Boolean.valueOf(verify)) {
+ if (verify == null || !Boolean.parseBoolean(verify)) {
return true;
}
@@ -225,7 +227,37 @@ public class AutoServiceProcessor extends AbstractProcessor {
Types types = processingEnv.getTypeUtils();
- return types.isSubtype(providerImplementer.asType(), providerType.asType());
+ if (types.isSubtype(providerImplementer.asType(), providerType.asType())) {
+ return true;
+ }
+
+ // Maybe the provider has generic type, but the argument to @AutoService can't be generic.
+ // So we allow that with a warning, which can be suppressed with @SuppressWarnings("rawtypes").
+ // See https://github.com/google/auto/issues/870.
+ if (types.isSubtype(providerImplementer.asType(), types.erasure(providerType.asType()))) {
+ if (!rawTypesSuppressed(providerImplementer)) {
+ warning(
+ "Service provider "
+ + providerType
+ + " is generic, so it can't be named exactly by @AutoService."
+ + " If this is OK, add @SuppressWarnings(\"rawtypes\").",
+ providerImplementer,
+ annotationMirror);
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ private static boolean rawTypesSuppressed(Element element) {
+ for (; element != null; element = element.getEnclosingElement()) {
+ SuppressWarnings suppress = element.getAnnotation(SuppressWarnings.class);
+ if (suppress != null && Arrays.asList(suppress.value()).contains("rawtypes")) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -241,19 +273,20 @@ public class AutoServiceProcessor extends AbstractProcessor {
Element enclosingElement = element.getEnclosingElement();
if (enclosingElement instanceof PackageElement) {
- PackageElement pkg = (PackageElement) enclosingElement;
+ PackageElement pkg = MoreElements.asPackage(enclosingElement);
if (pkg.isUnnamed()) {
return className;
}
return pkg.getQualifiedName() + "." + className;
}
- TypeElement typeElement = (TypeElement) enclosingElement;
+ TypeElement typeElement = MoreElements.asType(enclosingElement);
return getBinaryNameImpl(typeElement, typeElement.getSimpleName() + "$" + className);
}
/**
- * Returns the contents of a {@code Class[]}-typed "value" field in a given {@code annotationMirror}.
+ * Returns the contents of a {@code Class[]}-typed "value" field in a given {@code
+ * annotationMirror}.
*/
private ImmutableSet<DeclaredType> getValueFieldOfClasses(AnnotationMirror annotationMirror) {
return getAnnotationValue(annotationMirror, "value")
@@ -261,16 +294,15 @@ public class AutoServiceProcessor extends AbstractProcessor {
new SimpleAnnotationValueVisitor8<ImmutableSet<DeclaredType>, Void>() {
@Override
public ImmutableSet<DeclaredType> visitType(TypeMirror typeMirror, Void v) {
- // TODO(ronshapiro): class literals may not always be declared types, i.e. int.class,
- // int[].class
+ // TODO(ronshapiro): class literals may not always be declared types, i.e.
+ // int.class, int[].class
return ImmutableSet.of(MoreTypes.asDeclared(typeMirror));
}
@Override
public ImmutableSet<DeclaredType> visitArray(
List<? extends AnnotationValue> values, Void v) {
- return values
- .stream()
+ return values.stream()
.flatMap(value -> value.accept(this, null).stream())
.collect(toImmutableSet());
}
@@ -284,6 +316,10 @@ public class AutoServiceProcessor extends AbstractProcessor {
}
}
+ private void warning(String msg, Element element, AnnotationMirror annotation) {
+ processingEnv.getMessager().printMessage(Kind.WARNING, msg, element, annotation);
+ }
+
private void error(String msg, Element element, AnnotationMirror annotation) {
processingEnv.getMessager().printMessage(Kind.ERROR, msg, element, annotation);
}
diff --git a/service/processor/src/main/java/com/google/auto/service/processor/ServicesFiles.java b/service/processor/src/main/java/com/google/auto/service/processor/ServicesFiles.java
index c61b3ba2..75d6cca7 100644
--- a/service/processor/src/main/java/com/google/auto/service/processor/ServicesFiles.java
+++ b/service/processor/src/main/java/com/google/auto/service/processor/ServicesFiles.java
@@ -35,7 +35,7 @@ import java.util.Set;
final class ServicesFiles {
public static final String SERVICES_PATH = "META-INF/services";
- private ServicesFiles() { }
+ private ServicesFiles() {}
/**
* Returns an absolute path to a service file given the class
@@ -96,4 +96,4 @@ final class ServicesFiles {
}
writer.flush();
}
-} \ No newline at end of file
+}
diff --git a/service/processor/src/main/java/com/google/auto/service/processor/package-info.java b/service/processor/src/main/java/com/google/auto/service/processor/package-info.java
index a9f0adb5..453c95e8 100644
--- a/service/processor/src/main/java/com/google/auto/service/processor/package-info.java
+++ b/service/processor/src/main/java/com/google/auto/service/processor/package-info.java
@@ -15,4 +15,4 @@
* This package contains the annotation processor that implements the
* {@link com.google.auto.service.AutoService} API.
*/
-package com.google.auto.service.processor; \ No newline at end of file
+package com.google.auto.service.processor;
diff --git a/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java b/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java
index d3e00a73..35615689 100644
--- a/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java
+++ b/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java
@@ -16,52 +16,132 @@
package com.google.auto.service.processor;
import static com.google.auto.service.processor.AutoServiceProcessor.MISSING_SERVICES_ERROR;
-import static com.google.testing.compile.JavaSourcesSubject.assertThat;
+import static com.google.testing.compile.CompilationSubject.assertThat;
+import com.google.common.io.Resources;
+import com.google.testing.compile.Compilation;
+import com.google.testing.compile.Compiler;
import com.google.testing.compile.JavaFileObjects;
+import javax.tools.StandardLocation;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/**
- * Tests the {@link AutoServiceProcessor}.
- */
+/** Tests the {@link AutoServiceProcessor}. */
@RunWith(JUnit4.class)
public class AutoServiceProcessorTest {
@Test
public void autoService() {
- assertThat(
- JavaFileObjects.forResource("test/SomeService.java"),
- JavaFileObjects.forResource("test/SomeServiceProvider1.java"),
- JavaFileObjects.forResource("test/SomeServiceProvider2.java"),
- JavaFileObjects.forResource("test/Enclosing.java"),
- JavaFileObjects.forResource("test/AnotherService.java"),
- JavaFileObjects.forResource("test/AnotherServiceProvider.java"))
- .processedWith(new AutoServiceProcessor())
- .compilesWithoutError()
- .and().generatesFiles(
- JavaFileObjects.forResource("META-INF/services/test.SomeService"),
- JavaFileObjects.forResource("META-INF/services/test.AnotherService"));
+ Compilation compilation =
+ Compiler.javac()
+ .withProcessors(new AutoServiceProcessor())
+ .compile(
+ JavaFileObjects.forResource("test/SomeService.java"),
+ JavaFileObjects.forResource("test/SomeServiceProvider1.java"),
+ JavaFileObjects.forResource("test/SomeServiceProvider2.java"),
+ JavaFileObjects.forResource("test/Enclosing.java"),
+ JavaFileObjects.forResource("test/AnotherService.java"),
+ JavaFileObjects.forResource("test/AnotherServiceProvider.java"));
+ assertThat(compilation).succeededWithoutWarnings();
+ assertThat(compilation)
+ .generatedFile(StandardLocation.CLASS_OUTPUT, "META-INF/services/test.SomeService")
+ .hasContents(
+ Resources.asByteSource(Resources.getResource("META-INF/services/test.SomeService")));
+ assertThat(compilation)
+ .generatedFile(StandardLocation.CLASS_OUTPUT, "META-INF/services/test.AnotherService")
+ .hasContents(
+ Resources.asByteSource(Resources.getResource("META-INF/services/test.AnotherService")));
}
@Test
public void multiService() {
- assertThat(
- JavaFileObjects.forResource("test/SomeService.java"),
- JavaFileObjects.forResource("test/AnotherService.java"),
- JavaFileObjects.forResource("test/MultiServiceProvider.java"))
- .processedWith(new AutoServiceProcessor())
- .compilesWithoutError()
- .and().generatesFiles(
- JavaFileObjects.forResource("META-INF/services/test.SomeServiceMulti"),
- JavaFileObjects.forResource("META-INF/services/test.AnotherServiceMulti"));
+ Compilation compilation =
+ Compiler.javac()
+ .withProcessors(new AutoServiceProcessor())
+ .compile(
+ JavaFileObjects.forResource("test/SomeService.java"),
+ JavaFileObjects.forResource("test/AnotherService.java"),
+ JavaFileObjects.forResource("test/MultiServiceProvider.java"));
+ assertThat(compilation).succeededWithoutWarnings();
+ // We have @AutoService({SomeService.class, AnotherService.class}) class MultiServiceProvider.
+ // So we expect META-INF/services/test.SomeService with contents that name MultiServiceProvider
+ // and likewise META-INF/services/test.AnotherService.
+ assertThat(compilation)
+ .generatedFile(StandardLocation.CLASS_OUTPUT, "META-INF/services/test.SomeService")
+ .contentsAsUtf8String()
+ .isEqualTo("test.MultiServiceProvider\n");
+ assertThat(compilation)
+ .generatedFile(StandardLocation.CLASS_OUTPUT, "META-INF/services/test.AnotherService")
+ .contentsAsUtf8String()
+ .isEqualTo("test.MultiServiceProvider\n");
}
@Test
public void badMultiService() {
- assertThat(JavaFileObjects.forResource("test/NoServices.java"))
- .processedWith(new AutoServiceProcessor())
- .failsToCompile()
- .withErrorContaining(MISSING_SERVICES_ERROR);
+ Compilation compilation =
+ Compiler.javac()
+ .withProcessors(new AutoServiceProcessor())
+ .compile(JavaFileObjects.forResource("test/NoServices.java"));
+ assertThat(compilation).failed();
+ assertThat(compilation).hadErrorContaining(MISSING_SERVICES_ERROR);
+ }
+
+ @Test
+ public void generic() {
+ Compilation compilation =
+ Compiler.javac()
+ .withProcessors(new AutoServiceProcessor())
+ .compile(
+ JavaFileObjects.forResource("test/GenericService.java"),
+ JavaFileObjects.forResource("test/GenericServiceProvider.java"));
+ assertThat(compilation).succeededWithoutWarnings();
+ assertThat(compilation)
+ .generatedFile(StandardLocation.CLASS_OUTPUT, "META-INF/services/test.GenericService")
+ .contentsAsUtf8String()
+ .isEqualTo("test.GenericServiceProvider\n");
+ }
+
+ @Test
+ public void genericWithVerifyOption() {
+ Compilation compilation =
+ Compiler.javac()
+ .withProcessors(new AutoServiceProcessor())
+ .withOptions("-Averify=true")
+ .compile(
+ JavaFileObjects.forResource("test/GenericService.java"),
+ JavaFileObjects.forResource("test/GenericServiceProvider.java"));
+ assertThat(compilation).succeeded();
+ assertThat(compilation)
+ .hadWarningContaining(
+ "Service provider test.GenericService is generic, so it can't be named exactly by"
+ + " @AutoService. If this is OK, add @SuppressWarnings(\"rawtypes\").");
+ }
+
+ @Test
+ public void genericWithVerifyOptionAndSuppressWarings() {
+ Compilation compilation =
+ Compiler.javac()
+ .withProcessors(new AutoServiceProcessor())
+ .withOptions("-Averify=true")
+ .compile(
+ JavaFileObjects.forResource("test/GenericService.java"),
+ JavaFileObjects.forResource("test/GenericServiceProviderSuppressWarnings.java"));
+ assertThat(compilation).succeededWithoutWarnings();
+ }
+
+ @Test
+ public void nestedGenericWithVerifyOptionAndSuppressWarnings() {
+ Compilation compilation =
+ Compiler.javac()
+ .withProcessors(new AutoServiceProcessor())
+ .withOptions("-Averify=true")
+ .compile(
+ JavaFileObjects.forResource("test/GenericService.java"),
+ JavaFileObjects.forResource("test/EnclosingGeneric.java"));
+ assertThat(compilation).succeededWithoutWarnings();
+ assertThat(compilation)
+ .generatedFile(StandardLocation.CLASS_OUTPUT, "META-INF/services/test.GenericService")
+ .contentsAsUtf8String()
+ .isEqualTo("test.EnclosingGeneric$GenericServiceProvider\n");
}
}
diff --git a/service/processor/src/test/resources/META-INF/services/test.AnotherServiceMulti b/service/processor/src/test/resources/META-INF/services/test.AnotherServiceMulti
deleted file mode 100644
index f6ef36ac..00000000
--- a/service/processor/src/test/resources/META-INF/services/test.AnotherServiceMulti
+++ /dev/null
@@ -1 +0,0 @@
-test.MultiServiceProvider
diff --git a/service/processor/src/test/resources/META-INF/services/test.SomeServiceMulti b/service/processor/src/test/resources/META-INF/services/test.SomeServiceMulti
deleted file mode 100644
index f6ef36ac..00000000
--- a/service/processor/src/test/resources/META-INF/services/test.SomeServiceMulti
+++ /dev/null
@@ -1 +0,0 @@
-test.MultiServiceProvider
diff --git a/service/processor/src/test/resources/test/AnotherService.java b/service/processor/src/test/resources/test/AnotherService.java
index c096c223..de80f06d 100644
--- a/service/processor/src/test/resources/test/AnotherService.java
+++ b/service/processor/src/test/resources/test/AnotherService.java
@@ -15,4 +15,4 @@
*/
package test;
-interface AnotherService { } \ No newline at end of file
+interface AnotherService {}
diff --git a/service/processor/src/test/resources/test/AnotherServiceProvider.java b/service/processor/src/test/resources/test/AnotherServiceProvider.java
index c5e5c117..2a023e43 100644
--- a/service/processor/src/test/resources/test/AnotherServiceProvider.java
+++ b/service/processor/src/test/resources/test/AnotherServiceProvider.java
@@ -18,4 +18,4 @@ package test;
import com.google.auto.service.AutoService;
@AutoService(AnotherService.class)
-public class AnotherServiceProvider implements AnotherService { } \ No newline at end of file
+public class AnotherServiceProvider implements AnotherService {}
diff --git a/service/processor/src/test/resources/test/Enclosing.java b/service/processor/src/test/resources/test/Enclosing.java
index 26dd5852..24202a59 100644
--- a/service/processor/src/test/resources/test/Enclosing.java
+++ b/service/processor/src/test/resources/test/Enclosing.java
@@ -19,5 +19,5 @@ import com.google.auto.service.AutoService;
public class Enclosing {
@AutoService(SomeService.class)
- public static class NestedSomeServiceProvider implements SomeService { }
-} \ No newline at end of file
+ public static class NestedSomeServiceProvider implements SomeService {}
+}
diff --git a/service/processor/src/test/resources/test/EnclosingGeneric.java b/service/processor/src/test/resources/test/EnclosingGeneric.java
new file mode 100644
index 00000000..cddddacb
--- /dev/null
+++ b/service/processor/src/test/resources/test/EnclosingGeneric.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * 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 test;
+
+import com.google.auto.service.AutoService;
+
+/** Test for suppressing warnings about raw types on nested {@code @AutoService} classes. */
+@SuppressWarnings("rawtypes")
+public final class EnclosingGeneric {
+ /**
+ * This is technically a raw class reference, but should be suppressed by the
+ * {@code @SuppressWarnings} on the enclosing class.
+ */
+ @AutoService(GenericService.class)
+ public class GenericServiceProvider<T> implements GenericService<T> {}
+
+ private EnclosingGeneric() {}
+}
diff --git a/service/processor/src/test/resources/test/GenericService.java b/service/processor/src/test/resources/test/GenericService.java
new file mode 100644
index 00000000..5ed13ffc
--- /dev/null
+++ b/service/processor/src/test/resources/test/GenericService.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * 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 test;
+
+/**
+ * An interface with a type parameter, which by default will produce a warning with
+ * {@code @AutoService} if you compile with {@code -Averify=true}.
+ */
+public interface GenericService<T> {}
diff --git a/service/processor/src/test/resources/test/GenericServiceProvider.java b/service/processor/src/test/resources/test/GenericServiceProvider.java
new file mode 100644
index 00000000..84c5cba0
--- /dev/null
+++ b/service/processor/src/test/resources/test/GenericServiceProvider.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * 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 test;
+
+import com.google.auto.service.AutoService;
+
+/**
+ * An implementation of a service with a type parameter, which by default will produce a warning
+ * if you compile with {@code -Averify=true}.
+ */
+@AutoService(GenericService.class)
+public class GenericServiceProvider<T> implements GenericService<T> {}
diff --git a/service/processor/src/test/resources/test/GenericServiceProviderSuppressWarnings.java b/service/processor/src/test/resources/test/GenericServiceProviderSuppressWarnings.java
new file mode 100644
index 00000000..eb285dad
--- /dev/null
+++ b/service/processor/src/test/resources/test/GenericServiceProviderSuppressWarnings.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * 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 test;
+
+import com.google.auto.service.AutoService;
+
+/**
+ * An implementation of a service with a type parameter, which will not produce a warning even if
+ * compiled with {@code -Averify=true}, because of the {@code @SuppressWarnings}.
+ */
+@AutoService(GenericService.class)
+@SuppressWarnings("rawtypes")
+public class GenericServiceProviderSuppressWarnings<T> implements GenericService<T> {}
diff --git a/service/processor/src/test/resources/test/SomeService.java b/service/processor/src/test/resources/test/SomeService.java
index d29c4097..d81cac40 100644
--- a/service/processor/src/test/resources/test/SomeService.java
+++ b/service/processor/src/test/resources/test/SomeService.java
@@ -15,4 +15,4 @@
*/
package test;
-interface SomeService { } \ No newline at end of file
+interface SomeService {}
diff --git a/service/processor/src/test/resources/test/SomeServiceProvider1.java b/service/processor/src/test/resources/test/SomeServiceProvider1.java
index 008136be..fc2c843c 100644
--- a/service/processor/src/test/resources/test/SomeServiceProvider1.java
+++ b/service/processor/src/test/resources/test/SomeServiceProvider1.java
@@ -18,4 +18,4 @@ package test;
import com.google.auto.service.AutoService;
@AutoService(SomeService.class)
-public class SomeServiceProvider1 implements SomeService { } \ No newline at end of file
+public class SomeServiceProvider1 implements SomeService {}
diff --git a/service/processor/src/test/resources/test/SomeServiceProvider2.java b/service/processor/src/test/resources/test/SomeServiceProvider2.java
index 5444996b..b7097d41 100644
--- a/service/processor/src/test/resources/test/SomeServiceProvider2.java
+++ b/service/processor/src/test/resources/test/SomeServiceProvider2.java
@@ -18,4 +18,4 @@ package test;
import com.google.auto.service.AutoService;
@AutoService(SomeService.class)
-public class SomeServiceProvider2 implements SomeService { } \ No newline at end of file
+public class SomeServiceProvider2 implements SomeService {}