derive4j / hkt

Higher Kinded Type machinery for Java
BSD 3-Clause "New" or "Revised" License
81 stars 9 forks source link

Encoding of generated files should be UTF-8 #26

Closed DanielGronau closed 7 years ago

DanielGronau commented 7 years ago

Under Widows 10, I have the problem that the generated java files have the Windows default encoding, not UTF-8, which garbles the µ identifier in my case.

After trying every way to set an encoding in Maven or my IDE, I assume the annotation processor itself must take care of it. I think the relevant code location is GenCode:146:

Filer.createSourceFile(genClassName).openWriter()

As far as I understand, openWriter() simply wraps the underlying output stream with am OutputStreamWriter without setting an encoding, which results in using the system default (and not the encoding set for javac etc). I haven't tested it, but I would assume that using something like

new OutputStreamWriter(Filer.createSourceFile(genClassName).openOutputStream(), "UTF8")

could probably solve the problem. Of course instead of hard-coding, this could be also a parameter of the annotation processor (although I'm not sure in which scenarios would require another encoding)

jbgi commented 7 years ago

Yes, we very certainly always want to use UTF-8. And your suggested fix looks fine (with java.nio.charset.StandardCharsets.UTF_8instead of "UTF8"). do you want to make a PR?

jbgi commented 7 years ago

fixed by f775a81516a4640c02817767be9638254d790b88