forked from checkstyle/checkstyle
/
ModuleInputConfiguration.java
139 lines (109 loc) · 5 KB
/
ModuleInputConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2021 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.bdd;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public final class ModuleInputConfiguration {
/** The module name. */
private final String moduleName;
/** Map of default properties. */
private final Map<String, String> defaultProperties;
/** Map of non default properties. */
private final Map<String, String> nonDefaultProperties;
/** Map of module messages. */
private final Map<String, String> moduleMessages;
/** List of parsed violations. */
private final List<TestInputViolation> violations;
private ModuleInputConfiguration(String moduleName,
Map<String, String> defaultProperties,
Map<String, String> nonDefaultProperties,
Map<String, String> moduleMessages,
List<TestInputViolation> violations) {
this.moduleName = moduleName;
this.defaultProperties = defaultProperties;
this.nonDefaultProperties = nonDefaultProperties;
this.moduleMessages = moduleMessages;
this.violations = violations;
}
public String getModuleName() {
return moduleName;
}
public Map<String, String> getAllProperties() {
final Map<String, String> properties = new HashMap<>();
properties.putAll(defaultProperties);
properties.putAll(nonDefaultProperties);
return Collections.unmodifiableMap(properties);
}
public Map<String, String> getDefaultProperties() {
return Collections.unmodifiableMap(defaultProperties);
}
public Map<String, String> getNonDefaultProperties() {
return Collections.unmodifiableMap(nonDefaultProperties);
}
public Map<String, String> getModuleMessages() {
return Collections.unmodifiableMap(moduleMessages);
}
public List<TestInputViolation> getViolations() {
return Collections.unmodifiableList(violations);
}
public DefaultConfiguration createConfiguration() {
final DefaultConfiguration parsedConfig = new DefaultConfiguration(moduleName);
nonDefaultProperties.forEach(parsedConfig::addProperty);
moduleMessages.forEach(parsedConfig::addMessage);
return parsedConfig;
}
public String getDefaultPropertyValue(String key) {
return defaultProperties.get(key);
}
public static final class Builder {
private final Map<String, String> defaultProperties = new HashMap<>();
private final Map<String, String> nonDefaultProperties = new HashMap<>();
private final Map<String, String> moduleMessages = new HashMap<>();
private final List<TestInputViolation> violations = new ArrayList<>();
private String moduleName;
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public void addDefaultProperty(String propertyName, String defaultPropertyValue) {
defaultProperties.put(propertyName, defaultPropertyValue);
}
public void addNonDefaultProperty(String propertyName, String nonDefaultPropertyValue) {
nonDefaultProperties.put(propertyName, nonDefaultPropertyValue);
}
public void addModuleMessage(String messageKey, String messageString) {
moduleMessages.put(messageKey, messageString);
}
public void addViolation(int violationLine, String violationMessage) {
violations.add(new TestInputViolation(violationLine, violationMessage));
}
public ModuleInputConfiguration build() {
return new ModuleInputConfiguration(
moduleName,
defaultProperties,
nonDefaultProperties,
moduleMessages,
violations
);
}
}
}