Hi Jan,

thank you for confirming and having a look at this. I tried to wrap my
head around the jackpot execution, but I got lost somewhere in the java
compiler code. I'm looking forward to see what a magic is necessary to
fix this ;-)

Greetings

Matthias

Am Samstag, dem 27.11.2021 um 23:11 +0100 schrieb Jan Lahoda:
> Hi,
> 
> That rule should be working - a more general rule would be something like:
> 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



Reply via email to