Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 2.1.0-beta-1
-
Component/s: Compiler
-
Labels:None
-
Number of attachments :
Description
Allow use of a Groovy compiler flag to enable type checking for all classes and methods except for the classes and methods annotated with a @TypeUnchecked annotation (or another antonym of @TypeChecked such as @NotTypeChecked or @RuntimeTypeChecked or @TestInProduction or @YouNeedExtraUnitTestsForThis)
For large projects with hundreds of classes, where we want type checking on 99% of the code, it would be too much boilerplate to remember to put @TypeChecked annotations on every class. It would also require us to refactor methods containing dynamic code into separate non-type-checked classes just to satisfy the @TypeChecked contract. It would be better to have a compiler flag to reverse the type checking contract so everything is type checked except for the classes and methods that are explicitly marked for allowing dynamic code.
Discussed with Guillaume Laforge after his talk about Groovy 2.0 at GR8Conf 2012 in Copenhagen. He agreed it would be a good addition for Groovy 2.1, and that I should open a Jira ticket. Another audience member had the same request as well.
Issue Links
- depends upon
-
GROOVY-5553
Provide a builder for compilation customizers
-
-
GROOVY-5554
AST customizer working as a guard for another
-
- is duplicated by
-
GROOVY-5563
Option to default to Static Compilation
-
Note that currently, you can skip some classes or methods from being type checked using an annotation parameter. Regarding that particular feature, it would be interesting to have, but I think we should better have a generic way of applying AST transforms transparently using the groovy compiler, just like we have an option to do it using the GroovyShell. This has the advantage of being independent from the type checker features.
But basically, +1