Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeInfo and TypedElementName API name tuning #6841

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import io.helidon.common.types.TypeInfo;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypeNameDefault;
import io.helidon.common.types.TypedElementName;
import io.helidon.common.types.TypedElementInfo;
import io.helidon.config.metadata.ConfiguredOption;

import static io.helidon.builder.config.spi.ConfigBeanInfo.LevelType;
Expand Down Expand Up @@ -124,7 +124,7 @@ protected void preValidate(TypeName implTypeName,
* Generic/simple map types are not supported on config beans, only <String, <Known ConfigBean types>>.
*/
private void assertNoGenericMaps(TypeInfo typeInfo) {
List<TypedElementName> list = typeInfo.elementInfo().stream()
List<TypedElementInfo> list = typeInfo.interestingElementInfo().stream()
.filter(it -> it.typeName().isMap())
.filter(it -> {
TypeName typeName = it.typeName();
Expand Down Expand Up @@ -292,7 +292,7 @@ protected void appendExtraBuilderMethods(StringBuilder builder,

int i = 0;
for (String attrName : ctx.allAttributeNames()) {
TypedElementName method = ctx.allTypeInfos().get(i);
TypedElementInfo method = ctx.allTypeInfos().get(i);
String configKey = toConfigKey(attrName, method, ctx.builderTriggerAnnotation());

// resolver.of(config, "port", int.class).ifPresent(this::port);
Expand Down Expand Up @@ -449,7 +449,7 @@ private void javaDocAcceptResolveConfigCtx(StringBuilder builder,
}

private String toConfigKey(String attrName,
TypedElementName method,
TypedElementInfo method,
AnnotationAndValue ignoredBuilderAnnotation) {
String configKey = null;
Optional<? extends AnnotationAndValue> configuredOptions = AnnotationAndValueDefault
Expand All @@ -473,7 +473,7 @@ private static void assertNoAnnotation(String annoTypeName,
+ " on " + typeInfo.typeName());
}

for (TypedElementName elem : typeInfo.elementInfo()) {
for (TypedElementInfo elem : typeInfo.interestingElementInfo()) {
anno = AnnotationAndValueDefault.findFirst(annoTypeName, elem.annotations());
if (anno.isEmpty()) {
anno = AnnotationAndValueDefault.findFirst(annoTypeName, elem.elementTypeAnnotations());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import io.helidon.common.types.TypeInfoDefault;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypeNameDefault;
import io.helidon.common.types.TypedElementName;
import io.helidon.common.types.TypedElementNameDefault;
import io.helidon.common.types.TypedElementInfo;
import io.helidon.common.types.TypedElementInfoDefault;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -111,11 +111,11 @@ void preValidateConfigBeansMustBeRootToHaveDefaults() {

@Test
void preValidateConfigBeansMustNotHaveDuplicateSingularNames() {
TypedElementName method1 = TypedElementNameDefault.builder()
TypedElementInfo method1 = TypedElementInfoDefault.builder()
.elementName("socket")
.typeName(String.class)
.build();
TypedElementName method2 = TypedElementNameDefault.builder()
TypedElementInfo method2 = TypedElementInfoDefault.builder()
.elementName("socketSet")
.typeName(String.class)
.addAnnotation(AnnotationAndValueDefault.create(Singular.class, "socket"))
Expand All @@ -124,7 +124,7 @@ void preValidateConfigBeansMustNotHaveDuplicateSingularNames() {
TypeInfo typeInfo = TypeInfoDefault.builder()
.typeKind(TypeInfo.KIND_INTERFACE)
.typeName(TypeNameDefault.create(getClass()))
.elementInfo(Set.of(method1, method2))
.interestingElementInfo(Set.of(method1, method2))
.build();
AnnotationAndValueDefault configBeanAnno = AnnotationAndValueDefault.builder()
.typeName(TypeNameDefault.create(ConfigBean.class))
Expand All @@ -141,7 +141,7 @@ void preValidateConfigBeansMustNotHaveDuplicateSingularNames() {

@Test
void preValidateConfigBeansMustHaveMapTypesWithNestedConfigBeans() {
TypedElementName method1 = TypedElementNameDefault.builder()
TypedElementInfo method1 = TypedElementInfoDefault.builder()
.elementName("socket")
.typeName(TypeNameDefault.builder()
.type(Map.class)
Expand All @@ -154,7 +154,7 @@ void preValidateConfigBeansMustHaveMapTypesWithNestedConfigBeans() {
TypeInfo typeInfo = TypeInfoDefault.builder()
.typeKind(TypeInfo.KIND_INTERFACE)
.typeName(TypeNameDefault.create(getClass()))
.elementInfo(Set.of(method1))
.interestingElementInfo(Set.of(method1))
.build();
AnnotationAndValueDefault configBeanAnno = AnnotationAndValueDefault.builder()
.typeName(TypeNameDefault.create(ConfigBean.class))
Expand All @@ -172,7 +172,7 @@ void preValidateConfigBeansMustHaveMapTypesWithNestedConfigBeans() {
creator.preValidate(implTypeName, typeInfo, configBeanAnno);

// now we will validate the exceptions when ConfigBeans are attempted to be embedded
TypedElementName method2 = TypedElementNameDefault.builder()
TypedElementInfo method2 = TypedElementInfoDefault.builder()
.elementName("unsupported1")
.typeName(TypeNameDefault.builder()
.type(Map.class)
Expand All @@ -182,7 +182,7 @@ void preValidateConfigBeansMustHaveMapTypesWithNestedConfigBeans() {
TypeNameDefault.create(getClass())))
.build())
.build();
TypedElementName method3 = TypedElementNameDefault.builder()
TypedElementInfo method3 = TypedElementInfoDefault.builder()
.elementName("unsupported2")
.typeName(TypeNameDefault.builder()
.type(Map.class)
Expand All @@ -195,7 +195,7 @@ void preValidateConfigBeansMustHaveMapTypesWithNestedConfigBeans() {
TypeInfo typeInfo2 = TypeInfoDefault.builder()
.typeKind(TypeInfo.KIND_INTERFACE)
.typeName(TypeNameDefault.create(getClass()))
.elementInfo(List.of(method2, method3))
.interestingElementInfo(List.of(method2, method3))
.referencedTypeNamesToAnnotations(Map.of(TypeNameDefault.create(getClass()),
List.of(AnnotationAndValueDefault.create(Builder.class))))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

/**
* Java {@link java.util.ServiceLoader} provider interface used to discover type info creators.
Expand Down Expand Up @@ -58,13 +58,13 @@ Optional<TypeInfo> createBuilderTypeInfo(TypeName annoTypeName,
* @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
* included in {@link TypeInfo#interestingElementInfo()}. 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,
Predicate<TypedElementName> elementOfInterest);
Predicate<TypedElementInfo> elementOfInterest);

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import io.helidon.common.types.TypeInfo;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypeNameDefault;
import io.helidon.common.types.TypedElementName;
import io.helidon.common.types.TypedElementInfo;

import static io.helidon.builder.processor.tools.BeanUtils.isBooleanType;
import static io.helidon.builder.processor.tools.BeanUtils.isReservedWord;
Expand All @@ -54,8 +54,8 @@ public class BodyContext {
private final TypeName implTypeName;
private final TypeInfo typeInfo;
private final AnnotationAndValue builderTriggerAnnotation;
private final Map<String, TypedElementName> map = new LinkedHashMap<>();
private final List<TypedElementName> allTypeInfos = new ArrayList<>();
private final Map<String, TypedElementInfo> map = new LinkedHashMap<>();
private final List<TypedElementInfo> allTypeInfos = new ArrayList<>();
private final List<String> allAttributeNames = new ArrayList<>();
private final boolean hasStreamSupportOnImpl;
private final boolean hasStreamSupportOnBuilder;
Expand Down Expand Up @@ -180,7 +180,7 @@ public AnnotationAndValue builderTriggerAnnotation() {
*
* @return the map of elements by name
*/
protected Map<String, TypedElementName> map() {
protected Map<String, TypedElementInfo> map() {
return map;
}

Expand All @@ -189,7 +189,7 @@ protected Map<String, TypedElementName> map() {
*
* @return the list of type elements
*/
public List<TypedElementName> allTypeInfos() {
public List<TypedElementInfo> allTypeInfos() {
return allTypeInfos;
}

Expand Down Expand Up @@ -428,7 +428,7 @@ public Optional<String> interceptorCreateMethod() {
*/
public boolean hasOtherMethod(String name,
TypeInfo typeInfo) {
for (TypedElementName elem : typeInfo.otherElementInfo()) {
for (TypedElementInfo elem : typeInfo.otherElementInfo()) {
if (elem.elementName().equals(name)) {
return true;
}
Expand All @@ -448,7 +448,7 @@ public boolean hasOtherMethod(String name,
* @param isBeanStyleRequired is bean style required
* @return the bean attribute name
*/
protected static String toBeanAttributeName(TypedElementName method,
protected static String toBeanAttributeName(TypedElementInfo method,
boolean isBeanStyleRequired) {
AtomicReference<Optional<List<String>>> refAttrNames = new AtomicReference<>();
validateAndParseMethodName(method.elementName(), method.typeName().name(), isBeanStyleRequired, refAttrNames);
Expand Down Expand Up @@ -585,9 +585,9 @@ private void gatherAllAttributeNames(TypeInfo typeInfo) {
}
}

for (TypedElementName method : typeInfo.elementInfo()) {
for (TypedElementInfo method : typeInfo.interestingElementInfo()) {
String beanAttributeName = toBeanAttributeName(method, beanStyleRequired);
TypedElementName existing = map.get(beanAttributeName);
TypedElementInfo existing = map.get(beanAttributeName);
if (existing != null
&& isBooleanType(method.typeName().name())
&& method.elementName().startsWith("is")) {
Expand Down Expand Up @@ -630,16 +630,16 @@ && isBooleanType(method.typeName().name())
}
}

private static void populateMap(Map<String, TypedElementName> map,
private static void populateMap(Map<String, TypedElementInfo> map,
TypeInfo typeInfo,
boolean isBeanStyleRequired) {
if (typeInfo.superTypeInfo().isPresent()) {
populateMap(map, typeInfo.superTypeInfo().get(), isBeanStyleRequired);
}

for (TypedElementName method : typeInfo.elementInfo()) {
for (TypedElementInfo method : typeInfo.interestingElementInfo()) {
String beanAttributeName = toBeanAttributeName(method, isBeanStyleRequired);
TypedElementName existing = map.get(beanAttributeName);
TypedElementInfo existing = map.get(beanAttributeName);
if (existing != null) {
if (!existing.typeName().equals(method.typeName())) {
throw new IllegalStateException(method + " cannot redefine types from super for " + beanAttributeName);
Expand Down Expand Up @@ -684,7 +684,7 @@ private static TypeName toCtorBuilderAcceptTypeName(TypeInfo typeInfo,
return typeInfo.typeName();
}

return (parentAnnotationTypeName != null && typeInfo.elementInfo().isEmpty()
return (parentAnnotationTypeName != null && typeInfo.interestingElementInfo().isEmpty()
? typeInfo.superTypeInfo().orElseThrow().typeName() : typeInfo.typeName());
}

Expand Down
Loading