This is an automated email from the ASF dual-hosted git repository.
geertjan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans-website.git
The following commit(s) were added to refs/heads/master by this push:
new de7625b imports and custom conditions
new 82f42b6 Merge pull request #565 from mbien/patch-1
de7625b is described below
commit de7625beecc498cc45473ae557340a3b888603dd
Author: Michael Bien <[email protected]>
AuthorDate: Sat Oct 23 03:51:13 2021 +0200
imports and custom conditions
added examples for imports and custom conditions. Mostly taken from the old
bitbucket wiki, minor updates.
---
.../src/content/jackpot/HintsFileFormat.asciidoc | 53 ++++++++++++++++++++--
1 file changed, 49 insertions(+), 4 deletions(-)
diff --git a/netbeans.apache.org/src/content/jackpot/HintsFileFormat.asciidoc
b/netbeans.apache.org/src/content/jackpot/HintsFileFormat.asciidoc
index 831d13d..f57428d 100644
--- a/netbeans.apache.org/src/content/jackpot/HintsFileFormat.asciidoc
+++ b/netbeans.apache.org/src/content/jackpot/HintsFileFormat.asciidoc
@@ -32,9 +32,10 @@ The rules file consists of any number of transformation
rules.
The rule is defined as follows:
[source,java]
----
- <pattern>
- => <fix-pattern>
- => <fix-pattern>
+"description text":
+ <pattern> :: <rule-condition>
+ => <fix-pattern> :: <fix-condition>
+ => <fix-pattern> :: <fix-condition>
;;
----
@@ -63,6 +64,8 @@ to:
Note: `$1` is a variable, explained in the <<variables>> section.
+Note: conditions are explained in the <<conditions>> section.
+
Note: batch refactoring will typically use only the first applicable fix
patterns of each applicable rule.
== Patterns
@@ -313,7 +316,32 @@ Note: Special variable `$_` represents the whole matching
region.
=== Custom Conditions
-TBD
+The following rule finds variables of the type `com.whatever.Option` and name
"foo" or "bar" and renames them.
+
+[source,java]
+----
+<?
+import java.util.Set;
+?>
+
+ $opt :: $opt instanceof com.whatever.Option && matchName($opt)
+=> $optNew :: changeVariableName($opt, $optNew)
+;;
+
+<?
+ public boolean matchName(Variable v) {
+ return names.contains(context.name(v));
+ }
+
+ public boolean changeVariableName(Variable v, Variable target) {
+ String name = context.name(v);
+ context.createRenamed(v, target, name + "Renamed");
+ return true;
+ }
+
+ private final static Set<String> names = Set.of("foo", "bar");
+?>
+----
== Display Names and Localization
@@ -322,6 +350,23 @@ TBD
[[custom-imports]]
== Custom Imports
+[source,java]
+----
+<?
+import java.util.LinkedList;
+import java.util.ArrayList;
+?>
+
+ new LinkedList()
+=> new ArrayList()
+;;
+
+ LinkedList $0;
+=> ArrayList $0;
+;;
+----
+
+
== Notable Patterns
=== Catch Pattern
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists