querydsl / codegen

Java/Scala Code generation tool
Apache License 2.0
23 stars 22 forks source link

compiler error for field names ending with '_' in ScalaWriter #37

Open khoran opened 7 years ago

khoran commented 7 years ago

When a field name ends with _ (and likely any other symbol), the ScalaWriter class generates parameters that look like fieldName_: String. Since there is no space between the _ and the :, the scala compiler assumes the : is part of the variable name and throws a syntax error. The fix is to just put a space before the : I imagine. Here is a guess at the relevant lines in ScalaWriter:

ScalaWriter.scala line 353:

   public ScalaWriter field(Type type, String name) throws IOException {
        line(VAR, escape(name), ": ", getGenericName(true, type));
        return compact ? this : nl();
    }
    private ScalaWriter field(String modifier, Type type, String name) throws IOException {
        line(modifier, escape(name), ": ", getGenericName(true, type));
        return compact ? this : nl();
    }
    private ScalaWriter field(String modifier, Type type, String name, String value)
            throws IOException {
        line(modifier, escape(name), ": ", getGenericName(true, type), ASSIGN, value);
        return compact ? this : nl();
    }

I was exploring the use of generated case classes when I came across this bug, that won't work for me for unrelated reasons, but I won't be able to test any fixes here. I just thought I'd point out the bug.

Kevin