Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support package level annotations #5

Merged
merged 3 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic.Kind;
Expand Down Expand Up @@ -80,6 +81,10 @@ void add(Element elt) {
case CONSTRUCTOR:
t = (TypeElement) elt.getEnclosingElement();
break;
case PACKAGE:
classes.add(((PackageElement)elt).getQualifiedName().toString());
jglick marked this conversation as resolved.
Show resolved Hide resolved
return;

default:
// throw new AssertionError(elt.getKind());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ public class AnnotationProcessorImplTest {
assertEquals("some.pkg.Stuff" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
}

@Test public void packageinfo() {
Compilation compilation = new Compilation();
compilation.addSource("some.pkg.package-info").
addLine("@" + A.class.getCanonicalName()).
addLine("package some.pkg;");
compilation.addSource("some.pkg.Stuff").
addLine("package some.pkg;").
addLine("public class Stuff {}");
compilation.doCompile(null, "-source", "6");
assertEquals(Collections.emptyList(), Utils.filterObsoleteSourceVersionWarnings(compilation.getDiagnostics()));
assertEquals("some.pkg" + System.getProperty("line.separator"), Utils.getGeneratedResource(compilation, "META-INF/annotations/" + A.class.getName()));
}



@Test public void incremental() {
Compilation compilation = new Compilation();
compilation.addSource("some.pkg.Stuff").
Expand Down