-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling enum values in a consistent way in code generation. (#9167)
Handling type values in a consistent way in code generation.
- Loading branch information
1 parent
d8fc80c
commit 6665d7c
Showing
7 changed files
with
223 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
60 changes: 60 additions & 0 deletions
60
builder/tests/common-types/src/main/java/io/helidon/common/types/EnumValue.java
This file contains 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,60 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* 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 io.helidon.common.types; | ||
|
||
/** | ||
* When creating an {@link io.helidon.common.types.Annotation}, we may need to create an enum value | ||
* without access to the enumeration. | ||
* <p> | ||
* In such a case, you can use this type when calling {@link io.helidon.common.types.Annotation.Builder#putValue(String, Object)} | ||
*/ | ||
public interface EnumValue { | ||
/** | ||
* Create a new enum value, when the enum is not available on classpath. | ||
* | ||
* @param enumType type of the enumeration | ||
* @param enumName value of the enumeration | ||
* @return enum value | ||
*/ | ||
static EnumValue create(TypeName enumType, String enumName) { | ||
return new EnumValue() { | ||
@Override | ||
public TypeName type() { | ||
return enumType; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return enumName; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Type of the enumeration. | ||
* | ||
* @return type name of the enumeration | ||
*/ | ||
TypeName type(); | ||
|
||
/** | ||
* The enum value. | ||
* | ||
* @return enum value | ||
*/ | ||
String name(); | ||
} |
This file contains 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 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 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 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
60 changes: 60 additions & 0 deletions
60
common/types/src/main/java/io/helidon/common/types/EnumValue.java
This file contains 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,60 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* 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 io.helidon.common.types; | ||
|
||
/** | ||
* When creating an {@link io.helidon.common.types.Annotation}, we may need to create an enum value | ||
* without access to the enumeration. | ||
* <p> | ||
* In such a case, you can use this type when calling {@link io.helidon.common.types.Annotation.Builder#putValue(String, Object)} | ||
*/ | ||
public interface EnumValue { | ||
/** | ||
* Create a new enum value, when the enum is not available on classpath. | ||
* | ||
* @param enumType type of the enumeration | ||
* @param enumName value of the enumeration | ||
* @return enum value | ||
*/ | ||
static EnumValue create(TypeName enumType, String enumName) { | ||
return new EnumValue() { | ||
@Override | ||
public TypeName type() { | ||
return enumType; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return enumName; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Type of the enumeration. | ||
* | ||
* @return type name of the enumeration | ||
*/ | ||
TypeName type(); | ||
|
||
/** | ||
* The enum value. | ||
* | ||
* @return enum value | ||
*/ | ||
String name(); | ||
} |