-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Highlight enums with String values correctly #1488
Highlight enums with String values correctly #1488
Conversation
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.
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @aaronweissler)
components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/yamlhighlighter/HighlightRulesMapController.java
line 170 at r1 (raw file):
private List<String> extractEnumValues(Class<?> currentEnum) { List<String> allFields = Arrays.stream(currentEnum.getDeclaredFields()).map(Field::getName).collect(Collectors.toList()); if (allFields.contains("values")){
The field values
is specific to the TransportProtocol
.
In case of the TransportProtocol
it would also be sufficient to just map to the toString
method instead of the getName
.
Assuming that the other Enums do not override the toString
method to express something different, we can use
private List<String> extractEnumValues(Class<?> currentEnum) {
return Arrays.stream(currentEnum.getEnumConstants()).map(Object::toString).collect(Collectors.toList());
}
``
(in order to make the test pass, the order of the expected values for `TransportProtocol` need to be adjusted in `HighlightRulesMapControllerIntTest`
Alternatively, we can also add the edge case of the `TransportProcotol` directly into the `extractEnumValues` method:
private List extractEnumValues(Class currentEnum) {
Class> clazz = (Class>) currentEnum;
if (currentEnum.equals(TransportProtocol.class)) {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::toString).collect(Collectors.toList());
} else {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::name).collect(Collectors.toList());
}
}
Codecov Report
@@ Coverage Diff @@
## master #1488 +/- ##
============================================
+ Coverage 79.26% 79.27% +0.01%
Complexity 2254 2254
============================================
Files 231 230 -1
Lines 7305 7304 -1
Branches 867 867
============================================
Hits 5790 5790
+ Misses 1157 1156 -1
Partials 358 358 |
Using toString, empty values could not be parsed correctly by gson
4e8e78a
to
80490dd
Compare
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.
Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @heiko-holz)
components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/yamlhighlighter/HighlightRulesMapController.java
line 170 at r1 (raw file):
Previously, heiko-holz (Heiko Holz) wrote…
The field
values
is specific to theTransportProtocol
.In case of the
TransportProtocol
it would also be sufficient to just map to thetoString
method instead of thegetName
.Assuming that the other Enums do not override the
toString
method to express something different, we can useprivate List<String> extractEnumValues(Class<?> currentEnum) { return Arrays.stream(currentEnum.getEnumConstants()).map(Object::toString).collect(Collectors.toList()); } `` (in order to make the test pass, the order of the expected values for `TransportProtocol` need to be adjusted in `HighlightRulesMapControllerIntTest` Alternatively, we can also add the edge case of the `TransportProcotol` directly into the `extractEnumValues` method:
private List extractEnumValues(Class currentEnum) { Class> clazz = (Class>) currentEnum;
if (currentEnum.equals(TransportProtocol.class)) {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::toString).collect(Collectors.toList());
} else {
return Arrays.stream(clazz.getEnumConstants()).map(Enum::name).collect(Collectors.toList());
}
}
Yes, exactly this problem/limitation I would have mentioned when turning it from draft to reviewable, that right now it assumes that any other Enums using this functionality would also save their values in a values
field.
Simply using toString seems like a really good idea to me though, since it should be correct for any Enums used in this context, since the values for configurations are also defined as Strings.
And I like it more than defining an exception specifically for TransportProtocol, since it would just work for new Enums working the same way without additional code changes.
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.
Reviewed 1 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @aaronweissler)
components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/rest/yamlhighlighter/HighlightRulesMapController.java
line 170 at r1 (raw file):
Previously, aaronweissler wrote…
Yes, exactly this problem/limitation I would have mentioned when turning it from draft to reviewable, that right now it assumes that any other Enums using this functionality would also save their values in a
values
field.Simply using toString seems like a really good idea to me though, since it should be correct for any Enums used in this context, since the values for configurations are also defined as Strings.
And I like it more than defining an exception specifically for TransportProtocol, since it would just work for new Enums working the same way without additional code changes.
Yep, I also like the implementation with toString
versions(inspectIT#1507) Highlight enums with String values correctly (inspectIT#1488) * Treat enums with values-field differently * Fix default config exporters.yml * Fix order of possible values in test * Use toString instead of getName * Fix JSON parsing of Maps in test Using toString, empty values could not be parsed correctly by gson update patches update minor versions update eslint dependencies update @babel/core dependency re-update eslint update primeinons update primeflex update react-timeago update react-syntax-highligter update react-redux
versions(#1507) Highlight enums with String values correctly (#1488) * Treat enums with values-field differently * Fix default config exporters.yml * Fix order of possible values in test * Use toString instead of getName * Fix JSON parsing of Maps in test Using toString, empty values could not be parsed correctly by gson update patches update minor versions update eslint dependencies update @babel/core dependency re-update eslint update primeinons update primeflex update react-timeago update react-syntax-highligter update react-redux
… of Config Server UI dependencies (#1510) * update patches * update minor versions * update eslint dependencies * update @babel/core dependency * re-update eslint * update primeinons * update primeflex * update react-timeago * update react-syntax-highligter * update react-redux * update jwt-decode * Merge branch 'master' of https://github.com/inspectIT/inspectit-ocelot into dependencies-update * Closes #1507 : Update minor versions, patches and some major versions(#1507) Highlight enums with String values correctly (#1488) * Treat enums with values-field differently * Fix default config exporters.yml * Fix order of possible values in test * Use toString instead of getName * Fix JSON parsing of Maps in test Using toString, empty values could not be parsed correctly by gson update patches update minor versions update eslint dependencies update @babel/core dependency re-update eslint update primeinons update primeflex update react-timeago update react-syntax-highligter update react-redux * update jwt-decode * Add settings and info for developing UI in IntelliJ (#1496) * Activate formatter tags by default * Add indentation settings for JS * Add to CONTRIBUTING regarding JavaScript linting * Fix eol linting of .js files on Windows * Add yarn lint and format:write to README * Add section in CONTRIBUTING.md * Add to CONTRIBUTING based on comments * Fix linting command in README Co-authored-by: Heiko Holz <heiko.holz@novatec-gmbh.de> * [skip ci] Publish documentation v2.1.0 * Fix release notes links (#1503) * Closes #1507 - Update minor versions, patches and some major versions * Closes #1507 - Update minor versions, patches and some major versions * Delete package-lock.json Only one lock-file should be in project, which is yarn.lock in our case. * Small fix to next.config * Fix license string * Change parser to babel/eslint-parser * Add peer dependencies * Merge branch 'master' into dependencies-update * Fix linting errors * Move babel eslint to devdependencies, remove old version * Add helper-string-parser to devdependencies
Closes #1436
This change is