diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeAxisIterator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeAxisIterator.java index 9a0e23baf1..d22adb33ab 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeAxisIterator.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeAxisIterator.java @@ -42,7 +42,7 @@ public class AttributeAxisIterator extends Navigator.BaseEnumeration { public void advance() { if (this.iterator.hasNext()) { Attribute attribute = this.iterator.next(); - super.current = new AttributeNode(attribute, super.position()); + super.current = new AttributeNode(startNodeInfo, attribute, super.position()); } else { super.current = null; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java index 528b4fc578..5bea99b879 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java @@ -24,6 +24,8 @@ import net.sf.saxon.value.Value; @Deprecated @InternalApi public class AttributeNode extends AbstractNodeInfo { + + private final ElementNode parent; protected final Attribute attribute; protected final int id; protected Value value; @@ -32,9 +34,11 @@ public class AttributeNode extends AbstractNodeInfo { /** * Creates a new AttributeNode from a PMD Attribute. * + * @param parent * @param id The index within the attribute order */ - public AttributeNode(Attribute attribute, int id) { + public AttributeNode(ElementNode parent, Attribute attribute, int id) { + this.parent = parent; this.attribute = attribute; this.id = id; } @@ -54,6 +58,11 @@ public class AttributeNode extends AbstractNodeInfo { return ""; } + @Override + public ElementNode getParent() { + return parent; + } + @Override public Value atomize() { if (value == null) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index 94bec1fbb1..ef600ed7ab 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -14,8 +14,14 @@ import net.sf.saxon.om.EmptyIterator; import net.sf.saxon.om.Navigator; import net.sf.saxon.om.NodeArrayIterator; import net.sf.saxon.om.NodeInfo; +import net.sf.saxon.om.SequenceIterator; import net.sf.saxon.om.SingleNodeIterator; +import net.sf.saxon.om.SingletonIterator; import net.sf.saxon.type.Type; +import net.sf.saxon.value.AtomicValue; +import net.sf.saxon.value.StringValue; +import net.sf.saxon.value.UntypedAtomicValue; +import net.sf.saxon.value.Value; /** * A Saxon OM Element type node for an AST Node. @@ -99,6 +105,27 @@ public class ElementNode extends AbstractNodeInfo { return parent; } + @Override + public SequenceIterator getTypedValue() { + return SingletonIterator.makeIterator((AtomicValue) atomize()); + } + + @Override + public Value atomize() { + switch (getNodeKind()) { + case Type.COMMENT: + case Type.PROCESSING_INSTRUCTION: + return new StringValue(getStringValueCS()); + default: + return new UntypedAtomicValue(getStringValueCS()); + } + } + + @Override + public CharSequence getStringValueCS() { + return ""; + } + @Override public int compareOrder(NodeInfo other) { int result; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java index e725d652df..773d64a5c0 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java @@ -51,7 +51,7 @@ public class XPathRule extends AbstractRule { public static final EnumeratedProperty VERSION_DESCRIPTOR = EnumeratedProperty.named("version") .desc("XPath specification version") .mappings(XPATH_VERSIONS) - .defaultValue(XPATH_2_0) + .defaultValue(XPATH_1_0) .type(String.class) .uiOrder(2.0f) .build(); diff --git a/pmd-java/src/main/resources/category/java/design.xml b/pmd-java/src/main/resources/category/java/design.xml index 04ac51af08..0b9c3de696 100644 --- a/pmd-java/src/main/resources/category/java/design.xml +++ b/pmd-java/src/main/resources/category/java/design.xml @@ -1656,8 +1656,8 @@ your API. 3 +//MethodDeclaration[@Public=true()]/MethodDeclarator/FormalParameters[ + count(FormalParameter/Type/ReferenceType/ClassOrInterfaceType[@Image = 'String' and @Array=false()]) > 3 ] ]]> diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index b7ffed64a2..007918de4b 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -2416,7 +2416,7 @@ may indicate problematic behaviour. Empty cases are ignored as these indicate an + count(BlockStatement//Statement/ContinueStatement) + count(BlockStatement//Statement/ThrowStatement) + count(BlockStatement//Statement/IfStatement[@Else= true() and Statement[2][ReturnStatement|ContinueStatement|ThrowStatement]]/Statement[1][ReturnStatement|ContinueStatement|ThrowStatement]) - + count(SwitchLabel[name(following-sibling::node()) = 'SwitchLabel']) + + count(SwitchLabel[ following-sibling::node()[1][self::SwitchLabel] ]) + count(SwitchLabel[count(following-sibling::node()) = 0]) < count (SwitchLabel))] ]]> diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/xpath/XPathMetricFunctionTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/xpath/XPathMetricFunctionTest.java index 48d4c672ec..3e93c5049e 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/xpath/XPathMetricFunctionTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/xpath/XPathMetricFunctionTest.java @@ -33,6 +33,8 @@ import net.sourceforge.pmd.lang.rule.XPathRule; */ public class XPathMetricFunctionTest { + // TODO 7.0 when removing jaxen these tests need to be updated to use pmd-java:metric + private static final String VIOLATION_MESSAGE = "violation"; @org.junit.Rule diff --git a/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml b/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml index 4b6684db3c..1792c31ce2 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml @@ -190,7 +190,7 @@ See also: <http://eslint.org/docs/rules/no-else-return> diff --git a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml index 8a2ffd187f..d8bce354f8 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml @@ -62,11 +62,10 @@ same type. The === operator avoids the casting. @@ -110,7 +109,7 @@ precision in a floating point number. This may result in numeric calculations b diff --git a/pmd-xml/src/main/resources/category/pom/errorprone.xml b/pmd-xml/src/main/resources/category/pom/errorprone.xml index e3143511ca..cfedde95c5 100644 --- a/pmd-xml/src/main/resources/category/pom/errorprone.xml +++ b/pmd-xml/src/main/resources/category/pom/errorprone.xml @@ -78,9 +78,9 @@ By far the most common problem is the use of ${project.version} in a BOM or //dependencies/dependency [contains(version/text/@Image,'{project.version}')] [ - (/project/parent/groupId and groupId/text/@Image != /project/parent/groupId/text/@Image) + (/document/project/parent/groupId and groupId/text/@Image != /document/project/parent/groupId/text/@Image) or - (/project/groupId and groupId/text/@Image != /project/groupId/text/@Image) + (/document/project/groupId and groupId/text/@Image != /document/project/groupId/text/@Image) ]/version ]]>