From 1bbb1366145029c39bf8174de2516a0d6511a859 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Tue, 2 Feb 2021 14:09:44 -0800 Subject: Include all simple names present in source for error types When creating error types to model invalid elements during annotation processing, include all simple names present in source for qualified names, instead of just the last one. This fixes https://github.com/bazelbuild/bazel/issues/12926 PiperOrigin-RevId: 355249091 --- .../processing/ProcessingIntegrationTest.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'javatests') diff --git a/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java b/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java index f6a00d2..0774bf4 100644 --- a/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java +++ b/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java @@ -19,6 +19,7 @@ package com.google.turbine.processing; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.MoreCollectors.onlyElement; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth8.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; import static org.junit.Assert.fail; @@ -509,6 +510,51 @@ public class ProcessingIntegrationTest { assertThat(bound.generatedSources()).containsKey("A.java"); } + @SupportedAnnotationTypes("*") + public static class GenerateQualifiedProcessor extends AbstractProcessor { + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + String superType = + processingEnv.getElementUtils().getTypeElement("T").getSuperclass().toString(); + processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, superType); + return false; + } + } + + @Test + public void qualifiedErrorType() throws IOException { + ImmutableList units = + parseUnit( + "=== T.java ===", // + "class T extends G.I {", + "}"); + try { + Binder.bind( + units, + ClassPathBinder.bindClasspath(ImmutableList.of()), + ProcessorInfo.create( + ImmutableList.of(new GenerateQualifiedProcessor()), + getClass().getClassLoader(), + ImmutableMap.of(), + SourceVersion.latestSupported()), + TestClassPaths.TURBINE_BOOTCLASSPATH, + Optional.empty()); + fail(); + } catch (TurbineError e) { + assertThat( + e.diagnostics().stream() + .filter(d -> d.severity().equals(Diagnostic.Kind.NOTE)) + .map(d -> d.message())) + .containsExactly("G.I"); + } + } + private static ImmutableList parseUnit(String... lines) { return IntegrationTestSupport.TestInput.parse(Joiner.on('\n').join(lines)) .sources -- cgit v1.2.3