Fixing printer generation errors caused by last modification of ast_core.

After adding the possibility of generating fields as Optional<T>, the
generation of the default printer became incorrect. This commit fixes
the generated printer code for Java while also adding more safety to the
code handling printing ReferenceField and ReferenceListField.