diff options
author | Liam Miller-Cushon <cushon@google.com> | 2021-02-02 14:09:44 -0800 |
---|---|---|
committer | Javac Team <javac-team+copybara@google.com> | 2021-02-02 14:10:18 -0800 |
commit | 1bbb1366145029c39bf8174de2516a0d6511a859 (patch) | |
tree | 4347b3cec0cd0279a5b7094c05b7ac45bc0461b9 /javatests | |
parent | 622b59136c480a9aeca3fd6b4cc433c87777f8bd (diff) | |
download | turbine-1bbb1366145029c39bf8174de2516a0d6511a859.tar.gz |
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
Diffstat (limited to 'javatests')
-rw-r--r-- | javatests/com/google/turbine/processing/ProcessingIntegrationTest.java | 46 |
1 files changed, 46 insertions, 0 deletions
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<? extends TypeElement> 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<Tree.CompUnit> 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<Tree.CompUnit> parseUnit(String... lines) { return IntegrationTestSupport.TestInput.parse(Joiner.on('\n').join(lines)) .sources |