Add examples
This commit is contained in:
parent
7573fd94d9
commit
abe26203d5
@ -2,7 +2,7 @@ aliases:
|
||||
- &qname_param
|
||||
name: javaQualifiedName
|
||||
type: "xs:string"
|
||||
description: "The qualified name of a class, possibly with pairs of brackets to indicate an array type.
|
||||
description: "The qualified name of a Java class, possibly with pairs of brackets to indicate an array type.
|
||||
Can also be a primitive type name."
|
||||
- &needs_typenode "The context node must be a {% jdoc jast::TypeNode %}"
|
||||
|
||||
@ -13,10 +13,19 @@ langs:
|
||||
- name: typeIs
|
||||
returnType: "xs:boolean"
|
||||
shortDescription: "Tests a node's static type"
|
||||
description: "Returns true if the context node's static type is a subtype of the given type"
|
||||
description: "Returns true if the context node's static Java type is a subtype of the given type.
|
||||
This tests for the resolved type of the Java construct, not the type of the AST node.
|
||||
For example, the AST node for a literal (e.g. `5d`) has type ASTLiteral, however this
|
||||
function will compare the type of the literal (eg here, `double`) against the argument."
|
||||
notes: *needs_typenode
|
||||
parameters:
|
||||
- *qname_param
|
||||
examples:
|
||||
- code: '//FormalParameter[pmd-java:typeIs("java.lang.String[]")]'
|
||||
outcome: "Matches formal parameters of type `String[]` (including vararg parameters)"
|
||||
- code: '//VariableDeclaratorId[pmd-java:typeIs("java.lang.List")]'
|
||||
outcome: "Matches variable declarators of type `List` or any of its subtypes (including e.g. `ArrayList`)"
|
||||
|
||||
|
||||
- name: typeIsExactly
|
||||
returnType: "xs:boolean"
|
||||
@ -27,6 +36,10 @@ langs:
|
||||
notes: *needs_typenode
|
||||
parameters:
|
||||
- *qname_param
|
||||
examples:
|
||||
- code: '//VariableDeclaratorId[pmd-java:typeIsExactly("java.lang.List")]'
|
||||
outcome: "Matches variable declarators of type `List` (but not e.g. `ArrayList`)"
|
||||
|
||||
|
||||
- name: metric
|
||||
returnType: "xs:decimal?"
|
||||
@ -37,11 +50,3 @@ langs:
|
||||
- name: "metricKey"
|
||||
type: "xs:string"
|
||||
description: "The name of an enum constant in {% jdoc jmx::api.JavaOperationMetricKey %} or {% jdoc jmx::api.JavaClassMetricKey %}"
|
||||
|
||||
examples:
|
||||
- code: '//FormalParameter[pmd-java:typeIs("java.lang.String[]")]'
|
||||
outcome: "Matches formal parameters of type `String[]` (including vararg parameters)"
|
||||
- code: '//VariableDeclaratorId[pmd-java:typeIs("java.lang.List")]'
|
||||
outcome: "Matches variable declarators of type `List` or any of its subtypes (including e.g. `ArrayList`)"
|
||||
- code: '//VariableDeclaratorId[pmd-java:typeIsExactly("java.lang.List")]'
|
||||
outcome: "Matches variable declarators of type `List` (but not e.g. `ArrayList`)"
|
||||
|
@ -12,7 +12,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Function name</th>
|
||||
<th>Description</th>
|
||||
<th>Description (click for details)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -51,7 +51,7 @@
|
||||
<dt>Remarks</dt>
|
||||
<dd>{{ fun.notes }}</dd>
|
||||
|
||||
{% unless fun.parameters.size == 0 %}
|
||||
{% if fun.parameters.size > 0 %}
|
||||
|
||||
<dt>Parameters</dt>
|
||||
|
||||
@ -69,28 +69,24 @@
|
||||
</div>
|
||||
</dd>
|
||||
|
||||
{% endunless %}
|
||||
{% endif %}
|
||||
|
||||
{% unless fun.examples.size == 0 %}
|
||||
{% if fun.examples.size > 0 %}
|
||||
|
||||
<dt>Examples</dt>
|
||||
|
||||
<dd>
|
||||
<div style="margin-left: 20px">
|
||||
<dl class="code-examples">
|
||||
{% for example in fun.examples %}
|
||||
<dt><code>{{ example.code }}</code></dt>
|
||||
<dd>{% render %}{{ example.outcome }}{%endrender%}</dd>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
</div>
|
||||
</dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
|
||||
|
||||
<h5>Examples</h5>
|
||||
|
||||
<table>
|
||||
|
||||
{% for example in fun.examples %}
|
||||
|
||||
<tr>
|
||||
<td><code>{{ example.code }}</code></td>
|
||||
<td>{{ example.description }}</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endunless %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -104,17 +100,4 @@
|
||||
|
||||
</div>
|
||||
|
||||
{% unless lang.examples.size == 0 %}
|
||||
|
||||
#### Examples
|
||||
|
||||
|
||||
{% for example in lang.examples %}
|
||||
* `{{ example.code }}`<br/> {{example.outcome }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endunless %}
|
||||
|
||||
|
||||
{% endfor %}
|
||||
|
@ -81,3 +81,6 @@ details[open] summary {
|
||||
font-style: italic;
|
||||
color: darkgray;
|
||||
}
|
||||
.xpath-fun-doc .code-examples dt {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
@ -32,12 +32,11 @@ The version can be specified with the `version` property in the rule definition,
|
||||
|
||||
The default has always been version 1.0.
|
||||
|
||||
As of PMD version 6.13.0, XPath versions 1.0 and the 1.0 compatibility mode are
|
||||
deprecated. XPath 2.0 is superior in many ways, for example for its support for
|
||||
**As of PMD version 6.13.0, XPath versions 1.0 and the 1.0 compatibility mode are
|
||||
deprecated**. XPath 2.0 is superior in many ways, for example for its support for
|
||||
type checking, sequence values, or quantified expressions. For a detailed
|
||||
but approachable review of the features of XPath 2.0 and above, see [the Saxon documentation](https://www.saxonica.com/documentation/index.html#!expressions).
|
||||
|
||||
|
||||
It is recommended that you migrate to 2.0 before 7.0.0, but we expect
|
||||
to be able to provide an automatic migration tool when releasing 7.0.0. The
|
||||
following section describes incompatibilities between 1.0 and 2.0 for PMD rules.
|
||||
|
Loading…
x
Reference in New Issue
Block a user