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

devonfw / IDEasy / 24984011544

27 Apr 2026 08:14AM UTC coverage: 70.718% (+0.08%) from 70.641%
24984011544

Pull #1856

github

web-flow
Merge f59d7af1d into 344d6c0f7
Pull Request #1856: #1643 improve ux on syntax error

4403 of 6878 branches covered (64.02%)

Branch coverage included in aggregate %.

11348 of 15395 relevant lines covered (73.71%)

3.12 hits per line

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

95.65
cli/src/main/java/com/devonfw/tools/ide/validation/ValidationState.java
1
package com.devonfw.tools.ide.validation;
2

3
import com.devonfw.tools.ide.cli.CliArgument;
4

5
/**
6
 * Implementation of {@link ValidationResult} as a mutable state that can collect errors dynamically.
7
 */
8
public class ValidationState implements ValidationResult {
9

10
  private final String propertyName;
11

12
  private StringBuilder errorMessage;
13

14
  /**
15
   * Field for the {@link CliArgument} that was the reason for a failed validation.
16
   */
17
  private CliArgument cliArgument;
18

19
  /**
20
   * The default constructor for no property.
21
   */
22
  public ValidationState() {
23
    this(null);
×
24
  }
×
25

26
  /**
27
   * @param propertyName the name of the property to validate.
28
   */
29
  public ValidationState(String propertyName) {
2✔
30
    this.propertyName = propertyName;
3✔
31
  }
1✔
32

33
  @Override
34
  public boolean isValid() {
35
    return (this.errorMessage == null);
7✔
36
  }
37

38
  @Override
39
  public String getErrorMessage() {
40
    if (this.errorMessage == null) {
3✔
41
      return null;
2✔
42
    }
43
    return this.errorMessage.toString();
4✔
44
  }
45

46
  /**
47
   * @param error the error message to add to this {@link ValidationState}.
48
   */
49
  public void addErrorMessage(String error) {
50
    if (this.errorMessage == null) {
3✔
51
      if (this.propertyName == null) {
3✔
52
        this.errorMessage = new StringBuilder(error.length() + 1);
9✔
53
        this.errorMessage.append('\n');
6✔
54
      } else {
55
        this.errorMessage = new StringBuilder(error.length() + propertyName.length() + 21); // 21 for the static text below
13✔
56
        this.errorMessage.append(String.format("Error in property %s:", propertyName));
13✔
57
        this.errorMessage.append('\n');
6✔
58
      }
59
    } else {
60
      this.errorMessage.append('\n');
5✔
61
    }
62
    this.errorMessage.append(error);
5✔
63
  }
1✔
64

65
  /**
66
   * @param result the {@link ValidationResult} to add to this {@link ValidationState}.
67
   */
68
  public void add(ValidationResult result) {
69
    if (!result.isValid()) {
3✔
70
      if (this.errorMessage == null) {
3✔
71
        this.errorMessage = new StringBuilder(result.getErrorMessage().length());
8✔
72
        this.errorMessage.append(result.getErrorMessage());
7✔
73
      } else {
74
        addErrorMessage(result.getErrorMessage());
4✔
75
      }
76
    }
77
  }
1✔
78

79
  private String parseHint;
80

81
  private String parseExceptionMessage;
82

83
  /**
84
   * @param cliArgument The {@link CliArgument} that failed the validation.
85
   */
86
  public void setCliArgument(CliArgument cliArgument) {
87
    this.cliArgument = cliArgument;
3✔
88
  }
1✔
89

90
  /**
91
   * @return The {@link CliArgument} that failed the validation.
92
   */
93
  public CliArgument getCliArgument() {
94
    return this.cliArgument;
3✔
95
  }
96

97
  /**
98
   * @param parseHint the hint to display when a parse error occurred (e.g. a list of valid values).
99
   */
100
  public void setParseHint(String parseHint) {
101
    this.parseHint = parseHint;
3✔
102
  }
1✔
103

104
  /**
105
   * @return the hint for the failed parse, or {@code null} if none.
106
   */
107
  public String getParseHint() {
108
    return this.parseHint;
3✔
109
  }
110

111
  /**
112
   * @param parseExceptionMessage the message from a non-{@link IllegalArgumentException} parse failure.
113
   */
114
  public void setParseExceptionMessage(String parseExceptionMessage) {
115
    this.parseExceptionMessage = parseExceptionMessage;
3✔
116
  }
1✔
117

118
  /**
119
   * @return the exception message from a non-{@link IllegalArgumentException} parse failure, or {@code null}.
120
   */
121
  public String getParseExceptionMessage() {
122
    return this.parseExceptionMessage;
3✔
123
  }
124
}
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