pmd/docs/_data/xpath_funs.yml

141 lines
5.7 KiB
YAML
Raw Normal View History

2020-01-24 18:39:58 +01:00
# This file describes custom XPath functions per language
# This is rendered using _includes/custom/xpath_fun_doc.html
2019-04-05 14:13:39 +02:00
aliases:
- &qname_param
name: javaQualifiedName
type: "xs:string"
2019-04-07 18:00:02 +02:00
description: "The qualified name of a Java class, possibly with pairs of brackets to indicate an array type.
2019-04-05 14:13:39 +02:00
Can also be a primitive type name."
2022-03-20 13:09:48 +01:00
- &node_param
name: element
type: "xs:element"
description: "Any element node"
2019-04-05 14:13:39 +02:00
- &needs_typenode "The context node must be a {% jdoc jast::TypeNode %}"
- &coord_fun_note |
The function is not context-dependent, but takes a node as its first parameter.
The function is only available in XPath 2.0.
2022-03-22 19:34:13 +01:00
- &needs_node_ctx "The requires the context node to be an element"
2019-04-05 14:13:39 +02:00
2019-03-06 01:29:53 +01:00
langs:
2022-03-22 19:46:21 +01:00
- name: "All languages"
ns: "pmd"
2022-03-22 19:46:21 +01:00
header: "Functions available to all languages are in the namespace `pmd`."
funs:
- name: fileName
returnType: "xs:string"
2022-03-20 13:09:48 +01:00
shortDescription: "Returns the simple name of the current file"
2022-03-22 19:34:13 +01:00
description: |
Returns the current simple file name, without path but including the extension.
This can be used to write rules that check file naming conventions.
2022-03-20 13:09:48 +01:00
2022-03-22 19:34:13 +01:00
since: 6.38.0
notes: *needs_node_ctx
examples:
- code: "//b[pmd:fileName() = 'Foo.xml']"
outcome: "Matches any `<b>` tags in files called `Foo.xml`."
- name: startLine
2022-03-20 13:09:48 +01:00
returnType: "xs:int"
parameters:
- *node_param
shortDescription: "Returns the start line of the given node"
2022-03-22 19:34:13 +01:00
description: |
Returns the line where the node starts in the source file.
Line numbers are 1-based.
2022-03-20 13:09:48 +01:00
2022-03-22 19:34:13 +01:00
since: 6.44.0
notes: *coord_fun_note
2022-03-20 13:09:48 +01:00
examples:
- code: "//b[pmd:startLine(.) > 5]"
2022-03-20 13:09:48 +01:00
outcome: "Matches any `<b>` node which starts after the fifth line."
- name: endLine
returnType: "xs:int"
parameters:
- *node_param
shortDescription: "Returns the end line of the given node"
2022-03-22 19:34:13 +01:00
description: |
Returns the line where the node ends in the source file.
Line numbers are 1-based.
2022-03-20 13:09:48 +01:00
2022-03-22 19:34:13 +01:00
since: 6.44.0
notes: *coord_fun_note
2022-03-20 13:09:48 +01:00
examples:
- code: "//b[pmd:endLine(.) == pmd:startLine(.)]"
2022-03-20 13:09:48 +01:00
outcome: "Matches any `<b>` node which doesn't span more than one line."
- name: startColumn
returnType: "xs:int"
parameters:
- *node_param
shortDescription: "Returns the start column of the given node (inclusive)"
description: |
Returns the column number where the node starts in the source file.
Column numbers are 1-based. The start column is inclusive.
since: 6.44.0
notes: *coord_fun_note
examples:
- code: "//b[pmd:startColumn(.) = 1]"
outcome: "Matches any `<b>` node which starts on the first column of a line"
- name: endColumn
returnType: "xs:int"
parameters:
- *node_param
shortDescription: "Returns the end column of the given node (exclusive)"
description: |
Returns the column number where the node ends in the source file.
Column numbers are 1-based. The end column is exclusive.
since: 6.44.0
notes: *coord_fun_note
examples:
- code: "//b[pmd:startLine(.) = pmd:endLine(.) and pmd:endColumn(.) - pmd:startColumn(.) = 1]"
outcome: "Matches any `<b>` node which spans exactly one character"
2019-03-06 01:29:53 +01:00
- name: "Java"
ns: "pmd-java"
funs:
- name: typeIs
returnType: "xs:boolean"
2019-04-05 14:13:39 +02:00
shortDescription: "Tests a node's static type"
2019-04-07 18:00:02 +02:00
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."
2019-04-05 14:13:39 +02:00
notes: *needs_typenode
2019-03-06 01:29:53 +01:00
parameters:
2019-04-05 14:13:39 +02:00
- *qname_param
2019-04-07 18:00:02 +02:00
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`)"
2019-03-06 01:29:53 +01:00
- name: typeIsExactly
returnType: "xs:boolean"
2019-04-05 14:13:39 +02:00
shortDescription: "Tests a node's static type, ignoring subtypes"
2019-03-06 01:29:53 +01:00
description: "Returns true if the context node's static type is exactly the given type.
In particular, returns false if the context node's type is
a subtype of the given type."
2019-04-05 14:13:39 +02:00
notes: *needs_typenode
parameters:
- *qname_param
2019-04-07 18:00:02 +02:00
examples:
- code: '//VariableDeclaratorId[pmd-java:typeIsExactly("java.lang.List")]'
outcome: "Matches variable declarators of type `List` (but not e.g. `ArrayList`)"
2019-03-06 01:29:53 +01:00
- name: metric
returnType: "xs:decimal?"
2019-04-05 14:13:39 +02:00
shortDescription: "Computes and returns the value of a metric"
2019-03-06 01:29:53 +01:00
description: "Returns the value of the metric as evaluated on the context node"
notes: "The context node must be a {% jdoc jast::ASTAnyTypeDeclaration %} or a {% jdoc jast::MethodLikeNode %}"
parameters:
- name: "metricKey"
2019-03-06 02:22:36 +01:00
type: "xs:string"
description: "The name of an enum constant in {% jdoc jmx::api.JavaOperationMetricKey %} or {% jdoc jmx::api.JavaClassMetricKey %}"