[doc] Update language module docs (apex, java, visualforce)

This commit is contained in:
Andreas Dangel
2023-08-31 17:12:21 +02:00
parent 512d6cbb8d
commit 291a5aa956
6 changed files with 70 additions and 11 deletions

View File

@ -142,7 +142,9 @@ definitely don't come for free. It is much effort and requires perseverance to i
* For a minimal implementation, it just needs to return a parser *(see step #6)*.
* It can be used to provide other features for your language like
* violation suppression logic
* violation decorators, to add additional language specific information to the created violations
* {% jdoc core::reporting::ViolationDecorator %}s, to add additional language specific information to the
created violations. The [Java language module](pmd_languages_java.html#violation-decorators) uses this to
provide the method name or class name, where the violation occurred.
* metrics
* custom XPath functions

View File

@ -81,7 +81,9 @@ definitely don't come for free. It is much effort and requires perseverance to i
* For a minimal implementation, it just needs to return a parser *(see step #5)*.
* It can be used to provide other features for your language like
* violation suppression logic
* violation decorators, to add additional language specific information to the created violations
* {% jdoc core::reporting::ViolationDecorator %}s, to add additional language specific information to the
created violations. The [Java language module](pmd_languages_java.html#violation-decorators) uses this to
provide the method name or class name, where the violation occurred.
* metrics (see below "Optional features")
* custom XPath functions
* See `VmHandler` class as an example

View File

@ -2,14 +2,41 @@
title: Apex support
permalink: pmd_languages_apex.html
author: Clément Fournier
last_updated: March 2021 (7.0.0)
last_updated: September 2023 (7.0.0)
tags: [languages]
summary: "Apex-specific features and guidance"
---
Implementation: {% jdoc apex::lang.apex.ApexLanguageModule %}
Name: Apex
id: apex
PMD: yes
CPD: yes
{% include warning.html content="Todo for pmd 7" %}
### Metrics framework
## Metrics framework
In order to use code metrics in Java, use the metrics constants in {% jdoc apex::lang.apex.metrics.ApexMetrics %},
In order to use code metrics in Apex, use the metrics constants in {% jdoc apex::lang.apex.metrics.ApexMetrics %},
together with {% jdoc core::lang.metrics.MetricsUtil %}.
## Multifile Analysis
See {% jdoc apex::lang.apex.multifile.ApexMultifileAnalysis %}
Uses [ApexLink](https://github.com/nawforce/apex-link), see also [Apexlink POC #2830](https://github.com/pmd/pmd/pull/2830).
Note: ApexLink new home: https://github.com/apex-dev-tools
Used for rule {% rule apex/design/UnusedMethod %}
## Language Properties
See [Apex language properties](pmd_languages_configuration.html#apex-language-properties)
## Parser
We use Jorje...
## Limitations

View File

@ -82,3 +82,15 @@ public Object visit(ASTMethodDeclaration node, Object data) {
```
The Javadocs are the reference documentation.
## Violation Decorators
Violations reported are the same for all languages, but languages can opt in to provide more details.
Java does this by adding the following additional information for each reported violation:
* {% jdoc core::RuleViolation#VARIABLE_NAME %}
* {% jdoc core::RuleViolation#METHOD_NAME %}
* {% jdoc core::RuleViolation#CLASS_NAME %}
* {% jdoc core::RuleViolation#PACKAGE_NAME %}
You can access these via {% jdoc core::RuleViolation#getAdditionalInfo() %}

View File

@ -2,9 +2,19 @@
title: Visualforce Support
permalink: pmd_languages_visualforce.html
author: Andreas Dangel
last_updated: October 2021
last_updated: September 2023
---
Implementation: {% jdoc visualforce::lang.vf.VfLanguageModule %}
Name: Salesforce VisualForce
id: vf
PMD: yes
CPD: yes
## Language Properties
See [VisualForce language properties](pmd_languages_configuration.html#visualforce-language-properties)
## Type resolution
Since PMD 6.30.0 support for type resolution has been added.
@ -13,16 +23,22 @@ The Visualforce AST now can resolve the data type of Visualforce expressions tha
Apex Controller properties and Custom Object fields. This feature improves the precision of existing rules,
like {% rule vf/security/VfUnescapeEl %}.
This can be configured using two environment variables:
This can be configured using two language properties, which can be set as environment variables:
* `PMD_VF_APEXDIRECTORIES`: Comma separated list of directories for Apex classes. Absolute or relative
* `PMD_VF_APEX_DIRECTORIES`: Comma separated list of directories for Apex classes. Absolute or relative
to the Visualforce directory. Default is `../classes`. Specifying an empty string will disable data type
resolution for Apex Controller properties.
* `PMD_VF_OBJECTSDIRECTORIES`: Comma separated list of directories for Custom Objects. Absolute or relative
* `PMD_VF_OBJECTS_DIRECTORIES`: Comma separated list of directories for Custom Objects. Absolute or relative
to the Visualforce directory. Default is `../objects`. Specifying an empty string will disable data type
resolution for Custom Object fields.
{% include warning.html content="
These env vars have changed from PMD 6 to PMD 7:
* `PMD_VF_APEXDIRECTORIES` ➡️ `PMD_VF_APEX_DIRECTORIES`
* `PMD_VF_OBJECTSDIRECTORIES` ➡️ `PMD_VF_OBJECTS_DIRECTORIES`
"%}
This feature is experimental, in particular, expect changes to the way the configuration is specified.
We'll probably extend the CLI instead of relying on environment variables in a future version.

View File

@ -19,7 +19,7 @@ public class VfLanguageProperties extends LanguagePropertyBundle {
/**
* Directory that contains Apex classes that may be referenced from a Visualforce page.
*
* <p>Env variable is {@code PMD_VF_APEXDIRECTORIES}.
* <p>Env variable is {@code PMD_VF_APEX_DIRECTORIES}.
*/
public static final PropertyDescriptor<List<String>> APEX_DIRECTORIES_DESCRIPTOR =
PropertyFactory.stringListProperty("apexDirectories")
@ -30,7 +30,7 @@ public class VfLanguageProperties extends LanguagePropertyBundle {
/**
* Directory that contains Object definitions that may be referenced from a Visualforce page.
*
* <p>Env variable is {@code PMD_VF_OBJECTSDIRECTORIES}.
* <p>Env variable is {@code PMD_VF_OBJECTS_DIRECTORIES}.
*/
public static final PropertyDescriptor<List<String>> OBJECTS_DIRECTORIES_DESCRIPTOR =
PropertyFactory.stringListProperty("objectsDirectories")