APT-based source code generation tool for Querydsl that generates type-safe query classes from annotated Java entity classes.
—
Central annotation processing functionality providing the base framework for generating type-safe query classes from annotated Java entities. This module handles the core processing logic shared across all framework-specific processors.
Base abstract processor containing the main processing logic and lifecycle management.
/**
* Base class for Querydsl annotation processors, contains the main processing logic
*/
public abstract class AbstractQuerydslProcessor extends AbstractProcessor {
/**
* Main processing entry point called by the Java compiler
* @param annotations Set of annotation types being processed
* @param roundEnv Processing environment for current round
* @return Whether annotations were claimed by this processor
*/
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv);
/**
* Create configuration for this processor - must be implemented by subclasses
* @param roundEnv Processing environment
* @return Configuration instance for this processor
*/
protected abstract Configuration createConfiguration(RoundEnvironment roundEnv);
/**
* Get supported source version
* @return Latest supported Java source version
*/
public SourceVersion getSupportedSourceVersion();
// Static utilities available to all processors
public static Types TYPES;
public static Elements ELEMENTS;
public static final Boolean ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS = Boolean.FALSE;
}Processing Flow:
Default processor for general Querydsl annotations, handling the core Querydsl annotation set.
/**
* Default annotation processor for Querydsl annotations
* Handles @QueryEntity, @QuerySupertype, @QueryEmbeddable, @QueryEmbedded, @QueryTransient
*/
@SupportedAnnotationTypes({"com.mysema.query.annotations.*"})
public class QuerydslAnnotationProcessor extends AbstractQuerydslProcessor {
/**
* Creates configuration for Querydsl-specific annotations
* @param roundEnv Processing environment
* @return DefaultConfiguration with Querydsl annotation mappings
*/
@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv);
}Supported Annotations:
@QueryEntity: Marks a class as a query entity@QuerySupertype: Marks a superclass for query type inheritance@QueryEmbeddable: Marks a class as embeddable in queries@QueryEmbedded: Marks a field/property as embedded@QueryTransient: Marks a field/property to skip in query generation@QueryEntities: Package-level annotation listing entitiesUsage Example:
import com.mysema.query.annotations.QueryEntity;
import com.mysema.query.annotations.QueryTransient;
@QueryEntity
public class Product {
private Long id;
private String name;
private BigDecimal price;
@QueryTransient // Will not be included in generated QProduct
private transient String tempField;
}
// Generates QProduct.java with id, name, and price propertiesCore utilities for type analysis and extraction during annotation processing.
/**
* Utility for extracting TypeElement from TypeMirror instances
*/
public class TypeExtractor {
public TypeExtractor(boolean create);
public TypeElement visit(TypeMirror type);
}
/**
* Static utility methods for type processing operations
*/
public class TypeUtils {
public static boolean hasAnnotationOfType(TypeElement element, Set<Class<? extends Annotation>> annotations);
public static AnnotationMirror getAnnotationMirrorOfType(Element element, Class<? extends Annotation> type);
public static TypeMirror getAnnotationValueAsTypeMirror(AnnotationMirror annotation, String key);
public static Collection<TypeElement> getAnnotationValuesAsElements(AnnotationMirror annotation, String key);
public static boolean isAnnotationMirrorOfType(AnnotationMirror annotation, Class<? extends Annotation> type);
}
/**
* Factory for creating extended type representations
*/
public class ExtendedTypeFactory {
public ExtendedTypeFactory(ProcessingEnvironment env, Configuration conf, ...);
public EntityType getEntityType(TypeMirror type, boolean create);
public Collection<EntityType> getEntityTypes();
public void extendTypes();
}
/**
* Handler for processing TypeElement instances into entity models
*/
public class TypeElementHandler {
public TypeElementHandler(Configuration conf, ExtendedTypeFactory factory, TypeMappings typeMappings, QueryTypeFactory queryTypeFactory);
public EntityType handleEntityType(TypeElement element);
public EntityType handleProjectionType(TypeElement element);
public List<Parameter> transformParams(List<? extends VariableElement> parameters);
}Context object that maintains state during annotation processing rounds.
/**
* Processing context for storing intermediate results
*/
public class Context {
// Entity type collections organized by category
public final Map<String, EntityType> entityTypes = new HashMap<>();
public final Map<String, EntityType> embeddableTypes = new HashMap<>();
public final Map<String, EntityType> supertypes = new HashMap<>();
public final Map<String, EntityType> extensionTypes = new HashMap<>();
public final Map<String, EntityType> projectionTypes = new HashMap<>();
public final Map<String, EntityType> allTypes = new HashMap<>();
// Type element mappings for source tracking
public final Map<String, Set<TypeElement>> typeElements = new HashMap<>();
public void clean();
}Controls how annotation processors discover and process entity properties.
/**
* Configuration for controlling property visitor behavior
*/
public enum VisitorConfig {
/** Visit both fields and getters */
ALL(true, true, true),
/** Visit fields only */
FIELDS_ONLY(true, false, true),
/** Visit methods only */
METHODS_ONLY(false, true, true),
/** Visit none */
NONE(false, false, false);
public static VisitorConfig get(boolean fields, boolean methods);
public static VisitorConfig get(boolean fields, boolean methods, VisitorConfig defaultConfig);
public boolean visitFieldProperties();
public boolean visitMethodProperties();
public boolean visitConstructors();
}Property Discovery Modes:
The processor automatically detects getter methods using naming conventions (getPropertyName(), isPropertyName() for booleans) and validates that they have no parameters and appropriate return types.
Install with Tessl CLI
npx tessl i tessl/maven-com-mysema-querydsl--querydsl-apt