Commits

Jan Lahoda  committed 3056dd5

Description of the first two example scripts.

  • Participants
  • Parent commits ef67258

Comments (0)

Files changed (1)

-== Welcome ==
+=Jackpot 3.0 Examples
 
-Welcome to your wiki! This is the default page we've installed for your convenience. Go ahead and edit it.
+==Motivation Example
 
-=== Wiki features ===
+Java test file: {{{ImageUtils.java}}}
+Script file: {{{o.o.u.Utilities.hint}}}
 
-This wiki uses the [[http://www.wikicreole.org/|Creole]] syntax, and is fully compatible with the 1.0 specification.
+Description:
 
-The wiki itself is actually a mercurial repository, which means you can clone it, edit it locally/offline, add images or any other file type, and push it back to us. It will be live immediately.
+In NetBeans there is method {{{Utilities.loadImage(String)}}}. As
+many more image-related methods have been added to Utilities, a new class {{{ImageUtilities}}}
+has been introduced, and the image-related utilities have been put there. The original methods
+have been deprecated and delegate to the new methods. But, how to we support the transition
+from the old methods to the new methods for our API clients? Can't this be done semi-automatically.
 
-Go ahead and try:
+This is where the Jackpot language comes to play: it allows us to easily create a
+custom refactoring that will allow the API clients to easily upgrade their code.
 
+In this case the script is:
 {{{
-$ hg clone https://bitbucket.org/jlahoda/jackpot30-demo-examples/wiki
+org.openide.util.Utilities.loadImage($loc)
+=>
+org.openide.util.ImageUtilities.loadImage($loc)
+;;
 }}}
 
-Wiki pages are normal files, with the .wiki extension. You can edit them locally, as well as creating new ones.
+Where {{{$loc}}} is a variable: it will be bound to anything that will appear in
+the source code at the corresponding place.
 
-=== Syntax highlighting ===
+==Conditions
 
-You can also highlight snippets of text, we use the excellent [[http://www.pygments.org/|Pygments]] library.
+Java test file: {{{ImgIcon.java}}}
+Script file: {{{j.s.ImageIcon.hint}}}
 
-Here's an example of some Python code:
+Description:
 
+One of the utility methods in {{{ImageUtilities}}} is {{{image2Icon}}}, which is a replacement
+for {{{new javax.swing.ImageIcon(Image}}}, which may bypass the icon creation is some cases.
+
+Based on the previous script, we could try to write:
 {{{
-#!python
-
-def wiki_rocks(text):
-    formatter = lambda t: "funky"+t
-    return formatter(text)
+new javax.swing.ImageIcon($image)
+=>
+org.openide.util.ImageUtilities.image2Icon($image)
+;;
 }}}
 
-You can check out the source of this page to see how that's done, and make sure to bookmark [[http://pygments.org/docs/lexers/|the vast library of Pygment lexers]], we accept the 'short name' or the 'mimetype' of anything in there.
+This would work correctly in rewriting:
+{{{
+Image image = ...;
+Icon icon = new javax.swing.ImageIcon(image);
+}}}
+to 
+{{{
+Image image = ...;
+Icon icon = ImageUtilities.image2Icon(image);
+}}}
 
-Have fun!
+But, it would also attempt to rewrite:
+{{{
+String fileName = ...;
+Icon icon = new javax.swing.ImageIcon(fileName);
+}}}
+to 
+{{{
+String fileName = ...;
+Icon icon = ImageUtilities.image2Icon(fileName);
+}}}
+
+which is not correct, and would break the code. We need to specify that the expression
+that will be bound to variable ${{{image}}} needs to be of type {{{java.awt.Image}}}.
+We do that as follows:
+{{{
+new javax.swing.ImageIcon($image) :: $image instanceof java.awt.Image
+=>
+org.openide.util.ImageUtilities.image2Icon($image)
+;;
+}}}
+
+The {{{instanceof}}} is a condition. The conditions are written behind a {{{::}}.
+The warning and fix is used only when the conditions are true.