Merge pull request #1566 from querydsl/i1560-fix

Improve property escaping
This commit is contained in:
John Tims 2015-09-21 21:10:10 -04:00
commit cb72ce287f
2 changed files with 32 additions and 2 deletions

View File

@ -0,0 +1,22 @@
package com.querydsl.apt.domain;
import static org.junit.Assert.assertEquals;
import javax.persistence.MappedSuperclass;
import org.junit.Test;
public class Properties4Test extends AbstractTest {
@MappedSuperclass
public abstract static class Naming {
public abstract boolean is8FRecord();
}
@Test
public void test() {
assertEquals("8FRecord", QProperties4Test_Naming.naming._8FRecord.getMetadata().getName());
}
}

View File

@ -51,8 +51,7 @@ public final class Property implements Comparable<Property> {
public Property(EntityType declaringType, String name, Type type, List<String> inits,
boolean inherited) {
this(declaringType, name, JavaSyntaxUtils.isReserved(name) ? (name + "$") : name, type,
inits, inherited);
this(declaringType, name, escapeName(name), type, inits, inherited);
}
public Property(EntityType declaringType, String name, String escapedName, Type type,
@ -65,6 +64,15 @@ public final class Property implements Comparable<Property> {
this.inherited = inherited;
}
private static String escapeName(String name) {
if (JavaSyntaxUtils.isReserved(name)) {
name = name + "$";
} else if (!Character.isJavaIdentifierStart(name.charAt(0))) {
name = "_" + name;
}
return name;
}
public void addAnnotation(Annotation annotation) {
annotations.put(annotation.annotationType(), annotation);
}