Skip to content

Commit

Permalink
Merge pull request quarkusio#42930 from gsmet/avoid-annotation-in-pri…
Browse files Browse the repository at this point in the history
…mitive-type-names

Config Doc - Avoid annotations in primitive type name
  • Loading branch information
gsmet authored Sep 1, 2024
2 parents 2642c0b + 01ea052 commit 2c1cdd9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public final String toString() {
return unwrappedType.toString();
}

public static ResolvedType ofPrimitive(TypeMirror unwrappedType) {
String primitiveName = unwrappedType.toString();

return new ResolvedType(unwrappedType, unwrappedType, primitiveName, primitiveName, primitiveName, true, false, false,
public static ResolvedType ofPrimitive(TypeMirror unwrappedType, String typeName) {
return new ResolvedType(unwrappedType, unwrappedType, typeName, typeName, typeName, true, false, false,
false, false, false, false, false, false, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> e
if (discoveryConfigProperty.getType().isMap()) {
// it is a leaf pass through map, it is always optional
optional = true;
typeQualifiedName = discoveryConfigProperty.getType().wrapperType().toString();
typeQualifiedName = utils.element().getQualifiedName(discoveryConfigProperty.getType().wrapperType());
typeSimplifiedName = utils.element().simplifyGenericType(discoveryConfigProperty.getType().wrapperType());

potentiallyMappedPath += ConfigNamingUtil.getMapKey(discoveryConfigProperty.getMapKey());
additionalPaths = additionalPaths.stream()
.map(p -> p + ConfigNamingUtil.getMapKey(discoveryConfigProperty.getMapKey()))
.collect(Collectors.toCollection(ArrayList::new));
} else if (discoveryConfigProperty.getType().isList()) {
typeQualifiedName = discoveryConfigProperty.getType().wrapperType().toString();
typeQualifiedName = utils.element().getQualifiedName(discoveryConfigProperty.getType().wrapperType());
}

PropertyPath propertyPath = new PropertyPath(potentiallyMappedPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ private void scanElement(List<ConfigAnnotationListener> listeners, DiscoveryRoot
}
} else {
TypeMirror superclass = clazz.getSuperclass();
if (superclass.getKind() != TypeKind.NONE && !superclass.toString().equals(Object.class.getName())) {
if (superclass.getKind() != TypeKind.NONE
&& !utils.element().getQualifiedName(superclass).equals(Object.class.getName())) {
TypeElement superclassTypeElement = (TypeElement) ((DeclaredType) superclass).asElement();

debug("Detected superclass: " + superclassTypeElement, clazz);
Expand Down Expand Up @@ -324,7 +325,7 @@ private boolean isEnumAlreadyHandled(TypeElement clazz) {

private ResolvedType resolveType(TypeMirror typeMirror) {
if (typeMirror.getKind().isPrimitive()) {
return ResolvedType.ofPrimitive(typeMirror);
return ResolvedType.ofPrimitive(typeMirror, utils.element().getQualifiedName(typeMirror));
}
if (typeMirror.getKind() == TypeKind.ARRAY) {
ResolvedType resolvedType = resolveType(((ArrayType) typeMirror).getComponentType());
Expand Down Expand Up @@ -369,7 +370,7 @@ private ResolvedType resolveType(TypeMirror typeMirror) {
isConfigGroup = utils.element().isAnnotationPresent(typeElement, Types.ANNOTATION_CONFIG_GROUP);
} else if (typeElement.getKind() == ElementKind.CLASS) {
isClass = true;
isDuration = typeMirror.toString().equals(Duration.class.getName());
isDuration = utils.element().getQualifiedName(typeMirror).equals(Duration.class.getName());
isConfigGroup = utils.element().isAnnotationPresent(typeElement, Types.ANNOTATION_CONFIG_GROUP);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {
AnnotationMirror configDocFileNameAnnotation = null;

for (AnnotationMirror annotationMirror : configRoot.getAnnotationMirrors()) {
String annotationName = annotationMirror.getAnnotationType().toString();
String annotationName = utils.element().getQualifiedName(annotationMirror.getAnnotationType());

if (annotationName.equals(Types.ANNOTATION_CONFIG_ROOT)) {
configRootAnnotation = annotationMirror;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {
AnnotationMirror configDocFileNameAnnotation = null;

for (AnnotationMirror annotationMirror : configRoot.getAnnotationMirrors()) {
String annotationName = annotationMirror.getAnnotationType().toString();
String annotationName = utils.element().getQualifiedName(annotationMirror.getAnnotationType());

if (annotationName.equals(Types.ANNOTATION_CONFIG_ROOT)) {
configRootAnnotation = annotationMirror;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public final class JavadocUtil {

static final String VERTX_JAVA_DOC_SITE = "https://vertx.io/docs/apidocs/";
static final String OFFICIAL_JAVA_DOC_BASE_LINK = "https://docs.oracle.com/en/java/javase/17/docs/api/";
static final String OFFICIAL_JAVA_DOC_BASE_LINK = "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/";
static final String AGROAL_API_JAVA_DOC_SITE = "https://javadoc.io/doc/io.agroal/agroal-api/latest/";
static final String LOG_LEVEL_REDIRECT_URL = "https://javadoc.io/doc/org.jboss.logmanager/jboss-logmanager/latest/org/jboss/logmanager/Level.html";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ public class ElementUtil {
this.processingEnv = processingEnv;
}

public String getQualifiedName(TypeMirror type) {
switch (type.getKind()) {
case BOOLEAN:
return "boolean";
case BYTE:
return "byte";
case CHAR:
return "char";
case DOUBLE:
return "double";
case FLOAT:
return "float";
case INT:
return "int";
case LONG:
return "long";
case SHORT:
return "short";
case DECLARED:
return ((TypeElement) ((DeclaredType) type).asElement()).getQualifiedName().toString();
default:
// note that it includes annotations, which is something we don't want
// thus why all this additional work above...
// this default should never be triggered AFAIK, it's there to be extra safe
return type.toString();
}
}

public String getBinaryName(TypeElement clazz) {
return processingEnv.getElementUtils().getBinaryName(clazz).toString();
}
Expand Down

0 comments on commit 2c1cdd9

Please sign in to comment.