-
Notifications
You must be signed in to change notification settings - Fork 103
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
[ISSUE-179] Improve message regarding duplicated annotated constructors #180
Conversation
Try something like diff --git core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java
index 335074db3..c40b32d03 100644
--- core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java
+++ core/src/main/java/org/kohsuke/stapler/jsr269/ConstructorProcessor.java
@@ -30,10 +30,15 @@ public class ConstructorProcessor extends AbstractProcessorImpl {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
ElementScanner6<Void, Void> scanner = new ElementScanner6<Void, Void>() {
+ boolean written;
@Override
public Void visitExecutable(ExecutableElement e, Void aVoid) {
if(e.getAnnotation(DataBoundConstructor.class)!=null) {
- write(e);
+ if (written) {
+ processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Only one @DataBoundConstructor is permitted per class", e);
+ } else {
+ write(e);
+ }
} else {
String javadoc = getJavadoc(e);
if(javadoc!=null && javadoc.contains("@stapler-constructor")) { |
It fails when annotation is in several inner classes
@jglick This latest approach fails when the annotation is duplicated because of several annotated constructors in inner classes:
|
Back to catching the exception |
Nested classes you mean. Adding a I think this is simply because the processor is being passed source units (typically meaning one top-level class), so |
See #190. |
Fixes #179
This PR improves the message when you have two annotated constructors in the same class + tests.
The error now is not descriptive: