Hi,
it would be great if someone could give me a hint what I'm missing:
I would like to rewrite a pattern matching if into a if checking the
condition and then doing the necessary cast.
Basicly:
if (o instanceof FancyObject fancy) {
doSomethingWithFancy(fancy);
}
Should become:
if (o instanceof FancyObject) {
FancyObject fancy = (FancyObject) o;
doSomethingWithFancy(fancy);
}
And yes - the intention is to lower the source level from 14+ to 8.
I tried this:
------------------------------
if ($origVar instanceof $targetClass $targetName) {
$body$;
}
=>
if ($origVar instanceof $targetClass) {
$targetClass $targetName = ($targetClass) $origVar;
$body$;
}
;;
------------------------------
But that resulted in an partial rewrite:
------------------------------
public class Mavenproject1 {
public static void main(String[] args) {
Object o = 1;
if(o instanceof Integer i) {
System.out.println("Integer: " + i);
}
}
}
------------------------------
became
------------------------------
public class Mavenproject1 {
public static void main(String[] args) {
Object o = 1;
if(o instanceof $targetClass) {
$targetClass $targetName = ($targetClass) o;
System.out.println("Integer: " + i);
}
}
}
------------------------------
So it was matched and $origVar was picked up correctly, but the other
variables are totally ignored.
What am I missing?!
Greetings
Matthias
---------------------------------------------------------------------
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