Skip to content

Commit

Permalink
TypeInfo and Builder Refinements (#6729)
Browse files Browse the repository at this point in the history
Prereq changes to prepare for pico-anno-processor. This change enhances TypeInfo, TypedElementName, etc. It also introduces builder-testing.
  • Loading branch information
trentjeff authored May 2, 2023
1 parent b24a76e commit 3b7fa02
Show file tree
Hide file tree
Showing 37 changed files with 1,557 additions and 116 deletions.
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,11 @@
<artifactId>helidon-builder-config-processor</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.builder</groupId>
<artifactId>helidon-builder-testing</artifactId>
<version>${helidon.version}</version>
</dependency>

<!-- Pico Core -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected void appendMetaProps(StringBuilder builder,
appendConfigBeanInfoAttributes(builder,
ctx.typeInfo(),
AnnotationAndValueDefault
.findFirst(ConfigBean.class.getTypeName(),
.findFirst(ConfigBean.class,
ctx.typeInfo().annotations()).orElseThrow());
builder.append("\t\t\t\t\t\t.build()));\n");
super.appendMetaProps(builder, ctx, tag, needsCustomMapOf);
Expand Down Expand Up @@ -375,10 +375,10 @@ private void appendAvailableReferencedBuilders(StringBuilder builder,
TypeInfo typeInfo) {
typeInfo.referencedTypeNamesToAnnotations().forEach((k, v) -> {
AnnotationAndValue builderAnnotation = AnnotationAndValueDefault
.findFirst(io.helidon.builder.Builder.class.getName(), v).orElse(null);
.findFirst(io.helidon.builder.Builder.class, v).orElse(null);
if (builderAnnotation == null) {
builderAnnotation = AnnotationAndValueDefault
.findFirst(ConfigBean.class.getName(), v).orElse(null);
.findFirst(ConfigBean.class, v).orElse(null);
}

if (builderAnnotation != null) {
Expand Down Expand Up @@ -453,7 +453,7 @@ private String toConfigKey(String attrName,
AnnotationAndValue ignoredBuilderAnnotation) {
String configKey = null;
Optional<? extends AnnotationAndValue> configuredOptions = AnnotationAndValueDefault
.findFirst(ConfiguredOption.class.getName(), method.annotations());
.findFirst(ConfiguredOption.class, method.annotations());
if (configuredOptions.isPresent()) {
configKey = configuredOptions.get().value("key").orElse(null);
}
Expand Down
1 change: 1 addition & 0 deletions builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<module>processor</module>
<module>builder-config</module>
<module>builder-config-processor</module>
<module>testing</module>
<module>tests</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
package io.helidon.builder.processor.spi;

import java.util.Optional;
import java.util.function.Predicate;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;

import io.helidon.common.types.TypeInfo;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypedElementName;

/**
* Java {@link java.util.ServiceLoader} provider interface used to discover type info creators.
Expand All @@ -32,19 +35,36 @@
public interface TypeInfoCreatorProvider {

/**
* Creates a {@link TypeInfo}.
* Creates a {@link TypeInfo} that is appropriate for representing a type hierarchy appropriate for
* {@link io.helidon.builder.Builder} target creation.
*
* @param annoTypeName the annotation type name that triggered the creation
* @param annoTypeName the annotation type name that triggered the builder target creation
* @param typeName the type name that is being processed that is annotated with the triggering annotation
* @param element the element representative of the typeName
* @param element the element representative of the typeName that is being processed
* @param processingEnv the processing environment
* @param wantDefaultMethods true to accept {@code default} methods (normally this is passed as false)
* @return the type info associated with the arguments being processed, or empty if not able to process the type
*/
Optional<TypeInfo> createTypeInfo(TypeName annoTypeName,
TypeName typeName,
TypeElement element,
Optional<TypeInfo> createBuilderTypeInfo(TypeName annoTypeName,
TypeName typeName,
TypeElement element,
ProcessingEnvironment processingEnv,
boolean wantDefaultMethods);

/**
* Creates a {@link TypeInfo} that is broadly appropriate for general usage for any scenario.
*
* @param element the element that is being processed
* @param mirror the type mirror for the element being processed
* @param processingEnv the processing environment
* @param elementOfInterest the predicate filter to determine whether the element is of interest, and therefore should be
* included in {@link TypeInfo#elementInfo()}. Otherwise, if the predicate indicates it is not of
* interest then the method will be placed under {@link TypeInfo#otherElementInfo()} instead
* @return the type info associated with the arguments being processed, or empty if not able to process the type
*/
Optional<TypeInfo> createTypeInfo(TypeElement element,
TypeMirror mirror,
ProcessingEnvironment processingEnv,
boolean wantDefaultMethods);
Predicate<TypedElementName> elementOfInterest);

}
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ private static String searchForBuilderAnnotation(String key,

if (!builderTriggerAnnotation.typeName().equals(BUILDER_ANNO_TYPE_NAME)) {
AnnotationAndValue builderAnnotation = AnnotationAndValueDefault
.findFirst(BUILDER_ANNO_TYPE_NAME.name(), typeInfo.annotations()).orElse(null);
.findFirst(BUILDER_ANNO_TYPE_NAME, typeInfo.annotations()).orElse(null);
if (builderAnnotation != null) {
val = builderAnnotation.value(key).orElse(null);
}
Expand All @@ -576,7 +576,7 @@ private void gatherAllAttributeNames(TypeInfo typeInfo) {
TypeInfo superTypeInfo = typeInfo.superTypeInfo().orElse(null);
if (superTypeInfo != null) {
Optional<? extends AnnotationAndValue> superBuilderAnnotation = AnnotationAndValueDefault
.findFirst(builderTriggerAnnotation.typeName().name(), superTypeInfo.annotations());
.findFirst(builderTriggerAnnotation.typeName(), superTypeInfo.annotations());
if (superBuilderAnnotation.isEmpty()) {
gatherAllAttributeNames(superTypeInfo);
} else {
Expand Down Expand Up @@ -692,7 +692,7 @@ private static TypeName toParentTypeName(AnnotationAndValue builderTriggerAnnota
TypeInfo superTypeInfo = typeInfo.superTypeInfo().orElse(null);
if (superTypeInfo != null) {
Optional<? extends AnnotationAndValue> superBuilderAnnotation = AnnotationAndValueDefault
.findFirst(builderTriggerAnnotation.typeName().name(), superTypeInfo.annotations());
.findFirst(builderTriggerAnnotation.typeName(), superTypeInfo.annotations());
if (superBuilderAnnotation.isEmpty()) {
return toParentTypeName(builderTriggerAnnotation, superTypeInfo);
}
Expand Down
Loading

0 comments on commit 3b7fa02

Please sign in to comment.