-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
The implementation of ImmutablesBuilderProvider in 1.3.x and 1.4 branches doesn't support inner classes for immutables.
Example immutable:
@Value.Immutable
public interface Parent {
List<Child> getChildren();
@Value.Immutable
public interface Child {
String string();
Integer integer();
}
}A Mapper that encounters the Parent type will fail silently in 1.3 (no mapper generated) and with an error in 1.4 calling out that the mapper wasn't generated and suggesting verbose mode.
The root cause looks to be in the ImmutablesBuilderProvider building of the immutable TypeElement.
https://github.com/mapstruct/mapstruct/blame/1.3.x/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java#L76
if ( enclosingElement.getKind() == ElementKind.PACKAGE ) {
builderQualifiedName.append( ( (PackageElement) enclosingElement ).getQualifiedName().toString() );
}
else {
builderQualifiedName.append( ( (TypeElement) enclosingElement ).getQualifiedName().toString() );
}I think the intent of the code above is to get the FQN of the package, not the enclosing type. The desired change is to keep walking until you hit the package element. This matches what I'm seeing generated by Immutables.
The workaround is simply to not use inner classes. If inner classes are important, then providing a custom implementation of the ImmutablesBuilderProvider is possible. The method that needs to change is protected and the class isn't final.
I've refactored the inner classes away for now. I could submit a patch if you're open to it.