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
Robustness: All Throwables during completion must be handled, unless in debug mode
refactoring code Style, fixes indentation, "if" with brackets,
unnecessary var, and no unnecessary call to getProperty
better groovish reactions to bad functions.

Before:

groovy:000> show
ERROR org.codehaus.groovy.tools.shell.CommandException:
Command 'show' requires at least one argument
        at java_lang_Runnable$run.call (Unknown Source)
groovy:000> show foo
ERROR org.codehaus.groovy.tools.shell.CommandException:
Unknown function name: foo
        at java_lang_Runnable$run.call (Unknown Source)

After:

groovy:000> show
Command 'show' requires at least one argument of [variables, classes, imports, preferences, all]
groovy:000> show foo
Unknown function name: 'foo'. Valid arguments: [variables, classes, imports, preferences, all]
error message when invoking record with too many arguments
Refactor: CodeStyle ComplexCommandSupport
Also small fix: do_all returned "all" as well, probably not intended

functions field accessed via constructor and getter
executeFunction method called with function name as separate argument
Many Unit tests added
fix ComplexCommandSupport:
catch clause catches wrong Exception
Unit tested
Fix complex Command support: do_all to return the results of each call.
That's what the user would in general be able to use next.
refactor: Safe typing for history command
Refactoring of core Preferenes.java: Using constants instead of literals
display known preference keys
code style: Curly Brackets