Skip to content

Commit b8cdc1f

Browse files
committed
add side comments
1 parent 0c3453a commit b8cdc1f

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

core/src/main/java/net/j4c0b3y/api/config/ConfigDocument.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import dev.dejvokep.boostedyaml.YamlDocument;
44
import dev.dejvokep.boostedyaml.block.Block;
55
import dev.dejvokep.boostedyaml.block.Comments;
6+
import dev.dejvokep.boostedyaml.block.Comments.Position;
7+
import dev.dejvokep.boostedyaml.libs.org.snakeyaml.engine.v2.comments.CommentLine;
68
import dev.dejvokep.boostedyaml.route.Route;
79
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
810
import dev.dejvokep.boostedyaml.utils.format.NodeRole;
@@ -116,7 +118,7 @@ public void wipeComments(Block<?> block) {
116118
*/
117119
protected void setComment(Block<?> block, StaticConfig.Comment comment) {
118120
if (comment != null) {
119-
setComment(block, Arrays.asList(comment.value()));
121+
setComment(block, Arrays.asList(comment.value()), comment.side());
120122
}
121123
}
122124

@@ -126,12 +128,15 @@ protected void setComment(Block<?> block, StaticConfig.Comment comment) {
126128
* @param block The block to set the comment for.
127129
* @param comment The comment list.
128130
*/
129-
protected void setComment(Block<?> block, List<String> comment) {
130-
List<String> lines = comment.stream()
131-
.map(line -> " " + line)
131+
protected void setComment(Block<?> block, List<String> comment, boolean side) {
132+
Position position = side ? Position.INLINE : Position.BEFORE;
133+
NodeRole role = side ? NodeRole.VALUE : NodeRole.KEY;
134+
135+
List<CommentLine> lines = comment.stream()
136+
.map(line -> Comments.create(" " + line, position))
132137
.collect(Collectors.toList());
133138

134-
block.setComments(lines);
139+
Comments.set(block, role, position, lines);
135140
}
136141

137142
/**

core/src/main/java/net/j4c0b3y/api/config/StaticConfig.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.j4c0b3y.api.config.provider.context.LoadContext;
1111
import net.j4c0b3y.api.config.provider.context.SaveContext;
1212
import net.j4c0b3y.api.config.utils.ClassUtils;
13+
import net.j4c0b3y.api.config.utils.Pair;
1314

1415
import java.io.File;
1516
import java.io.IOException;
@@ -71,7 +72,7 @@ public abstract class StaticConfig {
7172
/**
7273
* A map of custom comments to add to fields.
7374
*/
74-
private final Map<String, List<String>> comments = new HashMap<>();
75+
private final Map<String, Pair<List<String>, Boolean>> comments = new HashMap<>();
7576

7677
/**
7778
* If the last load operation was successful.
@@ -390,14 +391,25 @@ private void relocate() {
390391
});
391392
}
392393

394+
/**
395+
* Adds a custom comment to a route in the document.
396+
*
397+
* @param route The route.
398+
* @param side If the comment is on the side.
399+
* @param comment The comment.
400+
*/
401+
protected void setComment(String route, boolean side, String ...comment) {
402+
comments.put(route, new Pair<>(Arrays.asList(comment), side));
403+
}
404+
393405
/**
394406
* Adds a custom comment to a route in the document.
395407
*
396408
* @param route The route.
397409
* @param comment The comment.
398410
*/
399411
protected void setComment(String route, String ...comment) {
400-
comments.put(route, Arrays.asList(comment));
412+
setComment(route, false, comment);
401413
}
402414

403415
/**
@@ -411,7 +423,7 @@ private void setComments() {
411423
List<String> comments = block.getComments();
412424
if (comments != null && !comments.isEmpty()) return;
413425

414-
document.setComment(block, comment);
426+
document.setComment(block, comment.getLeft(), comment.getRight());
415427
});
416428
}
417429

@@ -458,6 +470,7 @@ private String getRoute(Key key, String name) {
458470
@Target({ElementType.TYPE, ElementType.FIELD})
459471
protected @interface Comment {
460472
String[] value();
473+
boolean side() default false;
461474
}
462475

463476
/**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.j4c0b3y.api.config.utils;
2+
3+
import lombok.Getter;
4+
import lombok.RequiredArgsConstructor;
5+
6+
/**
7+
* @author J4C0B3Y
8+
* @version ConfigAPI
9+
* @since 7/02/2025
10+
*/
11+
@Getter
12+
@RequiredArgsConstructor
13+
public class Pair<L, R> {
14+
private final L left;
15+
private final R right;
16+
}

0 commit comments

Comments
 (0)