Skip to content

Commit 222f475

Browse files
committed
MTA-4637: Pattern matching docs need urgent improvements (quick fix)
Signed-off-by: A.Arnold <[email protected]>
1 parent 2c90f35 commit 222f475

File tree

2 files changed

+77
-33
lines changed

2 files changed

+77
-33
lines changed

docs/topics/create-yaml-rule.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ _Example_
173173
when:
174174
java.referenced:
175175
location: PACKAGE
176-
pattern: org.jboss.*
176+
pattern: org.jboss*
177177
----
178178

179179
. Create an `AND` or `OR` condition

docs/topics/yaml-rule-structure-syntax.adoc

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,16 @@ when:
352352

353353
===== `java` provider
354354

355-
The `java` provider analyzes Java source code.
355+
The Language Server used by the Java provider is Eclipse’s JDT Language Server (JDTLS). Internally, the JDTLS uses the Eclipse Java Development Toolkit, which includes utilities for searching code in projects.
356356

357357
This provider has the following capabilities:
358358

359359
* `referenced`
360360
* `dependency`
361361

362+
In the `pattern` element of a `java.referenced` condition, you can search through application code by using these utilities. For more details, see link:https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fsearch%2FSearchPattern.html&anchor=createPattern[Class SearchPattern], which contains all the information for building these patterns for `createPattern(String, int, int, int)`.
363+
364+
362365
.`referenced`
363366

364367
The `referenced` capability enables the provider to find references in the source code. This capability takes three input parameters: `pattern`, `location`, and `annotated`.
@@ -371,49 +374,90 @@ when:
371374
location: "<location>" <2>
372375
annotated: "<annotated>" <3>
373376
----
374-
<1> A regular expression pattern to match, for example, `org.kubernetes.*`.
377+
<1> A regular expression pattern to match, for example, `org.kubernetes*`.
375378
<2> Specifies the exact location where the pattern needs to be matched, for example, `IMPORT`.
376379
<3> Checks for specific annotations and their elements, such as name and value in the Java code using a query. For example, the following query matches the Bean(url = “http://www.example.com”) annotation in the method.
380+
381+
382+
.Examples
383+
384+
* Search for any class under the `javax.xml` package, occurring in any
385+
location:
377386
+
378-
[source,terminal]
387+
[source,yaml]
379388
----
380-
annotated:
381-
pattern: org.framework.Bean
382-
elements:
383-
- name: url
384-
value: "http://www.example.com"
389+
java.referenced:
390+
pattern: javax.xml*
385391
----
392+
+
393+
[WARNING]
394+
====
395+
When matching against packages, as in the previous example, the asterisk must not be after a dot.
386396
387-
The supported locations are the following:
397+
For example:
388398
389-
* `CONSTRUCTOR_CALL`
390-
* `TYPE`
391-
* `INHERITANCE`
392-
* `METHOD_CALL`
393-
* `ANNOTATION`
394-
* `IMPLEMENTS_TYPE`
395-
* `ENUM_CONSTANT`
396-
* `RETURN_TYPE`
397-
* `IMPORT`
398-
* `VARIABLE_DECLARATION`
399-
* `FIELD`
400-
* `METHOD`
399+
* `pattern: javax.xml*`
400+
+
401+
and not:
401402
402-
.`dependency`
403+
* `pattern: javax.xml.*`
404+
====
403405

404-
The `dependency` capability enables the provider to find dependencies for a given application. {ProductShortName} generates a list of the application's dependencies, and you can use this capability to query the list and check whether a certain dependency exists for the application within a given range of the dependency's versions.
406+
* Search for method declarations that return `java.lang.String`:
407+
+
408+
[source,yaml]
409+
----
410+
java.referenced:
411+
location: METHOD
412+
pattern: '* java.lang.String'
413+
----
405414

406-
[source,terminal]
415+
* Search for a method named "`method`" declared on `org.konveyor.MyClass`
416+
that returns a `List` of a type that extends `java.lang.String`:
417+
+
418+
[source,yaml]
407419
----
408-
when:
409-
java.dependency:
410-
name: "<dependency_name>" <1>
411-
upperbound: "<version_string>" <2>
412-
lowerbound: "<version_string>" <3>
420+
java.referenced:
421+
location: METHOD
422+
pattern: 'org.konveyor.Myclass.method(*) java.util.List<? extends java.lang.String>'
413423
----
414-
<1> Name of the dependency to search for.
415-
<2> Upper bound on the version of the dependency.
416-
<3> Lower bound on the version of the dependency.
424+
425+
* Search for a class that implements `java.util.List`:
426+
+
427+
[source,yaml]
428+
----
429+
java.referenced:
430+
location: IMPLEMENTS_TYPE
431+
pattern: java.util.List
432+
----
433+
434+
// Module included in the following assemblies:
435+
//
436+
// * docs/rules-development-guide/master.adoc
437+
438+
:_mod-docs-content-type: REFERENCE
439+
[id="yaml-custom-variables_{context}"]
440+
= Custom variables
441+
442+
Provider conditions can have associated custom variables. You can use custom variables to capture relevant information from the matched line in the source code. The values of these variables are interpolated with data matched in the source code.
443+
444+
These values can be used to generate detailed template messages in a rule's action (see xref:yaml-rule-actions_{context}[Message actions]). They can be added to a rule in the `customVariables` field:
445+
446+
[source,yaml]
447+
----
448+
- ruleID: lang-ref-004
449+
customVariables:
450+
- pattern: '([A-z]+)\.get\(\)' # <1>
451+
name: VariableName # <2>
452+
message: "Found generic call - {{ VariableName }}" # <3>
453+
when:
454+
java.referenced:
455+
location: METHOD_CALL
456+
pattern: com.example.apps.GenericClass.get
457+
----
458+
<1> `pattern`: A regular expression pattern that is matched on the source code line when a match is found.
459+
<2> `name`: The name of the variable that can be used in templates.
460+
<3> `message`: A template for a message using a custom variable.
417461

418462
===== `go` provider
419463

0 commit comments

Comments
 (0)