Skip to content

Commit 1486196

Browse files
SentryManrbygrave
andauthored
Handle EventPublishWriter TypeElement nulls (avaje#726)
* handle null from typeElement * Format only --------- Co-authored-by: Rob Bygrave <[email protected]>
1 parent cd67092 commit 1486196

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/EventPublisherWriter.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Optional;
1515

1616
import javax.lang.model.element.Element;
17+
import javax.lang.model.element.PackageElement;
1718
import javax.tools.JavaFileObject;
1819

1920
/** Write the source code for the bean. */
@@ -46,22 +47,23 @@ static void write(Element element) {
4647
private EventPublisherWriter(Element element) {
4748
final var asType = element.asType();
4849
this.utype = UType.parse(asType).param0();
49-
this.packageName = APContext.elements()
50-
.getPackageOf(APContext.typeElement(utype.mainType()))
51-
.getQualifiedName()
52-
.toString()
50+
this.packageName = Optional.ofNullable(APContext.typeElement(utype.mainType()))
51+
.map(APContext.elements()::getPackageOf)
52+
.map(PackageElement::getQualifiedName)
53+
.map(Object::toString)
54+
.orElse("error.notype")
5355
.replaceFirst("java.", "")
5456
+ ".events";
55-
qualifier = Optional.ofNullable(Util.named(element)).orElse("");
57+
58+
this.qualifier = Optional.ofNullable(Util.named(element)).orElse("");
5659
var className =
5760
packageName
5861
+ "."
5962
+ (qualifier.isEmpty() ? "" : "Qualified")
6063
+ Util.shortName(utype).replace(".", "_")
6164
+ "$Publisher";
6265

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

0 commit comments

Comments
 (0)