GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Deprecate support for List attributes with XPath 2.0 · pmd/pmd@9c48ad1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/pages
    • pmd/userdocs/extending
      • writing_xpath_rules.md
    • release_notes.md
  • pmd-core/src
    • main/java/net/sourceforge/pmd/lang/ast/xpath
      • Attribute.java
      • AttributeAxisIterator.java
    • test/java/net/sourceforge/pmd/lang
      • ast
        • DummyNodeWithListAndEnum.java
      • rule
        • XPathRuleTest.java
        • xpath
          • JaxenXPathRuleQueryTest.java
          • SaxonXPathRuleQueryTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/pages/pmd/userdocs/extending/writing_xpath_rules.md‎

Copy file name to clipboardExpand all lines: docs/pages/pmd/userdocs/extending/writing_xpath_rules.md
+6-1Lines changed: 6 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@ function from Java types to XDM types.
8080
|`String` | `xs:string`
8181
|`Character` | `xs:string`
8282
|`Enum<E>` | `xs:string` (uses `Object::toString`)
83-
|`List<E>` | `conv(E)*` (a sequence type)
83+
|`List<E>` | `conv(E)*` (a sequence type) <br> ⚠️ List support is deprecated with 6.25.0. See below.
8484

8585

8686
The same `conv` function is used to translate rule property values to XDM values.
8787

88+
{% include warning.html content="Support for attributes of type `List<E>` has been deprecated
89+
with PMD 6.25.0 and will be removed completely with PMD 7. The reason is that newer Saxon
90+
versions don't support sequences as attributes anymore. Lists are still possible in Java-based
91+
rules but not with XPath." %}
92+
8893

8994
## Migrating from 1.0 to 2.0
9095

Collapse file

‎docs/pages/release_notes.md‎

Copy file name to clipboardExpand all lines: docs/pages/release_notes.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The command line version of PMD continues to use **scala 2.13**.
6666
* apex-bestpractices
6767
* [#2554](https://github.com/pmd/pmd/issues/2554): \[apex] Exception applying rule UnusedLocalVariable on trigger
6868
* core
69+
* [#2451](https://github.com/pmd/pmd/issues/2451): \[core] Deprecate support for List attributes with XPath 2.0
6970
* [#2599](https://github.com/pmd/pmd/pull/2599): \[core] Fix XPath 2.0 Rule Chain Analyzer with Unions
7071
* [#2483](https://github.com/pmd/pmd/issues/2483): \[lang-test] Support cpd tests based on text comparison.
7172
For details see
Collapse file

‎pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java‎

Copy file name to clipboardExpand all lines: pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ public String replacementIfDeprecated() {
7575
return null;
7676
} else {
7777
DeprecatedAttribute annot = method.getAnnotation(DeprecatedAttribute.class);
78-
return annot != null
78+
String result = annot != null
7979
? annot.replaceWith()
8080
: method.isAnnotationPresent(Deprecated.class)
8181
? DeprecatedAttribute.NO_REPLACEMENT
8282
: null;
83+
if (result == null && List.class.isAssignableFrom(method.getReturnType())) {
84+
// Lists are generally deprecated, see #2451
85+
result = "";
86+
}
87+
return result;
8388
}
8489
}
8590

Collapse file

‎pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIterator.java‎

Copy file name to clipboardExpand all lines: pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIterator.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ private boolean isSimpleType(Class<?> klass) {
9696
return CONSIDERED_RETURN_TYPES.contains(klass) || klass.isEnum();
9797
}
9898

99+
// Note: Lists are deprecated with 6.25.0, see #2451
100+
// we still allow them here for compatibility, but this can be removed with PMD 7.
101+
@Deprecated
99102
private boolean isSequence(Type returnType) {
100103
if (returnType instanceof ParameterizedType && ((ParameterizedType) returnType).getRawType() == List.class) {
101104
Type[] actualTypeArguments = ((ParameterizedType) returnType).getActualTypeArguments();
Collapse file

‎…rule/xpath/DummyNodeWithListAndEnum.java‎ ‎…d/lang/ast/DummyNodeWithListAndEnum.java‎pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/DummyNodeWithListAndEnum.java renamed to pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNodeWithListAndEnum.java pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/DummyNodeWithListAndEnum.java renamed to pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNodeWithListAndEnum.java

Copy file name to clipboardExpand all lines: pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNodeWithListAndEnum.java
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
/**
1+
/*
22
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
33
*/
44

5-
package net.sourceforge.pmd.lang.rule.xpath;
5+
package net.sourceforge.pmd.lang.ast;
66

77
import java.util.Arrays;
88
import java.util.Collections;
99
import java.util.List;
1010

11-
import net.sourceforge.pmd.lang.ast.DummyNode;
12-
1311
public class DummyNodeWithListAndEnum extends DummyNode {
1412
public DummyNodeWithListAndEnum(int id) {
1513
super(id);
Collapse file

‎pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java‎

Copy file name to clipboardExpand all lines: pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.sourceforge.pmd.lang.LanguageRegistry;
2020
import net.sourceforge.pmd.lang.ast.DummyNode;
2121
import net.sourceforge.pmd.lang.ast.DummyNodeWithDeprecatedAttribute;
22+
import net.sourceforge.pmd.lang.ast.DummyNodeWithListAndEnum;
2223
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
2324
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
2425

@@ -56,6 +57,54 @@ public void testAttributeDeprecation20() {
5657
testDeprecation(XPathVersion.XPATH_2_0);
5758
}
5859

60+
@Test
61+
public void testListAttributeDeprecation20() {
62+
XPathRule xpr = makeRuleWithList("TestRuleWithListAccess");
63+
loggingRule.clear();
64+
65+
RuleContext ctx = new RuleContext();
66+
ctx.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
67+
DummyNode firstNode = newNodeWithList();
68+
eval(ctx, xpr, firstNode);
69+
assertEquals(1, ctx.getReport().size());
70+
71+
String log = loggingRule.getLog();
72+
assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@List' by XPath rule 'TestRuleWithListAccess'"));
73+
74+
loggingRule.clear();
75+
eval(ctx, xpr, newNodeWithList()); // with another node
76+
assertEquals(2, ctx.getReport().size());
77+
assertEquals("", loggingRule.getLog()); // no addtional warnings
78+
79+
// with another rule forked from the same one (in multithreaded processor)
80+
eval(ctx, xpr.deepCopy(), newNodeWithList());
81+
assertEquals(3, ctx.getReport().size());
82+
assertEquals("", loggingRule.getLog()); // no addtional warnings
83+
84+
// with another rule on the same node, new warnings
85+
XPathRule otherRule = makeRuleWithList("OtherTestRuleWithListAccess");
86+
otherRule.setRuleSetName("rset.xml");
87+
eval(ctx, otherRule, firstNode);
88+
assertEquals(4, ctx.getReport().size());
89+
log = loggingRule.getLog();
90+
assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@List' by XPath rule 'OtherTestRuleWithListAccess' (in ruleset 'rset.xml')"));
91+
}
92+
93+
94+
private XPathRule makeRuleWithList(String name) {
95+
XPathRule xpr = new XPathRule(XPathVersion.XPATH_2_0, "//dummyNode[@List = 'A']");
96+
xpr.setName(name);
97+
xpr.setMessage("list is 'a'");
98+
return xpr;
99+
}
100+
101+
102+
private DummyNode newNodeWithList() {
103+
DummyNode firstNode = new DummyNodeWithListAndEnum(0);
104+
firstNode.setCoords(1, 1, 1, 2);
105+
return firstNode;
106+
}
107+
59108
public void testDeprecation(XPathVersion version) {
60109
XPathRule xpr = makeRule(version, "SomeRule");
61110

Collapse file

‎pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java‎

Copy file name to clipboardExpand all lines: pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import net.sourceforge.pmd.RuleContext;
1414
import net.sourceforge.pmd.lang.LanguageRegistry;
15+
import net.sourceforge.pmd.lang.ast.DummyNodeWithListAndEnum;
1516
import net.sourceforge.pmd.lang.ast.Node;
1617
import net.sourceforge.pmd.properties.PropertyDescriptor;
1718

Collapse file

‎pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQueryTest.java‎

Copy file name to clipboardExpand all lines: pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQueryTest.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.junit.Test;
1414

1515
import net.sourceforge.pmd.RuleContext;
16+
import net.sourceforge.pmd.lang.ast.DummyNodeWithListAndEnum;
1617
import net.sourceforge.pmd.lang.ast.Node;
1718
import net.sourceforge.pmd.properties.PropertyDescriptor;
1819
import net.sourceforge.pmd.properties.PropertyFactory;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.