Update again
This commit is contained in:
@ -1,3 +1,6 @@
|
|||||||
|
# This file describes custom XPath functions per language
|
||||||
|
# This is rendered using _includes/custom/xpath_fun_doc.html
|
||||||
|
|
||||||
aliases:
|
aliases:
|
||||||
- &qname_param
|
- &qname_param
|
||||||
name: javaQualifiedName
|
name: javaQualifiedName
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% assign panel_id = 8 | random_alphabetic %}
|
|
||||||
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h4 class="panel-title">
|
|
||||||
<a class="noCrossRef accordion-toggle" data-toggle="collapse" data-parent="#accordion"
|
|
||||||
href="#{{ panel_id }}">{{ include.question | render_markdown }}</a>
|
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
<div id="{{ panel_id }}" class="panel-collapse collapse noCrossRef">
|
|
||||||
<div class="panel-body">
|
|
||||||
{{ include.answer | render_markdown }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1,6 +1,5 @@
|
|||||||
require 'pp'
|
|
||||||
#
|
#
|
||||||
# Tags to create a complex object inline in JSON.
|
# Apply a second pass of rendering on a block
|
||||||
#
|
#
|
||||||
class RenderBlock < Liquid::Block
|
class RenderBlock < Liquid::Block
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 249 KiB After Width: | Height: | Size: 129 KiB |
BIN
docs/images/userdocs/designer-overview.png
Normal file
BIN
docs/images/userdocs/designer-overview.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 101 KiB |
@ -189,3 +189,4 @@ the sequence *contains* `@Image`. That is, the above rule will report all variab
|
|||||||
named `foo` or `bar`. All other XPath 2.0 [functions operating on sequences](https://www.w3.org/TR/xpath-functions/#sequence-functions)
|
named `foo` or `bar`. All other XPath 2.0 [functions operating on sequences](https://www.w3.org/TR/xpath-functions/#sequence-functions)
|
||||||
are supported.
|
are supported.
|
||||||
|
|
||||||
|
{%include tip.html content="You can also [define properties directly in the designer](pmd-userdocs_designer_reference.html#rule-properties)" %}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: Intro to writing PMD rules
|
title: Introduction to writing PMD rules
|
||||||
tags: [extending, userdocs, getting_started]
|
tags: [extending, userdocs, getting_started]
|
||||||
summary: "Writing your own PMD rules TODO"
|
summary: "Writing your own PMD rules TODO"
|
||||||
last_updated: July 2018 (6.6.0)
|
last_updated: July 2018 (6.6.0)
|
||||||
@ -7,15 +7,14 @@ permalink: pmd_userdocs_extending_writing_rules_intro.html
|
|||||||
author: Clément Fournier <clement.fournier76@gmail.com>
|
author: Clément Fournier <clement.fournier76@gmail.com>
|
||||||
---
|
---
|
||||||
|
|
||||||
|
PMD is a framework to perform code analysis. You can create your own rules to
|
||||||
## Why write custom rules?
|
check for patterns specific to your codebase, or the coding practices of your
|
||||||
|
team.
|
||||||
TODO
|
|
||||||
|
|
||||||
## How rules work: the AST
|
## How rules work: the AST
|
||||||
|
|
||||||
Before running rules, PMD parses the source file into a data structure called an
|
Before running rules, PMD parses the source file into a data structure called an
|
||||||
*abstract syntax tree* (AST). This tree represents the syntactic structure of the
|
**abstract syntax tree (AST)**. This tree represents the syntactic structure of the
|
||||||
code, and encodes syntactic relations between source code elements. For instance,
|
code, and encodes syntactic relations between source code elements. For instance,
|
||||||
in Java, method declarations belong to a class: in the AST, the nodes representing
|
in Java, method declarations belong to a class: in the AST, the nodes representing
|
||||||
method declarations will be descendants of a node representing the declaration of
|
method declarations will be descendants of a node representing the declaration of
|
||||||
@ -74,7 +73,9 @@ Each PMD language has its own set of such classes, and its own rules about how
|
|||||||
these classes relate to one another, based on the grammar of the language. For
|
these classes relate to one another, based on the grammar of the language. For
|
||||||
example, all Java AST nodes extend {% jdoc java::lang.java.ast.JavaNode %}.
|
example, all Java AST nodes extend {% jdoc java::lang.java.ast.JavaNode %}.
|
||||||
|
|
||||||
The structure of the AST can be discovered by using the [Rule Designer](pmd_userdocs_extending_designer_reference.html).
|
The structure of the AST can be discovered through
|
||||||
|
* the [Rule Designer](pmd_userdocs_extending_designer_reference.html#ast-inspection)
|
||||||
|
* the [AST dump feature](pmd_devdocs_experimental_ast_dump.html)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,24 +140,3 @@ TODO
|
|||||||
|
|
||||||
You can notice that your XPath expression ends up inside a [property](pmd_userdocs_configuring_rules.html#rule-properties)
|
You can notice that your XPath expression ends up inside a [property](pmd_userdocs_configuring_rules.html#rule-properties)
|
||||||
of a rule of type XPathRule, which is how XPath rules are implemented.
|
of a rule of type XPathRule, which is how XPath rules are implemented.
|
||||||
|
|
||||||
### Defining rule properties
|
|
||||||
|
|
||||||
Some time later, your boss' boss decides he doesn't want to be called short in Java
|
|
||||||
too, and would like you to add him to the rule. There are several ways to do that,
|
|
||||||
but you decide to use a rule property to make your rule extensible. Doing that
|
|
||||||
directly in the XML is [explained on that page](pmd_userdocs_extending_defining_properties.html#for-xpath-rules),
|
|
||||||
and we'll explain here how to do that in the designer.
|
|
||||||
|
|
||||||
The table to the left of the zone (3) in the screenshot above is a list of
|
|
||||||
properties defined for your rule.
|
|
||||||
Right-clicking the table and selecting "Add property..", you may add a property of
|
|
||||||
type `List[String]` to represent your boss names. You can then use it in your XPath
|
|
||||||
query with a dollar prefix, i.e.
|
|
||||||
|
|
||||||
```xpath
|
|
||||||
//VariableDeclaratorId[@Image = $bossNames and ../../Type[@TypeImage = "short"]]
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
{% include note.html content="Using a property of type `List[String]` requires you to use XPath 2.0" %}
|
|
||||||
|
Reference in New Issue
Block a user