-
Notifications
You must be signed in to change notification settings - Fork 642
Migrate away from enums #6340
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
Merged
Merged
Migrate away from enums #6340
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
52f7387
Update Candidate.kt
daymxn 31e230d
Update HarmBlockMethod.kt
daymxn 7ffef1b
Update HarmBlockThreshold.kt
daymxn 5b42d8c
Update HarmCategory.kt
daymxn 301b737
Update HarmProbability.kt
daymxn 2bb344f
Update HarmSeverity.kt
daymxn b6e7e65
Update PromptFeedback.kt
daymxn 730f8a5
Update CHANGELOG.md
daymxn a529e9d
Update CHANGELOG.md
daymxn 1d6467f
Merge branch 'main' into daymon-migrate-away-from-enums
rlazo 40f0069
Add names where we need them
daymxn b175e7c
Throw whenever an enum is missing a case
daymxn e83ef0d
Create EnumUpdateTests.kt
daymxn 8899618
Merge branch 'daymon-migrate-away-from-enums' of https://github.com/f…
daymxn 4d219c8
formatting
daymxn a23be23
Add missing license
daymxn 13e1285
Merge branch 'main' into daymon-migrate-away-from-enums
daymxn 20e1653
Add context to exception message in case of developer leakage
daymxn ad5566c
Merge branch 'main' into daymon-migrate-away-from-enums
daymxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Unreleased | ||
* [changed] Breaking Change: refactored enum classes to be normal classes (#6340). | ||
|
||
|
||
# 16.0.0-beta05 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
firebase-vertexai/src/test/java/com/google/firebase/vertexai/common/EnumUpdateTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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 | ||
* | ||
* http://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 com.google.firebase.vertexai.common | ||
|
||
import com.google.firebase.vertexai.internal.util.toInternal | ||
import com.google.firebase.vertexai.type.HarmBlockMethod | ||
import com.google.firebase.vertexai.type.HarmBlockThreshold | ||
import com.google.firebase.vertexai.type.HarmCategory | ||
import org.junit.Test | ||
|
||
/** | ||
* Fetches all the `@JvmStatic` properties of a class that are instances of the class itself. | ||
* | ||
* For example, given the following class: | ||
* ```kt | ||
* public class HarmCategory private constructor(public val ordinal: Int) { | ||
* public companion object { | ||
* @JvmField public val UNKNOWN: HarmCategory = HarmCategory(0) | ||
* @JvmField public val HARASSMENT: HarmCategory = HarmCategory(1) | ||
* } | ||
* } | ||
* ``` | ||
* This function will yield: | ||
* ```kt | ||
* [UNKNOWN, HARASSMENT] | ||
* ``` | ||
*/ | ||
internal inline fun <reified T : Any> getEnumValues(): List<T> { | ||
return T::class | ||
.java | ||
.declaredFields | ||
.filter { it.type == T::class.java } | ||
.mapNotNull { it.get(null) as? T } | ||
} | ||
|
||
/** | ||
* Ensures that whenever any of our "pseudo-enums" are updated, that the conversion layer is also | ||
* updated. | ||
*/ | ||
internal class EnumUpdateTests { | ||
@Test | ||
fun `HarmCategory#toInternal() covers all values`() { | ||
val values = getEnumValues<HarmCategory>() | ||
values.forEach { it.toInternal() } | ||
} | ||
|
||
@Test | ||
fun `HarmBlockMethod#toInternal() covers all values`() { | ||
val values = getEnumValues<HarmBlockMethod>() | ||
values.forEach { it.toInternal() } | ||
} | ||
|
||
@Test | ||
fun `HarmBlockThreshold#toInternal() covers all values`() { | ||
val values = getEnumValues<HarmBlockThreshold>() | ||
values.forEach { it.toInternal() } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.