mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-16 21:01:10 +08:00
Improve property escaping
This commit is contained in:
parent
5789cae7d9
commit
2bfe011efb
@ -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());
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user