diff --git a/README.md b/README.md index 44780ae..d4dec4a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Requires Java 17+. dev.mccue magic-bean - 1.0.0 + 1.0.1 provided ``` @@ -26,7 +26,7 @@ Requires Java 17+. ### deps.edn ```edn {:mvn/repos {"jitpack" {:url "https://jitpack.io"}} - :aliases {:compile {:deps {dev.mccue/magic-bean {:mvn/version "1.0.0"}}}}} + :aliases {:compile {:deps {dev.mccue/magic-bean {:mvn/version "1.0.1"}}}}} ``` ## What this does diff --git a/pom.xml b/pom.xml index 96e39ee..996df2b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.mccue magic-bean - 1.0.0 + 1.0.1 jar diff --git a/src/main/java/dev/mccue/magic_bean/processor/AnnotationProcessor.java b/src/main/java/dev/mccue/magic_bean/processor/AnnotationProcessor.java index 67cdf01..8d65033 100644 --- a/src/main/java/dev/mccue/magic_bean/processor/AnnotationProcessor.java +++ b/src/main/java/dev/mccue/magic_bean/processor/AnnotationProcessor.java @@ -35,6 +35,7 @@ private String staticFactoryMethod(Name className, List fields) for (int i = 0; i < fields.size(); i++) { var field = fields.get(i); + staticFactoryMethod.append(" "); staticFactoryMethod.append(field.asType()); staticFactoryMethod.append(" "); @@ -156,7 +157,7 @@ public boolean process( if (modifiers.contains(Modifier.FINAL)) { messager.printMessage( Diagnostic.Kind.ERROR, - "Magic beans are not allowed to have any private non-static fields", + "Magic beans are not allowed to have any final non-static fields", element ); @@ -183,10 +184,12 @@ public boolean process( constructor.getParameters().size() == 0 && !constructor.getModifiers().contains(Modifier.PRIVATE) ); - if (!hasValidConstructor) { + + var annotation = typeElement.getAnnotation(MagicBean.class); + if (annotation.generateAllArgsStaticFactory() && !hasValidConstructor) { messager.printMessage( Diagnostic.Kind.ERROR, - "Magic beans need to have a non-private zero arg constructor", + "Magic beans need to have a non-private zero arg constructor in order for a factory method to be generated.", element ); return true; @@ -212,8 +215,6 @@ public boolean process( selfExpr = "((%s) this)".formatted(className); } - - var annotation = typeElement.getAnnotation(MagicBean.class); boolean useAbstractClass = annotation.generateToString() || annotation.generateEqualsAndHashCode(); BiFunction methodDefinition = (fieldType, fieldName) -> {