groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-7936: Improve doco for import aliasing
Date Mon, 12 Sep 2016 22:04:10 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 53b99ebb4 -> 3c97eff65


GROOVY-7936: Improve doco for import aliasing


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3c97eff6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3c97eff6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3c97eff6

Branch: refs/heads/master
Commit: 3c97eff65d60b4b3f378228353eedcd8a48b7bfb
Parents: 53b99eb
Author: paulk <paulk@asert.com.au>
Authored: Tue Sep 13 08:03:52 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Tue Sep 13 08:03:52 2016 +1000

----------------------------------------------------------------------
 src/spec/doc/style-guide.adoc | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/3c97eff6/src/spec/doc/style-guide.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/style-guide.adoc b/src/spec/doc/style-guide.adoc
index f503132..240e047 100644
--- a/src/spec/doc/style-guide.adoc
+++ b/src/spec/doc/style-guide.adoc
@@ -545,27 +545,32 @@ And more generally, types with an `isCase()` method can also decide
whether a va
 
 == Import aliasing
 
-In Java, when using two classes of the same name but from different packages, like `java.util.List`
and `java.awt.List`,
-you can import one class, but have to use a fully-qualified name for the other.
+In Java, when using two classes of the same name but from different packages, like `java.util.List`
+and `java.awt.List`, you can import one class, but have to use a fully-qualified name for
the other.
 
-Also sometimes, in your code, when using often a long class name, and the code becomes a
bit more verbose.
+Also sometimes, in your code, multiple usages of a long class name, can increase verbosity
and
+reduce clarify of the code.
 
 To improve such situations, Groovy features import aliasing:
 
 [source,groovy]
 ----
-import java.util.List as juList
-import java.awt.List as aList
+import java.util.List as UtilList
+import java.awt.List as AwtList
+import javax.swing.WindowConstants as WC
 
-import java.awt.WindowConstants as WC
+UtilList list1 = [WC.EXIT_ON_CLOSE]
+assert list1.size() instanceof Integer
+def list2 = new AwtList()
+assert list2.size() instanceof java.awt.Dimension
 ----
 
-You can also import methods statically:
+You can also use aliasing when importing methods statically:
 
 [source,groovy]
 ----
-import static pkg.SomeClass.foo
-foo()
+import static java.lang.Math.abs as mabs
+assert mabs(-4) == 4
 ----
 
 == Groovy Truth


Mime
View raw message