Skip to content

Commit

Permalink
Fix incorrect error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bowbahdoe committed Jan 22, 2022
1 parent 5fd8038 commit 633982c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Requires Java 17+.
<dependency>
<groupId>dev.mccue</groupId>
<artifactId>magic-bean</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
```

### 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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.mccue</groupId>
<artifactId>magic-bean</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private String staticFactoryMethod(Name className, List<VariableElement> fields)

for (int i = 0; i < fields.size(); i++) {
var field = fields.get(i);

staticFactoryMethod.append(" ");
staticFactoryMethod.append(field.asType());
staticFactoryMethod.append(" ");
Expand Down Expand Up @@ -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
);

Expand All @@ -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;
Expand All @@ -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<String, String, String> methodDefinition = (fieldType, fieldName) -> {
Expand Down

0 comments on commit 633982c

Please sign in to comment.