-
Notifications
You must be signed in to change notification settings - Fork 13
Add sub classing interfaces #372
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -56,6 +56,9 @@ class SpanSearchingFileVisitor extends AbstractSearchingFileVisitor { | |||||||
|
|
||||||||
| private final Collection<SpanEntry> spanEntries; | ||||||||
|
|
||||||||
| private final Collection<Class<?>> supportedInterfaces = new ArrayList<>( | ||||||||
| Arrays.asList(SpanDocumentation.class, ObservationDocumentation.class)); | ||||||||
|
Comment on lines
+59
to
+60
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this work?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not work, as Arrays.asList creates an immutable list, but I'm adding the found extending interfaces to the supportedInterfaces array. See AbstractSearchingFileVisitor.java#L81. But maybe there is a better way of doing this, which I didn't think of? |
||||||||
|
|
||||||||
| /** | ||||||||
| * The enclosing enum classes for overriding will be excluded from documentation | ||||||||
| */ | ||||||||
|
|
@@ -68,7 +71,7 @@ class SpanSearchingFileVisitor extends AbstractSearchingFileVisitor { | |||||||
|
|
||||||||
| @Override | ||||||||
| public Collection<Class<?>> supportedInterfaces() { | ||||||||
| return Arrays.asList(SpanDocumentation.class, ObservationDocumentation.class); | ||||||||
| return supportedInterfaces; | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * Copyright 2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.docs.metrics.test2; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| // Added any interface (Serializable) to test if the parser really goes through all extending interfaces | ||
| public interface ExtendExtendedMeterDoc extends Serializable, ExtendMeterDocumentation { | ||
|
|
||
| String secondDescription(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * Copyright 2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.docs.metrics.test2; | ||
|
|
||
| import io.micrometer.core.instrument.Meter; | ||
|
|
||
| public enum ExtendExtendedMyMetrics implements ExtendExtendedMeterDoc { | ||
|
|
||
| /** | ||
| * Test metric which extends the extended MeterDocumentation interface. | ||
| */ | ||
| EXTEND_EXTENDED_FOO { | ||
| @Override | ||
| public String secondDescription() { | ||
| return "This comes from ExtendedExtendMeterDoc interface"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return "This comes from ExtendMeterDocumentation interface"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "extend.extended.foo"; | ||
| } | ||
|
|
||
| @Override | ||
| public Meter.Type getType() { | ||
| return Meter.Type.COUNTER; | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Copyright 2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.docs.metrics.test2; | ||
|
|
||
| import io.micrometer.core.instrument.docs.MeterDocumentation; | ||
|
|
||
| public interface ExtendMeterDocumentation extends MeterDocumentation { | ||
|
|
||
| /** | ||
| * Returns the description (also known as {@code help} in some systems) for the given | ||
| * meter. | ||
| */ | ||
| String getDescription(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * Copyright 2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.docs.metrics.test2; | ||
|
|
||
| import io.micrometer.core.instrument.Meter; | ||
|
|
||
| public enum ExtendedMyMetrics implements ExtendMeterDocumentation { | ||
|
|
||
| /** | ||
| * Test metric which extends the MeterDocumentation interface | ||
| */ | ||
| FOO { | ||
| @Override | ||
| public String getDescription() { | ||
| return "foo metric"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "extended.foo"; | ||
| } | ||
|
|
||
| @Override | ||
| public Meter.Type getType() { | ||
| return Meter.Type.COUNTER; | ||
| } | ||
| }; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * Copyright 2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.docs.metrics.test2; | ||
|
|
||
| import io.micrometer.docs.metrics.MetricsDocGenerator; | ||
| import org.assertj.core.api.BDDAssertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| class MetricSearchingFileVisitorTest { | ||
|
|
||
| @Test | ||
| void should_render_metrics_from_sub_class_interfaces() throws IOException { | ||
| Path output = Paths.get(".", "build", "_metrics.adoc"); | ||
|
|
||
| File sourceRoot = new File(".", "src/test"); | ||
| new MetricsDocGenerator(sourceRoot, Pattern.compile(".*/docs/metrics/test2/[a-zA-Z]+\\.java"), | ||
| "templates/metrics.adoc.hbs", output) | ||
| .generate(); | ||
|
|
||
| BDDAssertions.then(new String(Files.readAllBytes(output))) | ||
| .contains("**Metric name** `extended.foo`. **Type** `counter`") | ||
| .contains("**Metric name** `extend.extended.foo`. **Type** `counter`"); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * Copyright 2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.docs.spans.test7; | ||
|
|
||
| public enum ExtendExtendedMySpan implements ExtendExtendedSpanDocumentation { | ||
|
|
||
| /** | ||
| * Test span for sub-classing documentation interfaces | ||
| */ | ||
| EXTEND_EXTENDED_FOO { | ||
| @Override | ||
| public String secondDescription() { | ||
| return "This comes from ExtendExtendedSpanDocumentation"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return "This comes from ExtendSpanDocumentation"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "extend extended foo"; | ||
| } | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work, as Arrays.asList creates an immutable list, but I'm adding the found extending interfaces to the supportedInterfaces array. See AbstractSearchingFileVisitor.java#L81.
But maybe there is a better way of doing this, which I didn't think of?