Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -20,8 +20,6 @@
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.micrometer.common.docs.KeyName;
import io.micrometer.common.lang.Nullable;
Expand All @@ -42,6 +40,9 @@

public class ParsingUtils {

private ParsingUtils() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anyone should have created an instance for this but strictly, this is a breaking change. I think we should fix this but maybe in another PR so we can call it out in the release notes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean who would ever want to instantiate this. I think that most IDEs suggest doing the private constructor. We can of course ignore this for the next minor and just not add this constructor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is probably ok to break this in a minor version. I would just do it in a separate PR so it is easier to call out in the release notes and separate it from an enhancement PR.

Copy link
Contributor Author

@fynnjuranek fynnjuranek Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. This is resolved with commit: d879fba7.

Do you want me to open a PR for the private Constructor?

}

private static final InternalLogger logger = InternalLoggerFactory.getInstance(ParsingUtils.class);

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -102,14 +103,30 @@ public static Set<String> readEnumClassNames(MethodSource<?> methodSource) {
MethodInvocation methodInvocation = (MethodInvocation) expression;

if ("merge".equals(methodInvocation.getName().getIdentifier())) {
// TODO: There must be a better way to do this...
// KeyName.merge(TestSpanTags.values(),AsyncSpanTags.values())
String invocationString = methodInvocation.toString();
Matcher matcher = Pattern.compile("([a-zA-Z]+.values)").matcher(invocationString);
Set<String> classNames = new TreeSet<>();
while (matcher.find()) {
String className = matcher.group(1).split("\\.")[0];
classNames.add(className);

// Traverse arguments of the "merge" method
for (Object argument : methodInvocation.arguments()) {
if (argument instanceof MethodInvocation) {
MethodInvocation argInvocation = (MethodInvocation) argument;

// Ensure the method is ".values()" and extract its scope
if ("values".equals(argInvocation.getName().getIdentifier())
&& argInvocation.getExpression() != null) {
Expression scope = argInvocation.getExpression();

// If KeyName is nested, extract only the corresponding class name
if (scope instanceof QualifiedName) {
String qualifiedName = scope.toString();
String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1);
classNames.add(className);
}
else {
classNames.add(scope.toString());
}
}
}
}
return classNames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Set;

import io.micrometer.common.docs.KeyName;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.docs.MeterDocumentation;
import io.micrometer.docs.RoasterTestUtils;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.jboss.forge.roaster.model.source.MethodSource;
Expand Down Expand Up @@ -49,6 +51,14 @@ void readMergeEnumClassName() {
assertThat(result).containsExactlyInAnyOrder("FooKeyName", "BarKeyName", "BazKeyName");
}

@Test
void readNestedEnumClassName() {
JavaClassSource javaSource = RoasterTestUtils.readJavaClass(ParsingUtilsReadEnumClassNamesTests.class);
MethodSource<?> methodSource = ((JavaClassSource) javaSource.getNestedType("MyClass")).getMethod("mergeNested");
Set<String> result = ParsingUtils.readEnumClassNames(methodSource);
assertThat(result).containsExactlyInAnyOrder("NestedFooKeyName", "NestedBarKeyName");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?
I'm questioning every nested class in this test.

Since the class is nested, it's name is not NestedFooKeyName but ParsingUtilsReadEnumClassNamesTests$FooMeterDocumentation$NestedFooKeyName or ParsingUtilsReadEnumClassNamesTests.FooMeterDocumentation.NestedFooKeyName depending on the context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently correct, as I add only the last part of the nested KeyNames, which happens here: ParsingUtils.java#L119. But I could just get rid of the substringing and add the whole class name, which would probably lead to a clearer description of where the nested KeyName is coming from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this now with commit: 213d0386. But this still does not take ParsingUtilsReadEnumClassNamesTests into place as we provide only the the nested type "MyClass" as the methodsource which does not contain ParsingUtilsReadEnumClassNamesTests. Because of these two lines: ParsingUtilsReadEnumClassNamesTests.java#L57-L58, I could change this to include the "root" source which would probably need a different jboss method.
Do you want me to change that?

}

static class MyClass {

Enum<?>[] simple() {
Expand All @@ -59,6 +69,11 @@ KeyName[] merge() {
return KeyName.merge(FooKeyName.values(), BarKeyName.values(), BazKeyName.values());
}

KeyName[] mergeNested() {
return KeyName.merge(FooMeterDocumentation.NestedFooKeyName.values(),
FooMeterDocumentation.NestedBarKeyName.values());
}

}

enum FooKeyName implements KeyName {
Expand Down Expand Up @@ -94,4 +109,42 @@ public String asString() {

}

enum FooMeterDocumentation implements MeterDocumentation {

FOO {
@Override
public String getName() {
return "foo";
}

@Override
public Meter.Type getType() {
return Meter.Type.COUNTER;
}
};

enum NestedFooKeyName implements KeyName {

NESTED_FOO {
@Override
public String asString() {
return "nested.foo";
}
}

}

enum NestedBarKeyName implements KeyName {

NESTED_BAR {
@Override
public String asString() {
return "nested.bar";
}
}

}

}

}