Skip to content

Commit

Permalink
Handle EventPublishWriter TypeElement nulls (#726)
Browse files Browse the repository at this point in the history
* handle null from typeElement

* Format only

---------

Co-authored-by: Rob Bygrave <robin.bygrave@gmail.com>
  • Loading branch information
SentryMan and rbygrave authored Nov 4, 2024
1 parent cd67092 commit 1486196
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Optional;

import javax.lang.model.element.Element;
import javax.lang.model.element.PackageElement;
import javax.tools.JavaFileObject;

/** Write the source code for the bean. */
Expand Down Expand Up @@ -46,22 +47,23 @@ static void write(Element element) {
private EventPublisherWriter(Element element) {
final var asType = element.asType();
this.utype = UType.parse(asType).param0();
this.packageName = APContext.elements()
.getPackageOf(APContext.typeElement(utype.mainType()))
.getQualifiedName()
.toString()
this.packageName = Optional.ofNullable(APContext.typeElement(utype.mainType()))
.map(APContext.elements()::getPackageOf)
.map(PackageElement::getQualifiedName)
.map(Object::toString)
.orElse("error.notype")
.replaceFirst("java.", "")
+ ".events";
qualifier = Optional.ofNullable(Util.named(element)).orElse("");

this.qualifier = Optional.ofNullable(Util.named(element)).orElse("");
var className =
packageName
+ "."
+ (qualifier.isEmpty() ? "" : "Qualified")
+ Util.shortName(utype).replace(".", "_")
+ "$Publisher";

originName = getUniqueClassName(className, 0);

this.originName = getUniqueClassName(className, 0);
if (GENERATED_PUBLISHERS.containsKey(originName)) {
//in super niche situations when compiling the same module, we need to tell avaje that these types already exist
//got this when running both my eclipse compiler and then the terminal build
Expand Down

0 comments on commit 1486196

Please sign in to comment.