Merge branch 'java-grammar' into typeres-jtypes

This commit is contained in:
Clément Fournier
2020-08-23 20:05:43 +02:00
2 changed files with 12 additions and 18 deletions

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.java;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -23,19 +22,13 @@ import net.sourceforge.pmd.lang.rule.xpath.Attribute;
*/
public class JavaAttributesPrinter extends RelevantAttributePrinter {
@Override
protected @NonNull Iterable<AttributeInfo> getAttributes(@NonNull Node node) {
protected void fillAttributes(@NonNull Node node, @NonNull List<AttributeInfo> result) {
super.fillAttributes(node, result);
if (node instanceof ASTModifierList) {
List<AttributeInfo> attributes = new ArrayList<>();
super.getAttributes(node).forEach(attributes::add);
attributes.add(getModifierAttr("EffectiveModifiers", ((ASTModifierList) node).getEffectiveModifiers()));
attributes.add(getModifierAttr("ExplicitModifiers", ((ASTModifierList) node).getExplicitModifiers()));
return attributes;
result.add(getModifierAttr("EffectiveModifiers", ((ASTModifierList) node).getEffectiveModifiers()));
result.add(getModifierAttr("ExplicitModifiers", ((ASTModifierList) node).getExplicitModifiers()));
}
return super.getAttributes(node);
}
@Override

View File

@ -42,18 +42,19 @@ open class BaseNodeAttributePrinter : TextTreeRenderer(true, -1) {
protected open fun ignoreAttribute(node: Node, attribute: Attribute): Boolean = true
protected open fun getAttributes(node: Node): Iterable<AttributeInfo> =
node.xPathAttributesIterator
.asSequence()
.filterNot { ignoreAttribute(node, it) }
.map { AttributeInfo(it.name, it.value?.toString()) }
.asIterable()
protected open fun fillAttributes(node: Node, result: MutableList<AttributeInfo>) {
node.xPathAttributesIterator
.asSequence()
.filterNot { ignoreAttribute(node, it) }
.map { AttributeInfo(it.name, it.value?.toString()) }
.forEach { result += it }
}
override fun appendNodeInfoLn(out: Appendable, node: Node) {
out.append(node.xPathNodeName)
val attrs = getAttributes(node).toMutableList()
val attrs = mutableListOf<AttributeInfo>().also { fillAttributes(node, it) }
// sort to get deterministic results
attrs.sortBy { it.name }