GROOVY-6114: Immutable AST transformation may generate invalid bytecode in combination with @CompileStatic
GROOVY-6119: If an explicit map constructor is provided, the type checker doesn't use it
GROOVY-6112: Support AST transforms on the field generated by @Field in scripts
minor refactor
GROOVY-6121: Object[].groupBy is not defined
GROOVY-5449: @Immutable should not throw NPE if an unmanageable type is used
GROOVY-4663: fix for using the local Preferences instance in groovyConsole unit test
changing java files within main/groovy into groovy files.
This is for consistency and for development ease

Note I removed the "assert parent != null",
which seemed to have been unjustified anyway (Code does null checks)
Extract class shared between Main and Groovy
Groovysh shell completion tests
changed a few asserts to explicit null checks and changed visibility of Groovysh.reader to allow easier unit testing
do not show lines of exception trace related to evaluation script.
Those get old very fast, and take away 2 lines of screen for zero value.
verbose or debug settings still display them
robust error handler call
code Style refactorings, mostly allows @CompileStatic and @TypeChecked

This declares types in several places, does some casting too.
Gave unique name to iterators in closures

Could not fix all Type checking and static compile problems,
due to weird hacks around command registry

Not including @CompileStatic and @TypeChecked annotations
because maybe this is to be backported to groovy 1.x, and also
I did not see other code here use them
refactoring: static compile fix: displayBuffer called from within DisplayCommand cannot be private
refactoring: fix static check Runtime Error:
Caught: BUG! exception in phase 'class generation'
On receiver: history.historyList with message: getAt and arguments: id

Not sure what caused this, really
ReflectionCompletor raises Exceptions when evaluation failed

e.g. when completing "println(java."
shorter Error when user users a var he has not defined
unused var
Colors need to be set via fg/bg, else this happens:
an =  Ansi.ansi().a(INTENSITY_BOLD).a(GREEN).a("Hello")
===> GREENHello
display Arrays pretty.

groovy:000> ["foo"].toArray()
Before:  ===> [Ljava.lang.Object;
After:   ===> [foo]

groovy:000> Object.fields
Before:  ===> [Ljava.lang.Object;@68a48abd
After:   ===> [] (class java.lang.reflect.Field)
using io on abnormalShutdown causes java.lang.IllegalStateException: Shutdown in progress
and breaks Terminal on linux

Can be tested by pressinc Control-C