generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37aed73
commit 2f21934
Showing
24 changed files
with
609 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/TypeAliasBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package xyz.block.ftl.deployment; | ||
|
||
import org.jboss.jandex.Type; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
public final class TypeAliasBuildItem extends MultiBuildItem { | ||
|
||
final String name; | ||
final String module; | ||
final Type localType; | ||
final Type serializedType; | ||
final boolean exported; | ||
|
||
public TypeAliasBuildItem(String name, String module, Type localType, Type serializedType, boolean exported) { | ||
this.name = name; | ||
this.module = module; | ||
this.localType = localType; | ||
this.serializedType = serializedType; | ||
this.exported = exported; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getModule() { | ||
return module; | ||
} | ||
|
||
public Type getLocalType() { | ||
return localType; | ||
} | ||
|
||
public Type getSerializedType() { | ||
return serializedType; | ||
} | ||
|
||
public boolean isExported() { | ||
return exported; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/TypeAliasProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package xyz.block.ftl.deployment; | ||
|
||
import org.jboss.jandex.Type; | ||
import org.jboss.jandex.TypeVariable; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
|
||
public class TypeAliasProcessor { | ||
|
||
@BuildStep | ||
public void processTypeAlias(CombinedIndexBuildItem index, | ||
BuildProducer<SchemaContributorBuildItem> schemaContributorBuildItemBuildProducer, | ||
BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItem, | ||
BuildProducer<TypeAliasBuildItem> typeAliasBuildItemBuildProducer) { | ||
var beans = new AdditionalBeanBuildItem.Builder().setUnremovable(); | ||
for (var mapper : index.getIndex().getAnnotations(FTLDotNames.TYPE_ALIAS)) { | ||
boolean exported = mapper.target().hasAnnotation(FTLDotNames.EXPORT); | ||
// This may or may not be the actual mapper, it may be a subclass | ||
|
||
var mapperClass = mapper.target().asClass(); | ||
var actualMapper = mapperClass; | ||
|
||
Type t = null; | ||
Type s = null; | ||
if (mapperClass.isInterface()) { | ||
for (var i : mapperClass.interfaceTypes()) { | ||
if (i.name().equals(FTLDotNames.TYPE_ALIAS_MAPPER)) { | ||
t = i.asParameterizedType().arguments().get(0); | ||
s = i.asParameterizedType().arguments().get(1); | ||
break; | ||
} | ||
} | ||
var implementations = index.getComputingIndex().getAllKnownImplementors(mapperClass.name()); | ||
if (implementations.isEmpty()) { | ||
continue; | ||
} | ||
if (implementations.size() > 1) { | ||
throw new RuntimeException( | ||
"Multiple implementations of " + mapperClass.name() + " found: " + implementations); | ||
} | ||
actualMapper = implementations.iterator().next(); | ||
} | ||
|
||
//TODO: this is a bit hacky and won't work for complex heirachies | ||
// it is enough to get us going through | ||
for (var i : actualMapper.interfaceTypes()) { | ||
if (i.name().equals(FTLDotNames.TYPE_ALIAS_MAPPER)) { | ||
t = i.asParameterizedType().arguments().get(0); | ||
s = i.asParameterizedType().arguments().get(1); | ||
break; | ||
} else if (i.name().equals(mapperClass.name())) { | ||
if (t instanceof TypeVariable) { | ||
t = i.asParameterizedType().arguments().get(0); | ||
} | ||
if (s instanceof TypeVariable) { | ||
s = i.asParameterizedType().arguments().get(1); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
beans.addBeanClass(actualMapper.name().toString()); | ||
var finalT = t; | ||
var finalS = s; | ||
String module = mapper.value("module") == null ? "" : mapper.value("module").asString(); | ||
String name = mapper.value("name").asString(); | ||
typeAliasBuildItemBuildProducer.produce(new TypeAliasBuildItem(name, module, t, s, exported)); | ||
if (module.isEmpty()) { | ||
schemaContributorBuildItemBuildProducer.produce(new SchemaContributorBuildItem(moduleBuilder -> moduleBuilder | ||
.registerTypeAlias(name, finalT, finalS, exported))); | ||
} | ||
|
||
} | ||
additionalBeanBuildItem.produce(beans.build()); | ||
|
||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/TypeKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package xyz.block.ftl.deployment; | ||
|
||
import java.util.List; | ||
|
||
record TypeKey(String name, List<String> typeParams) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.