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

Implement comments for maps and collections with snakeyaml #34

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2a81f61
Implement comments for maps and collections with snakeyaml
Brikster Aug 5, 2022
a98eb9f
Implement comments in bungee configurer
Brikster Aug 5, 2022
1aa0a9e
Remove comments limitations from README.md
Brikster Aug 5, 2022
6e7cb63
Fix collections start key
Brikster Jun 13, 2023
e1fcfc1
Try to fix ConfigPostprocessor again
Brikster Jun 13, 2023
97a3fff
Try to fix comments after multiline sections
Brikster Dec 24, 2023
72a1c13
Fix building
Brikster Dec 24, 2023
55df01a
Experimental comments language
Brikster Dec 24, 2023
8bddf0e
Set comments language directly to config declaration
Brikster Dec 24, 2023
1bc53dd
Fix settings comments language
Brikster Dec 24, 2023
e33a47b
Fix settings comments language again
Brikster Dec 24, 2023
ea9a920
Fix settings comments language again
Brikster Dec 24, 2023
d807689
Fix settings comments language again
Brikster Dec 24, 2023
7105aeb
Fix settings comments language again
Brikster Dec 24, 2023
6115644
Set language globally
Brikster Dec 24, 2023
347048c
Delete old field declaration with old language
Brikster Dec 24, 2023
7f56f8b
Delete old config declaration with old language
Brikster Dec 24, 2023
38cd4b7
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
536ca56
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
7fcbb02
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
42cad68
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
70cba8e
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
227ea4a
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
ef138c1
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
6b175fe
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
5a33076
Try to fix level error mistake on multiline strings
Brikster Jan 19, 2024
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
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<parent>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs</artifactId>
<version>4.0.6</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No project version bumps please

<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public ConfigPostprocessor updateLinesKeys(@NonNull ConfigSectionWalker walker)
for (String line : lines) {

int indent = countIndent(line);

int collectionsStartCount = 0;
while (walker.isKeyCollectionStart(line)) {
collectionsStartCount++;
int collectionStartCharIndex = line.indexOf(walker.getCollectionStartChar());
line = line.substring(0, collectionStartCharIndex) + ' ' + line.substring(collectionStartCharIndex + 1);
indent += 2;
}

int change = indent - lastIndent;
String key = walker.readName(line);

Expand Down Expand Up @@ -169,6 +178,12 @@ public ConfigPostprocessor updateLinesKeys(@NonNull ConfigSectionWalker walker)

lastIndent = indent;
String updatedLine = walker.update(line, currentPath.get(currentPath.size() - 1), currentPath);

while (collectionsStartCount != 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic changes in this class are really convoluted and have a lot of mutation based whiles. This needs better structure, should be very much doable with at least semi-simple result.

updatedLine = updatedLine.substring(0, indent - collectionsStartCount * 2) + walker.getCollectionStartChar() + updatedLine.substring(indent - collectionsStartCount * 2 + 1);
collectionsStartCount--;
}

newContext.append(updatedLine).append("\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public interface ConfigSectionWalker {

boolean isKeyMultilineStart(String line);

boolean isKeyCollectionStart(String line);

char getCollectionStartChar();

String readName(String line);

String update(String line, ConfigLineInfo lineInfo, List<ConfigLineInfo> path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public boolean isKey(String line) {
return !name.isEmpty() && (name.charAt(0) != '-') && (name.charAt(0) != '#');
}

@Override
public boolean isKeyCollectionStart(final String line) {
String name = this.readName(line);
return name.charAt(0) == '-';
}

@Override
public char getCollectionStartChar() {
return '-';
}

@Override
public String readName(String line) {
return line.split(":", 2)[0].trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public boolean isPrimitive() {
return this.type.isPrimitive();
}

public boolean isMap() {
return Map.class.isAssignableFrom(this.type);
}

public boolean isCollection() {
return Collection.class.isAssignableFrom(this.type);
}

public boolean isPrimitiveWrapper() {
return PRIMITIVE_WRAPPERS.contains(this.type);
}
Expand All @@ -156,4 +164,11 @@ public boolean isConfig() {
public boolean hasSubtypes() {
return (this.subtype != null) && !this.subtype.isEmpty();
}

public GenericsDeclaration getSubtype(int index) {
if (subtype.size() <= index) {
throw new IllegalArgumentException("Cannot find subtype at position " + index);
}
return subtype.get(index);
}
}
6 changes: 3 additions & 3 deletions hjson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-hjson</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
6 changes: 3 additions & 3 deletions hocon-lightbend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-hocon-lightbend</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
6 changes: 3 additions & 3 deletions json-gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-json-gson</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
6 changes: 3 additions & 3 deletions json-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-json-simple</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions serdes-bucket4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 deletions serdes-bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-serdes-bukkit</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
6 changes: 3 additions & 3 deletions serdes-bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-serdes-bungee</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
4 changes: 2 additions & 2 deletions serdes-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions serdes-okaeri/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions validator-jakartaee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions validator-okaeri/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>okaeri-configs</artifactId>
<groupId>eu.okaeri</groupId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 0 additions & 4 deletions yaml-bukkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ Add dependency to the `maven` section:
implementation 'eu.okaeri:okaeri-configs-yaml-bukkit:4.0.6'
```

## Limitations

- Comments do not work on the elements of Collection or Map.

## Usage

Please use YamlBukkitConfigurer as your configurer:
Expand Down
6 changes: 3 additions & 3 deletions yaml-bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-yaml-bukkit</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ public String update(String line, ConfigLineInfo lineInfo, List<ConfigLineInfo>
return line;
}
GenericsDeclaration fieldType = field.get().getType();
while (fieldType.isMap() || fieldType.isCollection()) {
if (fieldType.isMap()) {
fieldType = fieldType.getSubtype(1);
i++;
} else {
fieldType = fieldType.getSubtype(0);
}
}
if (!fieldType.isConfig()) {
return line;
}
Expand Down
4 changes: 0 additions & 4 deletions yaml-bungee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ Add dependency to the `maven` section:
implementation 'eu.okaeri:okaeri-configs-yaml-bungee:4.0.6'
```

## Limitations

- Comments do not work on the elements of Collection or Map.

## Usage

Please use YamlBungeeConfigurer as your configurer:
Expand Down
6 changes: 3 additions & 3 deletions yaml-bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
</parent>
<artifactId>okaeri-configs-yaml-bungee</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>eu.okaeri</groupId>
<artifactId>okaeri-configs-core</artifactId>
<version>4.0.6</version>
<version>4.0.7-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
Loading