• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / CyclopsCore / #479033825

15 Feb 2026 08:26AM UTC coverage: 22.891% (+0.8%) from 22.078%
#479033825

Pull #217

github

Copilot
Fix javadoc HTML malformed errors in NOT handler

Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
Pull Request #217: Add parentheses grouping support for NBT path logical expressions

115 of 133 new or added lines in 6 files covered. (86.47%)

2412 of 10537 relevant lines covered (22.89%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/src/main/java/org/cyclops/cyclopscore/nbt/path/parse/NbtPathExpressionParseHandlerGrouping.java
1
package org.cyclops.cyclopscore.nbt.path.parse;
2

3
import org.cyclops.cyclopscore.nbt.path.INbtPathExpression;
4
import org.cyclops.cyclopscore.nbt.path.NbtParseException;
5
import org.cyclops.cyclopscore.nbt.path.NbtPath;
6

7
import javax.annotation.Nullable;
8
import java.util.regex.Matcher;
9
import java.util.regex.Pattern;
10

11
/**
12
 * A handler that handles parenthesized expressions for grouping: "(expression)".
13
 * This allows precedence control in complex logical expressions.
14
 */
15
public class NbtPathExpressionParseHandlerGrouping implements INbtPathExpressionParseHandler {
1✔
16

17
    private static final Pattern REGEX_EXPRESSION = Pattern.compile("^ *\\(");
1✔
18

19
    @Nullable
20
    @Override
21
    public HandleResult handlePrefixOf(String nbtPathExpression, int pos) {
22
        Matcher matcher = REGEX_EXPRESSION
1✔
23
                .matcher(nbtPathExpression)
1✔
24
                .region(pos, nbtPathExpression.length());
1✔
25
        if (!matcher.find()) {
1✔
26
            return HandleResult.INVALID;
1✔
27
        }
28

29
        // Find the matching closing parenthesis
30
        int openPos = pos + matcher.group().length() - 1; // Position of '('
1✔
31
        int closePos = findMatchingClosingParenthesis(nbtPathExpression, openPos);
1✔
32
        if (closePos == -1) {
1✔
NEW
33
            return HandleResult.INVALID;
×
34
        }
35

36
        // Extract the expression inside the parentheses
37
        String innerExpression = nbtPathExpression.substring(openPos + 1, closePos);
1✔
38

39
        try {
40
            // Parse the inner expression
41
            INbtPathExpression expression = NbtPath.parse(innerExpression.trim());
1✔
42

43
            // The grouping itself doesn't change the expression, it just controls precedence
44
            // So we return the inner expression directly wrapped in a pass-through
45
            return new HandleResult(expression, matcher.group().length() + innerExpression.length() + 1);
1✔
NEW
46
        } catch (NbtParseException e) {
×
NEW
47
            return HandleResult.INVALID;
×
48
        }
49
    }
50

51
    /**
52
     * Find the matching closing parenthesis for an opening parenthesis.
53
     * @param expression The expression string
54
     * @param openPos The position of the opening parenthesis
55
     * @return The position of the matching closing parenthesis, or -1 if not found
56
     */
57
    private int findMatchingClosingParenthesis(String expression, int openPos) {
58
        int depth = 0;
1✔
59
        for (int i = openPos; i < expression.length(); i++) {
1✔
60
            char c = expression.charAt(i);
1✔
61
            if (c == '(') {
1✔
62
                depth++;
1✔
63
            } else if (c == ')') {
1✔
64
                depth--;
1✔
65
                if (depth == 0) {
1✔
66
                    return i;
1✔
67
                }
68
            }
69
        }
NEW
70
        return -1;
×
71
    }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc