Repository: incubator-groovy Updated Branches: refs/heads/GROOVY_2_4_X e80097972 -> a1436a2b0
Update core-program-structure.adoc (closes #64) - Added why the packages are imported by defaults and also removed the 6 part as two classes are also imported. - Changed the star import content as that was rendered as bold on the page. - is instead of it Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/a1436a2b Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/a1436a2b Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/a1436a2b Branch: refs/heads/GROOVY_2_4_X Commit: a1436a2b0635d0007ba9319551ab74a69c32b592 Parents: e800979 Author: Aseem Bansal <aseemban...@live.com> Authored: Sat Jul 18 18:01:53 2015 +0530 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Sat Aug 1 12:19:48 2015 +0200 ---------------------------------------------------------------------- src/spec/doc/core-program-structure.adoc | 12 ++++++++---- src/spec/test/ScriptsAndClassesSpecTest.groovy | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/a1436a2b/src/spec/doc/core-program-structure.adoc ---------------------------------------------------------------------- diff --git a/src/spec/doc/core-program-structure.adoc b/src/spec/doc/core-program-structure.adoc index 317eaba..9f66fe2 100644 --- a/src/spec/doc/core-program-structure.adoc +++ b/src/spec/doc/core-program-structure.adoc @@ -56,7 +56,9 @@ Default imports are the imports that Groovy language provides by default. For ex include::{projectdir}/src/spec/test/PackageTest.groovy[tags=default_import,indent=0] ---- -The same code in Java needs an import statement to `Date` class like this: ++import java.util.Date++. Groovy by default imports these classes for you. There are six packages that groovy imports for you, they are: +The same code in Java needs an import statement to `Date` class like this: ++import java.util.Date++. Groovy by default imports these classes for you. + +The below imports are added by groovy for you: [source,groovy] ---- @@ -70,6 +72,8 @@ import java.math.BigInteger import java.math.BigDecimal ---- +This is done because the classes from these packages are most commonly used. By importing these boilerplate code is reduced. + === Simple import A simple import is an import statement where you fully define the class name along with the package. For example the import statement ++import groovy.xml.MarkupBuilder++ in the code below is a simple import which directly refers to a class inside a package. @@ -81,14 +85,14 @@ include::{projectdir}/src/spec/test/PackageTest.groovy[tags=import_statement,ind === Star import -Groovy, like Java, provides a special way to import all classes from a package using `*`, a so called Star import. `MarkupBuilder` is a class which is in package `groovy.xml`, alongside another class called `StreamingMarkupBuilder`. In case you need to use both classes, you can do: +Groovy, like Java, provides a special way to import all classes from a package using `*`, the so called star import. `MarkupBuilder` is a class which is in package `groovy.xml`, alongside another class called `StreamingMarkupBuilder`. In case you need to use both classes, you can do: [source,groovy] ---- include::{projectdir}/src/spec/test/PackageTest.groovy[tags=multiple_import,indent=0] ---- -That's perfectly valid code. But with a `*` import, we can achieve the same effect with just one line, where `*` imports all the classes under package `groovy.xml`: +That's perfectly valid code. But with a `*` import, we can achieve the same effect with just one line. The star imports all the classes under package `groovy.xml`: [source,groovy] ---- @@ -203,7 +207,7 @@ include::{projectdir}/src/spec/test/ScriptsAndClassesSpecTest.groovy[tags=groovy <1> The `Main` class extends the `groovy.lang.Script` class <2> `groovy.lang.Script` requires a `run` method returning a value <3> the script body goes into the `run` method -<4> the `main` method it automatically generated +<4> the `main` method is automatically generated <5> and delegates the execution of the script on the `run` method If the script is in a file, then the base name of the file is used to determine the name of the generated script class. http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/a1436a2b/src/spec/test/ScriptsAndClassesSpecTest.groovy ---------------------------------------------------------------------- diff --git a/src/spec/test/ScriptsAndClassesSpecTest.groovy b/src/spec/test/ScriptsAndClassesSpecTest.groovy index 4ae6358..0364387 100644 --- a/src/spec/test/ScriptsAndClassesSpecTest.groovy +++ b/src/spec/test/ScriptsAndClassesSpecTest.groovy @@ -52,7 +52,7 @@ class ScriptsAndClassesSpecTest extends GroovyTestCase { assertScript ''' // tag::method_in_script[] int fib(int n) { - n<2?1:fib(n-1)+fib(n-2) + n < 2 ? 1 : fib(n-1) + fib(n-2) } assert fib(10)==89 // end::method_in_script[]