Rename extraData to additionalInfo consistently
This commit is contained in:
5 files changed
+45
-45
No files matched your search
+16
-16
@@ -37,20 +37,20 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
private final String ruleClassName;
|
||||
private final String ruleName;
|
||||
private final String ruleTargetLanguage;
|
||||
private final Map<String, String> extraData;
|
||||
private final Map<String, String> additionalInfo;
|
||||
|
||||
private CachedRuleViolation(final CachedRuleMapper mapper, final String description,
|
||||
final String fileName, final String ruleClassName, final String ruleName,
|
||||
final String ruleTargetLanguage, final int beginLine, final int beginColumn,
|
||||
final int endLine, final int endColumn,
|
||||
final Map<String, String> extraData) {
|
||||
final Map<String, String> additionalInfo) {
|
||||
this.mapper = mapper;
|
||||
this.description = description;
|
||||
this.location = FileLocation.range(fileName, TextRange2d.range2d(beginLine, beginColumn, endLine, endColumn));
|
||||
this.ruleClassName = ruleClassName;
|
||||
this.ruleName = ruleName;
|
||||
this.ruleTargetLanguage = ruleTargetLanguage;
|
||||
this.extraData = extraData;
|
||||
this.additionalInfo = additionalInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +71,7 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAdditionalInfo() {
|
||||
return extraData;
|
||||
return additionalInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,24 +93,24 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
final int beginColumn = stream.readInt();
|
||||
final int endLine = stream.readInt();
|
||||
final int endColumn = stream.readInt();
|
||||
Map<String, String> extraData = readExtraData(stream);
|
||||
final Map<String, String> additionalInfo = readAdditionalInfo(stream);
|
||||
return new CachedRuleViolation(mapper, description, fileName, ruleClassName, ruleName, ruleTargetLanguage,
|
||||
beginLine, beginColumn, endLine, endColumn, extraData);
|
||||
beginLine, beginColumn, endLine, endColumn, additionalInfo);
|
||||
}
|
||||
|
||||
private static @NonNull Map<String, String> readExtraData(DataInputStream stream) throws IOException {
|
||||
int numExtraKvps = stream.readInt();
|
||||
if (numExtraKvps == 0) {
|
||||
private static @NonNull Map<String, String> readAdditionalInfo(DataInputStream stream) throws IOException {
|
||||
int numAdditionalInfoKeyValuePairs = stream.readInt();
|
||||
if (numAdditionalInfoKeyValuePairs == 0) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<String, String> extraData = new LinkedHashMap<>();
|
||||
while (numExtraKvps-- > 0) {
|
||||
Map<String, String> additionalInfo = new LinkedHashMap<>();
|
||||
while (numAdditionalInfoKeyValuePairs-- > 0) {
|
||||
final String key = stream.readUTF();
|
||||
final String value = stream.readUTF();
|
||||
extraData.put(key, value);
|
||||
additionalInfo.put(key, value);
|
||||
}
|
||||
return Collections.unmodifiableMap(extraData);
|
||||
return Collections.unmodifiableMap(additionalInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,9 +131,9 @@ public final class CachedRuleViolation implements RuleViolation {
|
||||
stream.writeInt(location.getStartPos().getColumn());
|
||||
stream.writeInt(location.getEndPos().getColumn());
|
||||
stream.writeInt(location.getEndPos().getColumn());
|
||||
Map<String, String> extraData = violation.getAdditionalInfo();
|
||||
stream.writeInt(extraData.size());
|
||||
for (Entry<String, String> entry : extraData.entrySet()) {
|
||||
Map<String, String> additionalInfo = violation.getAdditionalInfo();
|
||||
stream.writeInt(additionalInfo.size());
|
||||
for (Entry<String, String> entry : additionalInfo.entrySet()) {
|
||||
stream.writeUTF(entry.getKey());
|
||||
stream.writeUTF(StringUtil.nullToEmpty(entry.getValue()));
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ParametricRuleViolation implements RuleViolation {
|
||||
|
||||
private final FileLocation location;
|
||||
|
||||
private final Map<String, String> extraData;
|
||||
private final Map<String, String> additionalInfo;
|
||||
|
||||
// todo add factory methods on the interface and hide the class.
|
||||
|
||||
@@ -43,25 +43,25 @@ public class ParametricRuleViolation implements RuleViolation {
|
||||
this(theRule, location, message, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public ParametricRuleViolation(Rule theRule, Reportable node, String message, Map<String, String> extraData) {
|
||||
this(theRule, node.getReportLocation(), message, extraData);
|
||||
public ParametricRuleViolation(Rule theRule, Reportable node, String message, Map<String, String> additionalInfo) {
|
||||
this(theRule, node.getReportLocation(), message, additionalInfo);
|
||||
}
|
||||
|
||||
public ParametricRuleViolation(Rule theRule, FileLocation location, String message, Map<String, String> extraData) {
|
||||
public ParametricRuleViolation(Rule theRule, FileLocation location, String message, Map<String, String> additionalInfo) {
|
||||
this.rule = AssertionUtil.requireParamNotNull("rule", theRule);
|
||||
this.description = AssertionUtil.requireParamNotNull("message", message);
|
||||
this.location = location;
|
||||
|
||||
if (!extraData.isEmpty()) {
|
||||
this.extraData = Collections.unmodifiableMap(extraData);
|
||||
if (!additionalInfo.isEmpty()) {
|
||||
this.additionalInfo = Collections.unmodifiableMap(additionalInfo);
|
||||
} else {
|
||||
this.extraData = Collections.emptyMap();
|
||||
this.additionalInfo = Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAdditionalInfo() {
|
||||
return extraData;
|
||||
return additionalInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,27 +13,27 @@ import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
/**
|
||||
* Adds extra key/value pairs to a violation in a language-specific manner.
|
||||
* Adds additional key/value pairs to a violation in a language-specific manner.
|
||||
* The keys are completely free. {@link RuleViolation} defines some of these keys.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ViolationDecorator {
|
||||
|
||||
/**
|
||||
* Compute extra key/value pairs about the violation that should be
|
||||
* reflected in {@link RuleViolation#getAdditionalInfo()}. This extra
|
||||
* info should be accumulated into the {@code extraData} parameter.
|
||||
* Compute additional key/value pairs about the violation that should be
|
||||
* reflected in {@link RuleViolation#getAdditionalInfo()}. This additional
|
||||
* info should be accumulated into the {@code additionalInfo} parameter.
|
||||
*
|
||||
* @param violationNode The node on which the violation was reported
|
||||
* @param extraData Accumulator
|
||||
* @param violationNode The node on which the violation was reported
|
||||
* @param additionalInfo Accumulator
|
||||
*/
|
||||
void decorate(Node violationNode, Map<String, String> extraData);
|
||||
void decorate(Node violationNode, Map<String, String> additionalInfo);
|
||||
|
||||
static Map<String, String> apply(ViolationDecorator decorator, Node violationNode) {
|
||||
Map<String, String> extraData = new HashMap<>();
|
||||
decorator.decorate(violationNode, extraData);
|
||||
if (!extraData.isEmpty()) {
|
||||
return Collections.unmodifiableMap(extraData);
|
||||
Map<String, String> additionalInfo = new HashMap<>();
|
||||
decorator.decorate(violationNode, additionalInfo);
|
||||
if (!additionalInfo.isEmpty()) {
|
||||
return Collections.unmodifiableMap(additionalInfo);
|
||||
} else {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ class YAHTMLRendererTest extends AbstractRendererTest {
|
||||
|
||||
private RuleViolation newRuleViolation(int beginLine, int beginColumn, int endLine, int endColumn, final String packageNameArg, final String classNameArg) {
|
||||
FileLocation loc = createLocation(beginLine, beginColumn, endLine, endColumn);
|
||||
Map<String, String> extraData = CollectionUtil.mapOf(RuleViolation.PACKAGE_NAME, packageNameArg,
|
||||
RuleViolation.CLASS_NAME, classNameArg);
|
||||
return new ParametricRuleViolation(new FooRule(), loc, "blah", extraData);
|
||||
Map<String, String> additionalInfo = CollectionUtil.mapOf(RuleViolation.PACKAGE_NAME, packageNameArg,
|
||||
RuleViolation.CLASS_NAME, classNameArg);
|
||||
return new ParametricRuleViolation(new FooRule(), loc, "blah", additionalInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-7
@@ -32,13 +32,13 @@ final class JavaViolationDecorator implements ViolationDecorator {
|
||||
static final ViolationDecorator INSTANCE = new JavaViolationDecorator();
|
||||
|
||||
@Override
|
||||
public void decorate(Node violationNode, Map<String, String> extraData) {
|
||||
public void decorate(Node violationNode, Map<String, String> additionalInfo) {
|
||||
JavaNode javaNode = (JavaNode) violationNode;
|
||||
|
||||
setIfNonNull(RuleViolation.VARIABLE_NAME, getVariableNameIfExists(javaNode), extraData);
|
||||
setIfNonNull(RuleViolation.METHOD_NAME, getMethodName(javaNode), extraData);
|
||||
setIfNonNull(RuleViolation.CLASS_NAME, getClassName(javaNode), extraData);
|
||||
setIfNonNull(RuleViolation.PACKAGE_NAME, javaNode.getRoot().getPackageName(), extraData);
|
||||
setIfNonNull(RuleViolation.VARIABLE_NAME, getVariableNameIfExists(javaNode), additionalInfo);
|
||||
setIfNonNull(RuleViolation.METHOD_NAME, getMethodName(javaNode), additionalInfo);
|
||||
setIfNonNull(RuleViolation.CLASS_NAME, getClassName(javaNode), additionalInfo);
|
||||
setIfNonNull(RuleViolation.PACKAGE_NAME, javaNode.getRoot().getPackageName(), additionalInfo);
|
||||
}
|
||||
|
||||
private @Nullable String getClassName(JavaNode javaNode) {
|
||||
@@ -61,9 +61,9 @@ final class JavaViolationDecorator implements ViolationDecorator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setIfNonNull(String key, String value, Map<String, String> extraData) {
|
||||
private void setIfNonNull(String key, String value, Map<String, String> additionalInfo) {
|
||||
if (value != null) {
|
||||
extraData.put(key, value);
|
||||
additionalInfo.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user