mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
added support for annotated getters
moved APT constants to com.mysema.query.apt.Constants added Adapter for Query
This commit is contained in:
parent
aa3472c514
commit
97bbb59d75
@ -29,6 +29,11 @@
|
||||
<version>1.4</version>
|
||||
<!-- license : Apache License 2.0 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
|
||||
@ -12,7 +12,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mysema.query.apt.general.GeneralProcessor;
|
||||
import com.mysema.query.apt.jpa.JpaProcessor;
|
||||
import com.mysema.query.apt.querydsl.QuerydslProcessor;
|
||||
import com.sun.mirror.apt.AnnotationProcessor;
|
||||
@ -26,14 +25,11 @@ import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class APTFactory implements AnnotationProcessorFactory {
|
||||
public class APTFactory implements AnnotationProcessorFactory, Constants {
|
||||
|
||||
private static final Collection<String> supportedAnnotations = Arrays.asList(
|
||||
GeneralProcessor.qdEntity,
|
||||
GeneralProcessor.qdDto,
|
||||
JpaProcessor.jpaEmbeddable,
|
||||
JpaProcessor.jpaEntity,
|
||||
JpaProcessor.jpaSuperClass
|
||||
qdEntity, qdDto,
|
||||
jpaEntity, jpaSuperClass, jpaEmbeddable
|
||||
);
|
||||
|
||||
private static final Collection<String> supportedOptions = Collections.emptySet();
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
/**
|
||||
* Constants provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Constants {
|
||||
String qdEntity= "com.mysema.query.annotations.Domain";
|
||||
String qdDto = "com.mysema.query.annotations.DTO";
|
||||
|
||||
String jpaSuperClass = "javax.persistence.MappedSuperclass";
|
||||
String jpaEntity = "javax.persistence.Entity";
|
||||
String jpaEmbeddable = "javax.persistence.Embeddable";
|
||||
|
||||
}
|
||||
@ -8,6 +8,8 @@ package com.mysema.query.apt.general;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.mysema.query.apt.model.Field;
|
||||
import com.mysema.query.apt.model.Type;
|
||||
import com.sun.mirror.declaration.ClassDeclaration;
|
||||
@ -24,10 +26,22 @@ import com.sun.mirror.util.SimpleDeclarationVisitor;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DefaultEntityVisitor extends SimpleDeclarationVisitor {
|
||||
public final Map<String, Type> types = new HashMap<String, Type>();
|
||||
|
||||
private Type last;
|
||||
|
||||
public final Map<String, Type> types = new HashMap<String, Type>();
|
||||
|
||||
private void addField(String originalName, TypeHelper typeInfo) {
|
||||
String name = FieldHelper.javaSafe(originalName);
|
||||
String realName = FieldHelper.realName(originalName);
|
||||
String keyTypeName = typeInfo.getKeyTypeName();
|
||||
String typeName = typeInfo.getFullName();
|
||||
String typePackage = typeInfo.getPackageName();
|
||||
String simpleTypeName = typeInfo.getSimpleName();
|
||||
Field.Type fieldType = typeInfo.getFieldType();
|
||||
last.addField(new Field(name, realName, keyTypeName, typePackage,
|
||||
typeName, simpleTypeName, fieldType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClassDeclaration(ClassDeclaration d) {
|
||||
String simpleName = d.getSimpleName();
|
||||
@ -37,7 +51,14 @@ public class DefaultEntityVisitor extends SimpleDeclarationVisitor {
|
||||
last = new Type(superType, packageName, name, simpleName);
|
||||
types.put(d.getQualifiedName(), last);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitFieldDeclaration(FieldDeclaration d) {
|
||||
if (!d.getModifiers().contains(Modifier.STATIC) && !d.getModifiers().contains(Modifier.TRANSIENT)) {
|
||||
addField(d.getSimpleName(), new TypeHelper(d.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInterfaceDeclaration(InterfaceDeclaration d){
|
||||
String simpleName = d.getSimpleName();
|
||||
@ -50,28 +71,20 @@ public class DefaultEntityVisitor extends SimpleDeclarationVisitor {
|
||||
last = new Type(superType, packageName, name, simpleName);
|
||||
types.put(d.getQualifiedName(), last);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFieldDeclaration(FieldDeclaration d) {
|
||||
if (!d.getModifiers().contains(Modifier.STATIC) && !d.getModifiers().contains(Modifier.TRANSIENT)) {
|
||||
TypeHelper typeInfo = new TypeHelper(d.getType());
|
||||
String name = FieldHelper.javaSafe(d.getSimpleName());
|
||||
String realName = FieldHelper.realName(name);
|
||||
String keyTypeName = typeInfo.getKeyTypeName();
|
||||
String typeName = typeInfo.getFullName();
|
||||
String typePackage = typeInfo.getPackageName();
|
||||
String simpleTypeName = typeInfo.getSimpleName();
|
||||
Field.Type fieldType = typeInfo.getFieldType();
|
||||
last.addField(new Field(name, realName, keyTypeName, typePackage,
|
||||
typeName, simpleTypeName, fieldType));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodDeclaration(MethodDeclaration d) {
|
||||
if (!d.getModifiers().contains(Modifier.STATIC)){
|
||||
// TODO
|
||||
if (d.getParameters().isEmpty()){
|
||||
if (d.getSimpleName().startsWith("get")){
|
||||
String name = StringUtils.uncapitalize(d.getSimpleName().substring(3));
|
||||
addField(name, new TypeHelper(d.getReturnType()));
|
||||
}else if (d.getSimpleName().startsWith("is")){
|
||||
String name = StringUtils.uncapitalize(d.getSimpleName().substring(2));
|
||||
addField(name, new TypeHelper(d.getReturnType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -29,9 +29,6 @@ import com.sun.mirror.declaration.Declaration;
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class GeneralProcessor implements AnnotationProcessor {
|
||||
|
||||
public static final String qdEntity= "com.mysema.query.annotations.Domain",
|
||||
qdDto = "com.mysema.query.annotations.DTO";
|
||||
|
||||
public static final FreeMarkerSerializer
|
||||
DOMAIN_OUTER_TMPL = new FreeMarkerSerializer("/domain-as-outer-classes.ftl"),
|
||||
|
||||
@ -5,12 +5,14 @@ import static com.sun.mirror.util.DeclarationVisitors.getDeclarationScanner;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.mysema.query.apt.Constants;
|
||||
import com.mysema.query.apt.general.DefaultEntityVisitor;
|
||||
import com.mysema.query.apt.general.GeneralProcessor;
|
||||
import com.mysema.query.apt.model.Type;
|
||||
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
|
||||
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
import com.sun.mirror.declaration.Declaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
|
||||
/**
|
||||
* JpaProcessor provides
|
||||
@ -18,11 +20,7 @@ import com.sun.mirror.declaration.Declaration;
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class JpaProcessor extends GeneralProcessor{
|
||||
|
||||
public static final String jpaSuperClass = "javax.persistence.MappedSuperclass",
|
||||
jpaEntity = "javax.persistence.Entity",
|
||||
jpaEmbeddable = "javax.persistence.Embeddable";
|
||||
public class JpaProcessor extends GeneralProcessor implements Constants{
|
||||
|
||||
public JpaProcessor(AnnotationProcessorEnvironment env) {
|
||||
super(env, jpaSuperClass, jpaEntity, qdDto);
|
||||
@ -37,13 +35,24 @@ public class JpaProcessor extends GeneralProcessor{
|
||||
|
||||
Map<String, Type> entityTypes = entityVisitor.types;
|
||||
if (entityTypes.isEmpty()) {
|
||||
env.getMessager().printNotice("No class generation for domain types");
|
||||
env.getMessager().printNotice("No class generation for embeddable types");
|
||||
} else {
|
||||
serializeAsOuterClasses(entityTypes.values(), EMBEDDABLE_OUTER_TMPL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO : add switch for field / getter handling
|
||||
@Override
|
||||
protected DefaultEntityVisitor createEntityVisitor(){
|
||||
return new DefaultEntityVisitor(){
|
||||
@Override
|
||||
public void visitMethodDeclaration(MethodDeclaration d) {
|
||||
// skip property handling
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void process() {
|
||||
super.process();
|
||||
createEmbeddableClasses();
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.mysema.query.apt.querydsl;
|
||||
|
||||
import com.mysema.query.apt.Constants;
|
||||
import com.mysema.query.apt.general.DefaultEntityVisitor;
|
||||
import com.mysema.query.apt.general.GeneralProcessor;
|
||||
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
|
||||
/**
|
||||
* QureydslProcessor provides
|
||||
@ -9,10 +12,20 @@ import com.sun.mirror.apt.AnnotationProcessorEnvironment;
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
public class QuerydslProcessor extends GeneralProcessor{
|
||||
public class QuerydslProcessor extends GeneralProcessor implements Constants{
|
||||
|
||||
public QuerydslProcessor(AnnotationProcessorEnvironment env) {
|
||||
super(env, null, qdEntity, qdDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultEntityVisitor createEntityVisitor(){
|
||||
return new DefaultEntityVisitor(){
|
||||
@Override
|
||||
public void visitMethodDeclaration(MethodDeclaration d) {
|
||||
// skip property handling
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user