mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-19 21:00:53 +08:00
improved Querydsl APT configuration
This commit is contained in:
parent
24d9d75cf9
commit
b50245d887
@ -7,7 +7,6 @@ package com.mysema.query.apt;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -52,18 +51,20 @@ public class DefaultConfiguration implements Configuration {
|
||||
private static final String QUERYDSL_ENTITY_ACCESSORS = "querydsl.entityAccessors";
|
||||
|
||||
private static final String DEFAULT_OVERWRITE = "defaultOverwrite";
|
||||
|
||||
private final Collection<String> keywords;
|
||||
|
||||
private final TypeMappings typeMappings = new TypeMappings();
|
||||
|
||||
private final SerializerConfig defaultSerializerConfig;
|
||||
|
||||
private final Serializer dtoSerializer = new ProjectionSerializer(typeMappings);
|
||||
private final Serializer dtoSerializer;
|
||||
|
||||
private final Serializer embeddableSerializer = new EmbeddableSerializer(typeMappings, getKeywords());
|
||||
private final Serializer embeddableSerializer;
|
||||
|
||||
private final Serializer entitySerializer = new EntitySerializer(typeMappings,getKeywords());
|
||||
private final Serializer entitySerializer;
|
||||
|
||||
private final Serializer supertypeSerializer = new SupertypeSerializer(typeMappings,getKeywords());
|
||||
private final Serializer supertypeSerializer;
|
||||
|
||||
private String namePrefix = "Q";
|
||||
|
||||
@ -81,18 +82,24 @@ public class DefaultConfiguration implements Configuration {
|
||||
public DefaultConfiguration(
|
||||
RoundEnvironment roundEnv,
|
||||
Map<String, String> options,
|
||||
Collection<String> keywords,
|
||||
@Nullable Class<? extends Annotation> entitiesAnn,
|
||||
Class<? extends Annotation> entityAnn,
|
||||
@Nullable Class<? extends Annotation> superTypeAnn,
|
||||
@Nullable Class<? extends Annotation> embeddableAnn,
|
||||
@Nullable Class<? extends Annotation> embeddedAnn,
|
||||
@Nullable Class<? extends Annotation> skipAnn) {
|
||||
this.keywords = keywords;
|
||||
this.dtoSerializer = new ProjectionSerializer(typeMappings);
|
||||
this.embeddableSerializer = new EmbeddableSerializer(typeMappings, keywords);
|
||||
this.entitySerializer = new EntitySerializer(typeMappings, keywords);
|
||||
this.supertypeSerializer = new SupertypeSerializer(typeMappings, keywords);
|
||||
this.entitiesAnn = entitiesAnn;
|
||||
this.entityAnn = Assert.notNull(entityAnn,"entityAnn");
|
||||
this.superTypeAnn = superTypeAnn;
|
||||
this.embeddableAnn = embeddableAnn;
|
||||
this.embeddedAnn = embeddedAnn;
|
||||
this.skipAnn = skipAnn;
|
||||
this.skipAnn = skipAnn;
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(Config.class)){
|
||||
Config querydslConfig = element.getAnnotation(Config.class);
|
||||
SerializerConfig config = SimpleSerializerConfig.getConfig(querydslConfig);
|
||||
@ -297,7 +304,7 @@ public class DefaultConfiguration implements Configuration {
|
||||
|
||||
@Override
|
||||
public Collection<String> getKeywords(){
|
||||
return Collections.emptyList();
|
||||
return keywords;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
@ -46,7 +47,7 @@ public class QuerydslAnnotationProcessor extends AbstractProcessor{
|
||||
embedded = QueryEmbedded.class;
|
||||
skip = QueryTransient.class;
|
||||
|
||||
DefaultConfiguration configuration = new DefaultConfiguration(roundEnv, processingEnv.getOptions(), entities, entity, superType, embeddable, embedded, skip);
|
||||
DefaultConfiguration configuration = new DefaultConfiguration(roundEnv, processingEnv.getOptions(), Collections.<String>emptySet(), entities, entity, superType, embeddable, embedded, skip);
|
||||
|
||||
Processor processor = new Processor(processingEnv, roundEnv, configuration);
|
||||
processor.process();
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
package com.mysema.query.apt.jdo;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
@ -29,6 +31,21 @@ import com.mysema.query.apt.Processor;
|
||||
@SupportedAnnotationTypes("*")
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
public class JDOAnnotationProcessor extends AbstractProcessor{
|
||||
|
||||
private static final Set<String> KEYWORDS = new HashSet<String>(Arrays.asList(
|
||||
"AS","ASC",
|
||||
"ASCENDING","AVG",
|
||||
"BY","COUNT",
|
||||
"DESC","DESCENDING",
|
||||
"DISTINCT","EXCLUDE",
|
||||
"FROM","GROUP",
|
||||
"HAVING","INTO",
|
||||
"MAX","MIN",
|
||||
"ORDER","PARAMETERS",
|
||||
"RANGE","SELECT",
|
||||
"SUBCLASSES","SUM",
|
||||
"UNIQUE","VARIABLES",
|
||||
"WHERE"));
|
||||
|
||||
private Class<? extends Annotation> entity, embeddable, skip;
|
||||
|
||||
@ -41,7 +58,8 @@ public class JDOAnnotationProcessor extends AbstractProcessor{
|
||||
embeddable = (Class)Class.forName("javax.jdo.annotations.EmbeddedOnly");
|
||||
skip = (Class)Class.forName("javax.jdo.annotations.NotPersistent");
|
||||
|
||||
DefaultConfiguration configuration = new DefaultConfiguration(roundEnv, processingEnv.getOptions(), null, entity, null, embeddable, null, skip);
|
||||
DefaultConfiguration configuration = new DefaultConfiguration(
|
||||
roundEnv, processingEnv.getOptions(), KEYWORDS, null, entity, null, embeddable, null, skip);
|
||||
configuration.setUseGetters(false);
|
||||
Processor processor = new Processor(processingEnv, roundEnv, configuration);
|
||||
processor.process();
|
||||
@ -52,8 +70,4 @@ public class JDOAnnotationProcessor extends AbstractProcessor{
|
||||
}
|
||||
}
|
||||
|
||||
protected DefaultConfiguration createConfiguration(RoundEnvironment roundEnv) throws ClassNotFoundException {
|
||||
return new JDOConfiguration(roundEnv, processingEnv.getOptions(), entity, null, embeddable, skip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
package com.mysema.query.apt.jdo;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
|
||||
import com.mysema.query.apt.DefaultConfiguration;
|
||||
|
||||
/**
|
||||
* Configuration for {@link JDOAnnotationProcessor}
|
||||
*
|
||||
* @author tiwe
|
||||
* @see JDOAnnotationProcessor
|
||||
*
|
||||
*/
|
||||
public class JDOConfiguration extends DefaultConfiguration{
|
||||
|
||||
private static final List<String> keywords = Arrays.asList(
|
||||
"AS","ASC",
|
||||
"ASCENDING","AVG",
|
||||
"BY","COUNT",
|
||||
"DESC","DESCENDING",
|
||||
"DISTINCT","EXCLUDE",
|
||||
"FROM","GROUP",
|
||||
"HAVING","INTO",
|
||||
"MAX","MIN",
|
||||
"ORDER","PARAMETERS",
|
||||
"RANGE","SELECT",
|
||||
"SUBCLASSES","SUM",
|
||||
"UNIQUE","VARIABLES",
|
||||
"WHERE");
|
||||
|
||||
public JDOConfiguration(RoundEnvironment roundEnv,Map<String,String> options,
|
||||
Class<? extends Annotation> entityAnn,
|
||||
@Nullable Class<? extends Annotation> superTypeAnn,
|
||||
Class<? extends Annotation> embeddableAnn,
|
||||
Class<? extends Annotation> skipAnn) throws ClassNotFoundException {
|
||||
super(roundEnv, options, null, entityAnn, superTypeAnn, embeddableAnn, null, skipAnn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getKeywords(){
|
||||
return keywords;
|
||||
}
|
||||
|
||||
}
|
||||
@ -9,6 +9,7 @@ import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -29,7 +30,7 @@ import com.mysema.query.apt.VisitorConfig;
|
||||
*/
|
||||
public class JPAConfiguration extends DefaultConfiguration {
|
||||
|
||||
private static final List<String> keywords = Arrays.asList(
|
||||
private static final Collection<String> KEYWORDS = new HashSet<String>(Arrays.asList(
|
||||
"ABS","ALL","AND","ANY","AS","ASC","AVG","BETWEEN",
|
||||
"BIT_LENGTH[51]","BOTH","BY","CASE","CHAR_LENGTH",
|
||||
"CHARACTER_LENGTH","CLASS",
|
||||
@ -44,7 +45,7 @@ public class JPAConfiguration extends DefaultConfiguration {
|
||||
"ORDER","OUTER","POSITION","SELECT","SET","SIZE","SOME",
|
||||
"SQRT","SUBSTRING","SUM","THEN",
|
||||
"TRAILING","TRIM","TRUE","TYPE","UNKNOWN","UPDATE","UPPER",
|
||||
"VALUE","WHEN","WHERE");
|
||||
"VALUE","WHEN","WHERE"));
|
||||
|
||||
private List<Class<? extends Annotation>> annotations;
|
||||
|
||||
@ -53,7 +54,7 @@ public class JPAConfiguration extends DefaultConfiguration {
|
||||
Class<? extends Annotation> superTypeAnn,
|
||||
Class<? extends Annotation> embeddableAnn,
|
||||
Class<? extends Annotation> skipAnn) throws ClassNotFoundException {
|
||||
super(roundEnv, options, null, entityAnn, superTypeAnn, embeddableAnn, null, skipAnn);
|
||||
super(roundEnv, options, KEYWORDS, null, entityAnn, superTypeAnn, embeddableAnn, null, skipAnn);
|
||||
this.annotations = getAnnotations();
|
||||
}
|
||||
|
||||
@ -108,9 +109,4 @@ public class JPAConfiguration extends DefaultConfiguration {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getKeywords(){
|
||||
return keywords;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
package com.mysema.query.mongodb;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
@ -37,7 +38,9 @@ public class MongodbAnnotationProcessor extends AbstractProcessor{
|
||||
embedded = Embedded.class;
|
||||
skip = Transient.class;
|
||||
|
||||
DefaultConfiguration configuration = new DefaultConfiguration(roundEnv, processingEnv.getOptions(), entities, entity, null, null, embedded, skip);
|
||||
DefaultConfiguration configuration = new DefaultConfiguration(
|
||||
roundEnv, processingEnv.getOptions(), Collections.<String>emptySet(),
|
||||
entities, entity, null, null, embedded, skip);
|
||||
|
||||
Processor processor = new Processor(processingEnv, roundEnv, configuration);
|
||||
processor.process();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user