Abstract away file IO when writing generated code

This allows us to write unittests of Java/Cpp AST elements without
doing file I/O each time.  Introduce a CodeWriter class which
may write to either a string or a file dependening on the contect.

While here, mark the write methods as const.

Test: Compiles, unittests pass, added new unittest demonstrating usage.
Bug: 23598995

Change-Id: I240ede41f0f9c04c0d14d1a3680ce5ab332babbc
18 files changed