On Sat, Nov 27, 2021 at 11:11 PM Jan Lahoda <[email protected]> wrote:
> Hi,
>
> That rule should be working - a more general rule would be something like:
>
I meant: that is a rule that should do what you want, and the fact it is
not working is a bug.
Jan
if ($expr instanceof $type $name) {
> $stmts$;
> } else $else$;
> =>
> if ($expr instanceof $type) {
> $type $name = ($type) $expr);
> $stmts$;
> } else $else$;
> ;;
>
> I am working on it.
>
> Jan
>
>
> On Wed, Nov 24, 2021 at 12:54 AM Michael Bien <[email protected]> wrote:
>
>> Hi Matthias,
>>
>> looks like jackpot doesn't understand
>>
>> if (o instanceof Integer i)
>>
>> yet.
>>
>> I tested with:
>>
>> if ($origVar instanceof $T $t) {
>> }
>> =>
>> if ($origVar instanceof $T $t) {
>> }
>> ;;
>>
>> and it never initialized $T or $t.
>>
>>
>> There is a "Changing source level to 1.8" line in the log, I saw that
>> before but never had time to investigate, its possible that jackpot
>> can't match anything beyond 8 language level because of that (if at all
>> related to this issue).
>>
>> another thing what jackpot doesn't understand is the short form of
>> lambdas, e.g:
>> $stream.mapToObj(($x) -> $x)
>>
>> never matches anything
>>
>> -michael
>>
>> On 23.11.21 23:37, Matthias Bläsing wrote:
>> > 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
>> >
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>>
>>
>>