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

support lowercase for modifiers names #6844

Merged
merged 3 commits 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 @@ -138,7 +138,7 @@ public static boolean validateAndParseMethodName(String methodName,
* @return true if it appears to be a reserved word
*/
public static boolean isReservedWord(String word) {
return RESERVED.get().contains(word.toUpperCase());
return RESERVED.get().stream().anyMatch(word::equalsIgnoreCase);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ public class BodyContext {
searchForBuilderAnnotation("interceptorCreateMethod", builderTriggerAnnotation, typeInfo);
this.interceptorCreateMethod = (interceptorCreateMethod == null || interceptorCreateMethod.isEmpty())
? null : interceptorCreateMethod;
this.publicOrPackagePrivateDecl = (typeInfo.typeKind().equals(TypeInfo.KIND_INTERFACE)
|| typeInfo.modifierNames().isEmpty()
|| typeInfo.modifierNames().contains(TypeInfo.MODIFIER_PUBLIC))
? "public " : "";
this.publicOrPackagePrivateDecl = (
typeInfo.typeKind().equals(TypeInfo.KIND_INTERFACE)
|| typeInfo.modifierNames().isEmpty()
|| typeInfo.modifierNames().stream().anyMatch(TypeInfo.MODIFIER_PUBLIC::equalsIgnoreCase))
? "public " : "";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ public Optional<TypeInfo> createBuilderTypeInfo(TypeName annotationTypeName,

Collection<TypedElementName> elementInfo = toElementInfo(element, processingEnv, true, wantDefaultMethods);
Collection<TypedElementName> otherElementInfo = toElementInfo(element, processingEnv, false, wantDefaultMethods);
Set<String> modifierNames = toModifierNames(element.getModifiers()).stream()
.map(String::toUpperCase)
.collect(Collectors.toSet());
Set<String> modifierNames = toModifierNames(element.getModifiers());
return Optional.of(TypeInfoDefault.builder()
.typeName(typeName)
.typeKind(String.valueOf(element.getKind()))
Expand Down
16 changes: 8 additions & 8 deletions common/types/src/main/java/io/helidon/common/types/TypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ public interface TypeInfo {
/**
* The {@code public} modifier.
*/
String MODIFIER_PUBLIC = "PUBLIC";
String MODIFIER_PUBLIC = "public";
/**
* The {@code protected} modifier.
*/
String MODIFIER_PROTECTED = "PROTECTED";
String MODIFIER_PROTECTED = "protected";
/**
* The {@code private} modifier.
*/
String MODIFIER_PRIVATE = "PRIVATE";
String MODIFIER_PRIVATE = "private";
/**
* The {@code abstract} modifier.
*/
String MODIFIER_ABSTRACT = "ABSTRACT";
String MODIFIER_ABSTRACT = "abstract";
/**
* The {@code default} modifier.
*/
String MODIFIER_DEFAULT = "DEFAULT";
String MODIFIER_DEFAULT = "default";
/**
* The {@code static} modifier.
*/
String MODIFIER_STATIC = "STATIC";
String MODIFIER_STATIC = "static";
/**
* The {@code sealed} modifier.
*/
String MODIFIER_SEALED = "SEALED";
String MODIFIER_SEALED = "sealed";
/**
* The {@code final} modifier.
*/
String MODIFIER_FINAL = "FINAL";
String MODIFIER_FINAL = "final";


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,30 @@ protected void doFiler(ServicesToProcess services) {
* @param elementsOfInterest the elements that are eligible for some form of Pico processing
*/
protected void validate(Collection<TypedElementName> elementsOfInterest) {
validatePerClass(elementsOfInterest,
"There can be max of one injectable constructor per class",
1,
(it) -> it.elementTypeKind().equals(TypeInfo.KIND_CONSTRUCTOR)
&& GeneralProcessorUtils.findFirst(Inject.class, it.annotations()).isPresent());
validatePerClass(elementsOfInterest,
"There can be max of one PostConstruct method per class",
1,
(it) -> it.elementTypeKind().equals(TypeInfo.KIND_METHOD)
&& GeneralProcessorUtils.findFirst(PostConstruct.class, it.annotations()).isPresent());
validatePerClass(elementsOfInterest,
"There can be max of one PreDestroy method per class",
1,
(it) -> it.elementTypeKind().equals(TypeInfo.KIND_METHOD)
&& GeneralProcessorUtils.findFirst(PreDestroy.class, it.annotations()).isPresent());
validatePerClass(elementsOfInterest,
PicoServicesConfig.NAME + " does not currently support static or private elements",
0,
(it) -> toModifierNames(it.modifierNames()).contains(TypeInfo.MODIFIER_PRIVATE)
|| toModifierNames(it.modifierNames()).contains(TypeInfo.MODIFIER_STATIC));
validatePerClass(
elementsOfInterest,
"There can be max of one injectable constructor per class",
1,
(it) -> it.elementTypeKind().equals(TypeInfo.KIND_CONSTRUCTOR)
&& GeneralProcessorUtils.findFirst(Inject.class, it.annotations()).isPresent());
validatePerClass(
elementsOfInterest,
"There can be max of one PostConstruct method per class",
1,
(it) -> it.elementTypeKind().equals(TypeInfo.KIND_METHOD)
&& GeneralProcessorUtils.findFirst(PostConstruct.class, it.annotations()).isPresent());
validatePerClass(
elementsOfInterest,
"There can be max of one PreDestroy method per class",
1,
(it) -> it.elementTypeKind().equals(TypeInfo.KIND_METHOD)
&& GeneralProcessorUtils.findFirst(PreDestroy.class, it.annotations()).isPresent());
validatePerClass(
elementsOfInterest,
PicoServicesConfig.NAME + " does not currently support static or private elements",
0,
(it) -> toModifierNames(it.modifierNames()).stream().anyMatch(TypeInfo.MODIFIER_PRIVATE::equalsIgnoreCase)
|| toModifierNames(it.modifierNames()).stream().anyMatch(TypeInfo.MODIFIER_STATIC::equalsIgnoreCase));
}

private void validatePerClass(Collection<TypedElementName> elementsOfInterest,
Expand Down Expand Up @@ -369,7 +373,7 @@ protected void processBasics(ServicesToProcess services,
services.addAccessLevel(serviceTypeName,
toAccess(modifierNames));
services.addIsAbstract(serviceTypeName,
modifierNames.contains(TypeInfo.MODIFIER_ABSTRACT));
modifierNames.stream().anyMatch(TypeInfo.MODIFIER_ABSTRACT::equalsIgnoreCase));
services.addServiceTypeHierarchy(serviceTypeName,
toServiceTypeHierarchy(service));
services.addQualifiers(serviceTypeName,
Expand Down
6 changes: 3 additions & 3 deletions pico/tools/src/main/java/io/helidon/pico/tools/TypeTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -1472,11 +1472,11 @@ static InjectionPointInfo.Access toAccess(int modifiers) {
* @return the access
*/
public static ElementInfo.Access toAccess(Set<String> modifiers) {
if (modifiers.contains(TypeInfo.MODIFIER_PROTECTED)) {
if (modifiers.stream().anyMatch(TypeInfo.MODIFIER_PROTECTED::equalsIgnoreCase)) {
return ElementInfo.Access.PROTECTED;
} else if (modifiers.contains(TypeInfo.MODIFIER_PRIVATE)) {
} else if (modifiers.stream().anyMatch(TypeInfo.MODIFIER_PRIVATE::equalsIgnoreCase)) {
return ElementInfo.Access.PRIVATE;
} else if (modifiers.contains(TypeInfo.MODIFIER_PUBLIC)) {
} else if (modifiers.stream().anyMatch(TypeInfo.MODIFIER_PUBLIC::equalsIgnoreCase)) {
return ElementInfo.Access.PUBLIC;
}
return ElementInfo.Access.PACKAGE_PRIVATE;
Expand Down