-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'quiltmc-master' into alias
# Conflicts: # serializers-json5/src/main/java/org/quiltmc/config/api/serializers/Json5Serializer.java
- Loading branch information
Showing
17 changed files
with
609 additions
and
6 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
72 changes: 72 additions & 0 deletions
72
src/main/java/org/quiltmc/config/api/annotations/SerializedNameConvention.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,72 @@ | ||
/* | ||
* Copyright 2024 QuiltMC | ||
* | ||
* 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 org.quiltmc.config.api.annotations; | ||
|
||
import org.quiltmc.config.api.Config; | ||
import org.quiltmc.config.api.metadata.MetadataType; | ||
import org.quiltmc.config.api.metadata.NamingScheme; | ||
import org.quiltmc.config.api.metadata.NamingSchemes; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Used to tell the serializer how properties should be formatted when saving to disk. Can be applied to configs, sections and properties. {@link SerializedName} must always take priority. | ||
* @see SerializedName | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.TYPE}) | ||
public @interface SerializedNameConvention { | ||
/** | ||
* A {@link MetadataType} to supply to {@link Config.Builder#metadata} | ||
*/ | ||
MetadataType<NamingScheme, SerializedNameConvention.Builder> TYPE = MetadataType.create(Optional::empty, SerializedNameConvention.Builder::new, true); | ||
|
||
/** | ||
* One of the included {@link NamingSchemes}. The naming schemes must not generate spaces. {@link SerializedNameConvention#custom()} takes priority when not empty | ||
* @see NamingSchemes | ||
*/ | ||
NamingSchemes value() default NamingSchemes.PASSTHROUGH; | ||
|
||
/** | ||
* A fully qualified name of a class implementing the {@link NamingScheme}. Ignored when empty, takes precedence over {@link SerializedNameConvention#value()} otherwise. | ||
*/ | ||
String custom() default ""; | ||
|
||
final class Builder implements MetadataType.Builder<NamingScheme> { | ||
private NamingScheme scheme; | ||
|
||
public Builder() { | ||
scheme = NamingSchemes.PASSTHROUGH; | ||
} | ||
|
||
public void set(NamingScheme scheme) { | ||
if (scheme == NamingSchemes.SPACE_SEPARATED_LOWER_CASE || scheme == NamingSchemes.SPACE_SEPARATED_LOWER_CASE_INITIAL_UPPER_CASE || scheme == NamingSchemes.TITLE_CASE) { | ||
throw new IllegalArgumentException("Scheme with spaces unsupported for serialized names"); | ||
} | ||
this.scheme = scheme; | ||
} | ||
|
||
@Override | ||
public NamingScheme build() { | ||
return scheme; | ||
} | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/quiltmc/config/api/metadata/NamingScheme.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,29 @@ | ||
/* | ||
* Copyright 2024 QuiltMC | ||
* | ||
* 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 org.quiltmc.config.api.metadata; | ||
|
||
/** | ||
* A naming scheme to indicate how a string should be formatted. | ||
* <p> | ||
* Common formats are exposed in {@link NamingSchemes}. | ||
* </p> | ||
* @see org.quiltmc.config.api.annotations.SerializedNameConvention | ||
*/ | ||
@FunctionalInterface | ||
public interface NamingScheme { | ||
String coerce(String input); | ||
} |
Oops, something went wrong.