Skip to content
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

[Attention][Feature] Rewrite config #21

Merged
merged 25 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1656796
🐺🚧📕🔧💻✔️💾🚀️
AmarokIce Dec 22, 2024
c3f8fa2
🐺🚧📕🔧💻✔️💾🚀️
AmarokIce Dec 22, 2024
053b2bc
🐺📰
AmarokIce Dec 24, 2024
46203a1
🐺🚧
AmarokIce Dec 24, 2024
01c69c9
chore: Apply Spotless
github-actions[bot] Dec 24, 2024
d094dfa
🐺❓
AmarokIce Dec 24, 2024
1cc3730
Merge branch 'dev/config' of https://github.com/KessokuTeaTime/Kessok…
AmarokIce Dec 24, 2024
e487dd3
🐺🚧🚀
AmarokIce Dec 25, 2024
21841a1
chore: Apply Spotless
github-actions[bot] Dec 25, 2024
2aa4eba
🐺🦀
AmarokIce Dec 27, 2024
1e6de53
Merge remote-tracking branch 'origin/dev/config' into dev/config
AmarokIce Dec 27, 2024
55ead24
🐺💾🪡🔩
AmarokIce Dec 27, 2024
a9d2ba1
chore: Apply Spotless
github-actions[bot] Dec 27, 2024
719e663
🐺💾🪡🔩
AmarokIce Jan 13, 2025
14cd07f
chore: Apply Spotless
github-actions[bot] Jan 13, 2025
397f236
🐺🪡🔩🚀
AmarokIce Jan 31, 2025
bd8eabf
Merge branch 'dev/config' of https://github.com/KessokuTeaTime/Kessok…
AmarokIce Jan 31, 2025
782d262
chore: Apply Spotless
github-actions[bot] Jan 31, 2025
beb2460
🐺🚀🎶
AmarokIce Feb 1, 2025
321868d
Merge remote-tracking branch 'origin/dev/config' into dev/config
AmarokIce Feb 1, 2025
63c46aa
chore: Apply Spotless
github-actions[bot] Feb 1, 2025
786ad36
🐺❌
AmarokIce Feb 3, 2025
554f678
chore: Apply Spotless
github-actions[bot] Feb 3, 2025
12bbb73
🐺📰🎶
AmarokIce Feb 4, 2025
194b30a
chore: Apply Spotless
github-actions[bot] Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,22 @@ build

run
.DS_Store
.architectury-transformer
.architectury-transformer

# Eclipse
.loadpath
.metadata
.settings

**/.classpath
**/.project

# NetBeans
nbbuild
dist
nbdist
.nb-gradle

**/nbproject/private
**/nbproject/Makefile-*.mk
**/nbproject/Package-*.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package band.kessoku.lib.api.base.reflect;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.util.Arrays;

import band.kessoku.lib.api.KessokuLib;

public final class ReflectUtil {
private ReflectUtil() {
}
Expand All @@ -31,4 +34,14 @@ public static boolean isAssignableFrom(Object o, Class<?>... classes) {
var flag = Arrays.stream(classes).anyMatch(clazz -> !o.getClass().isAssignableFrom(clazz));
return !flag;
}

public static boolean markAccessible(AccessibleObject obj) {
try {
obj.setAccessible(true);
return true;
} catch (Exception e) {
KessokuLib.getLogger().error(e.getMessage(), e);
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 KessokuTeaTime
*
* Licensed under the GNU Lesser General Pubic License, Version 3 (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.gnu.org/licenses/lgpl-3.0.html
*
* 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 band.kessoku.lib.api.config;

import java.lang.annotation.*;

/**
* Config certainly allows comment, and multi-line comment.
* It is usually used to explain the purpose of an entry or to fill in the format, etc.
*
* <p>This annotation should be placed on the config's field.
*
* {@snippet :
* import band.kessoku.lib.config.api.config.Config;
* import band.kessoku.lib.config.api.config.Name;
* import band.kessoku.lib.config.api.config.Comments;
* import band.kessoku.lib.config.values.config.StringValue;
*
* @Config(modid="mymodid", serialize="json5")
* public class MyConfig {
* @Comment("First comment")
* @Comment("Second comment")
* @Name("someoneField")
* public static final StringValue SOMEONE_FIELD = new StringValue("test");
* }
*}
*
* <p>and in config:
*
* {@snippet :
* // First comment
* // Second comment
* someoneField = test
* }
*
* @see Config @Config
* @see Name @Name
*
* @author AmarokIce
*/
@Repeatable(Comments.class)
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Comment {
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package band.kessoku.lib.api.config.annotations;
package band.kessoku.lib.api.config;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
/**
* @see Comment
*
* @author AmarokIce
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Comments {
Comment[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,53 @@
*/
package band.kessoku.lib.api.config;

import band.kessoku.lib.impl.config.AbstractConfig;

public class Config extends AbstractConfig {
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import band.kessoku.lib.api.config.serializer.ConfigSerializers;

/**
* All configs started here to create a new config.
*
* <p>The only necessary data is modid, if config name is empty, it will fill by modid.
* The registration process is automatic, you need to put the secondary bet liberation
* at the head of the config class.
*
* <p>We provide some default {@link ConfigSerializer} in {@link ConfigSerializers}.
*
* <p>And the new config {@code ConfigSerializer} should registry in {@link ConfigSerializers#register}.
*
* {@snippet :
* @Config(modid="mymodid", serialize="json5")
* public class MyConfig {
* @Comment("First comment")
* @Comment("Second comment")
* @Name("someoneField")
* public static String SOMEONE_FIELD = "test";
* }
*}
*
* <p>and in config:
*
* {@snippet :
* // First comment
* // Second comment
* someoneField = test
* }
*
* @see Comment
* @see Name
* @see ConfigSerializers
*
* @author AmarokIce
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Config {
String modid();
String name() default "";
String serialize() default "toml";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
*/
package band.kessoku.lib.api.config;

import java.util.Map;

import band.kessoku.lib.impl.config.AbstractConfig;
import band.kessoku.lib.api.config.exception.IllegalValueException;
import band.kessoku.lib.api.config.serializer.Json5ConfigSerializer;
import band.kessoku.lib.api.config.serializer.JsonConfigSerializer;
import band.kessoku.lib.api.config.serializer.TomlConfigSerializer;

/**
* @see JsonConfigSerializer
* @see Json5ConfigSerializer
* @see TomlConfigSerializer
*
* @author AmarokIce
*/
public interface ConfigSerializer {
String serialize(Map<String, AbstractConfig.WrappedValue> valueMap);

Map<String, Object> deserialize(String value);
/**
* @throws IllegalValueException If config name cannot be encoded, throw IllegalValueException.
*/
void serializer(String valueStr, Class<?> clazz) throws IllegalValueException;

String getFileExtension();
/**
* @return raw data will fill in config.
*/
String deserializer(Class<?> clazz);
}

This file was deleted.

Loading