Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.javahelpers.simple.builders.processor.model.type.TypeName;
import org.javahelpers.simple.builders.processor.model.javadoc.JavadocDto;
import org.javahelpers.simple.builders.processor.generators.MethodGenerator;
import org.javahelpers.simple.builders.processor.processing.ProcessingContext;
import org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext;

/**
* Custom generator that adds validation methods for String fields.
Expand Down Expand Up @@ -60,13 +60,13 @@ public int getPriority() {
}

@Override
public boolean appliesTo(FieldDto field, TypeName dtoType, ProcessingContext context) {
public boolean appliesTo(FieldDto field, TypeName dtoType, BuilderProcessingContext context) {
// Only apply to String fields
return "java.lang.String".equals(field.getFieldType().getFullQualifiedName());
}

@Override
public List<BuilderMethodDto> generateMethods(FieldDto field, TypeName builderType, ProcessingContext context) {
public List<BuilderMethodDto> generateMethods(FieldDto field, TypeName builderType, BuilderProcessingContext context) {
String fieldInDto = field.getOriginalFieldName();
String fieldInBuilder = field.getFieldNameInBuilder();
String methodName = "validate" + StringUtils.capitalize(fieldInDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
import org.javahelpers.simple.builders.processor.model.type.TypeNameMap;
import org.javahelpers.simple.builders.processor.model.type.TypeNameSet;
import org.javahelpers.simple.builders.processor.processing.BuilderConfigurationReader;
import org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext;
import org.javahelpers.simple.builders.processor.processing.CompilerArgumentsEnum;
import org.javahelpers.simple.builders.processor.processing.CompilerArgumentsReader;
import org.javahelpers.simple.builders.processor.processing.ProcessingContext;
import org.javahelpers.simple.builders.processor.processing.ProcessingTarget;
import org.javahelpers.simple.builders.processor.processing.SourceFormatterResolver;
import org.javahelpers.simple.builders.processor.processing.logging.PerformanceTracker;
Expand All @@ -97,7 +97,7 @@ public class BuilderProcessor extends AbstractProcessor {
private static final String MSG_FAILED_TO_GENERATE =
"simple-builders: Failed to generate builder - %s";

private ProcessingContext context;
private BuilderProcessingContext context;
private ProcessingLogger logger;
private ClassCodeGenerator codeGenerator;
private SourceFormatterResolver formatterResolver;
Expand All @@ -121,7 +121,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) {

SimpleBuildersSpiIntegration.initCompilation(processingEnv.getElementUtils());

this.context = new ProcessingContext(logger, globalConfig, processingEnv);
this.context = new BuilderProcessingContext(logger, globalConfig, processingEnv);
this.codeGenerator =
new RoasterCodeGenerator(
new GenerationEnvironment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.javahelpers.simple.builders.processor.model.type.BuilderInstantiation;
import org.javahelpers.simple.builders.processor.model.type.ResolvedBuilder;
import org.javahelpers.simple.builders.processor.model.type.TypeName;
import org.javahelpers.simple.builders.processor.processing.ProcessingContext;
import org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext;

/**
* Central resolver that decides whether a builder may be referenced for a given type.
Expand Down Expand Up @@ -75,7 +75,7 @@ private record ResolutionInputs(BuilderConfiguration configuration, String build
List.of(GENERATED_FACTORY_METHOD_NAME, "of");
private static final char[] UPPERCASE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();

private final ProcessingContext context;
private final BuilderProcessingContext context;
private ResolutionInputs cachedResolutionInputs;
private PackageScopes usagePackages = PackageScopes.unscoped();
private final Map<String, Optional<ResolvedBuilder>> resolvedBuilderTypes = new HashMap<>();
Expand All @@ -86,17 +86,17 @@ private record ResolutionInputs(BuilderConfiguration configuration, String build
*
* @param context the processing context providing configuration and type utilities
*/
public BuilderScopeResolver(ProcessingContext context) {
public BuilderScopeResolver(BuilderProcessingContext context) {
this.context = context;
}

/**
* Resolves the builder type to use for the given referenced type, if any.
*
* <p>This method reads the configuration from the processing context via {@link
* org.javahelpers.simple.builders.processor.processing.ProcessingContext#getConfiguration()}. The
* caller must ensure that {@link
* org.javahelpers.simple.builders.processor.processing.ProcessingContext#initProcessingTarget}
* org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext#getConfiguration()}.
* The caller must ensure that {@link
* org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext#initProcessingTarget}
* has been invoked with the owner element's resolved configuration beforehand, so that
* per-element {@code builderUsagePackages} overrides are respected.
*
Expand Down Expand Up @@ -170,7 +170,7 @@ public Optional<ResolvedBuilder> resolveGeneratedBuilder(TypeElement referencedT
* <p>Unlike {@link #resolveUsableBuilderType(TypeElement)}, this method takes the configuration
* as an explicit parameter rather than reading it from the processing context. This is because it
* is called during generation-plan resolution, before {@link
* org.javahelpers.simple.builders.processor.processing.ProcessingContext#initProcessingTarget}
* org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext#initProcessingTarget}
* has been invoked for the element, so the context does not yet hold the per-element
* configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.javahelpers.simple.builders.processor.model.type.TypeName;
import org.javahelpers.simple.builders.processor.processing.ProcessingContext;
import org.javahelpers.simple.builders.processor.processing.AnnotationProcessingContext;

/** Helperclass for extrating specific information from existing classes. */
public final class JavaLangAnalyser {
Expand All @@ -68,7 +68,8 @@ private JavaLangAnalyser() {}
* @param context the processing context, used to resolve {@link java.lang.Object}'s methods
* @return {@code true}, if it is no method with the signature of a java.lang.Object method
*/
public static boolean isNoMethodOfObjectClass(ExecutableElement mth, ProcessingContext context) {
public static boolean isNoMethodOfObjectClass(
ExecutableElement mth, AnnotationProcessingContext context) {
TypeElement objectElement = context.getTypeElement(Object.class.getCanonicalName());
if (objectElement == null) {
return true;
Expand All @@ -89,7 +90,7 @@ public static boolean isNoMethodOfObjectClass(ExecutableElement mth, ProcessingC
* @return filtered list excluding Object class methods
*/
public static List<ExecutableElement> findAllPossibleSettersOfClass(
TypeElement typeElement, ProcessingContext context) {
TypeElement typeElement, AnnotationProcessingContext context) {
return ElementFilter.methodsIn(context.getAllMembers(typeElement)).stream()
.filter(mth -> isNoMethodOfObjectClass(mth, context))
.filter(JavaLangAnalyser::isSetterForField)
Expand Down Expand Up @@ -250,7 +251,7 @@ public static List<AnnotationMirror> findAnnotationInstances(
Element element,
Class<? extends Annotation> annotationClass,
Class<? extends Annotation> containerClass,
ProcessingContext context) {
AnnotationProcessingContext context) {
if (element == null) {
return List.of();
}
Expand All @@ -275,7 +276,7 @@ public static List<AnnotationMirror> findAnnotationInstances(
* @return the annotation mirrors wrapped by the container
*/
private static List<AnnotationMirror> unwrapContainerInstances(
AnnotationMirror containerMirror, ProcessingContext context) {
AnnotationMirror containerMirror, AnnotationProcessingContext context) {
Optional<AnnotationValue> containerValue =
findAnnotationAttribute(containerMirror, "value", context);
if (containerValue.isEmpty() || !(containerValue.get().getValue() instanceof List<?> entries)) {
Expand All @@ -299,7 +300,9 @@ private static List<AnnotationMirror> unwrapContainerInstances(
* @return the attribute's value, or empty if the annotation has no such attribute
*/
public static Optional<AnnotationValue> findAnnotationAttribute(
AnnotationMirror annotationMirror, String attributeName, ProcessingContext context) {
AnnotationMirror annotationMirror,
String attributeName,
AnnotationProcessingContext context) {
for (Map.Entry<ExecutableElement, AnnotationValue> entry :
context.getElementValuesWithDefaults(annotationMirror).entrySet()) {
if (entry.getKey().getSimpleName().contentEquals(attributeName)) {
Expand All @@ -311,13 +314,13 @@ public static Optional<AnnotationValue> findAnnotationAttribute(

/**
* Single-parameter variant of {@link #findMethodsStatic(TypeElement, List, TypeName,
* ProcessingContext)}.
* AnnotationProcessingContext)}.
*/
public static List<ExecutableElement> findMethodsStatic(
TypeElement type,
TypeName expectedParameterType,
TypeName expectedReturnType,
ProcessingContext context) {
AnnotationProcessingContext context) {
return findMethodsStatic(type, List.of(expectedParameterType), expectedReturnType, context);
}

Expand All @@ -335,7 +338,7 @@ public static List<ExecutableElement> findMethodsStatic(
TypeElement type,
List<TypeName> expectedParameterTypes,
TypeName expectedReturnType,
ProcessingContext context) {
AnnotationProcessingContext context) {
return findMethods(type, expectedParameterTypes, expectedReturnType, context).stream()
.filter(Predicate.not(JavaLangAnalyser::isNotStatic))
.toList();
Expand All @@ -351,7 +354,9 @@ public static List<ExecutableElement> findMethodsStatic(
* @return the matching methods, in declaration order
*/
public static List<ExecutableElement> findMethodsStatic(
TypeElement type, List<TypeName> expectedParameterTypes, ProcessingContext context) {
TypeElement type,
List<TypeName> expectedParameterTypes,
AnnotationProcessingContext context) {
return findMethods(type, expectedParameterTypes, mirror -> true, context).stream()
.filter(Predicate.not(JavaLangAnalyser::isNotStatic))
.toList();
Expand All @@ -371,7 +376,7 @@ public static List<ExecutableElement> findMethods(
TypeElement type,
List<TypeName> expectedParameterTypes,
TypeName expectedReturnType,
ProcessingContext context) {
AnnotationProcessingContext context) {
Predicate<TypeMirror> returnTypeMatcher =
expectedReturnType == null
? mirror -> mirror.getKind() == VOID
Expand All @@ -383,7 +388,7 @@ private static List<ExecutableElement> findMethods(
TypeElement type,
List<TypeName> expectedParameterTypes,
Predicate<TypeMirror> returnTypeMatcher,
ProcessingContext context) {
AnnotationProcessingContext context) {
if (type == null) {
return List.of();
}
Expand Down Expand Up @@ -463,7 +468,7 @@ public record ReadableProperty(String name, String accessor, TypeMirror typeMirr
* @return the readable properties in declaration order
*/
public static List<ReadableProperty> findReadableProperties(
TypeElement typeElement, ProcessingContext context) {
TypeElement typeElement, AnnotationProcessingContext context) {
if (typeElement == null) {
return List.of();
}
Expand All @@ -478,7 +483,7 @@ public static List<ReadableProperty> findReadableProperties(
&& hasNoParameters(method)
&& method.getReturnType().getKind() != VOID
&& isNoMethodOfObjectClass(method, context)
&& context.isMemberAccessibleFromBuilderPackage(method)) {
&& context.isAccessibleFromGeneratedPackage(method)) {
String name = propertyNameOf(method);
properties.putIfAbsent(
name,
Expand All @@ -487,7 +492,7 @@ && isNoMethodOfObjectClass(method, context)
}
for (VariableElement field : ElementFilter.fieldsIn(context.getAllMembers(typeElement))) {
if (!field.getModifiers().contains(STATIC)
&& context.isMemberAccessibleFromBuilderPackage(field)) {
&& context.isAccessibleFromGeneratedPackage(field)) {
String name = field.getSimpleName().toString();
properties.putIfAbsent(name, new ReadableProperty(name, name, field.asType()));
}
Expand All @@ -505,7 +510,7 @@ && isNoMethodOfObjectClass(method, context)
* @return the field functions in declaration order
*/
public static List<ExecutableElement> findFieldFunctions(
TypeElement type, ProcessingContext context) {
TypeElement type, AnnotationProcessingContext context) {
return ElementFilter.methodsIn(context.getAllMembers(type)).stream()
.filter(JavaLangAnalyser::isNotStatic)
.filter(method -> isNoMethodOfObjectClass(method, context))
Expand Down Expand Up @@ -542,7 +547,7 @@ private static String propertyNameOf(ExecutableElement method) {
* @return {@code true} if the type declares or inherits a matching constructor
*/
public static boolean hasConstructorAccepting(
TypeElement builderType, TypeName expectedType, ProcessingContext context) {
TypeElement builderType, TypeName expectedType, AnnotationProcessingContext context) {
if (builderType == null) {
return false;
}
Expand Down Expand Up @@ -759,7 +764,7 @@ public static Optional<ExecutableElement> findGetterForField(
TypeElement dtoType,
String fieldName,
TypeMirror fieldTypeMirror,
ProcessingContext context) {
AnnotationProcessingContext context) {
if (dtoType == null || fieldName == null || fieldTypeMirror == null) {
return Optional.empty();
}
Expand All @@ -772,7 +777,7 @@ public static Optional<ExecutableElement> findGetterForField(
if (Strings.CI.equalsAny(name, fieldName, "is" + fieldName, "get" + fieldName)
&& candidate.getParameters().isEmpty()
&& context.isSameType(candidate.getReturnType(), fieldTypeMirror)
&& context.isMemberAccessibleFromBuilderPackage(candidate)) {
&& context.isAccessibleFromGeneratedPackage(candidate)) {
return Optional.of(candidate);
}
}
Expand Down Expand Up @@ -827,7 +832,7 @@ public static Optional<javax.lang.model.element.RecordComponentElement> findReco
* @return Optional containing the setter ExecutableElement if found
*/
public static Optional<ExecutableElement> findSetterForField(
TypeElement dtoType, String fieldName, ProcessingContext context) {
TypeElement dtoType, String fieldName, AnnotationProcessingContext context) {
if (dtoType == null || fieldName == null) {
return Optional.empty();
}
Expand All @@ -837,7 +842,7 @@ public static Optional<ExecutableElement> findSetterForField(
if (candidate.getSimpleName().contentEquals(setterName)
&& candidate.getParameters().size() == 1
&& candidate.getReturnType().getKind() == VOID
&& context.isMemberAccessibleFromBuilderPackage(candidate)) {
&& context.isAccessibleFromGeneratedPackage(candidate)) {
return Optional.of(candidate);
}
}
Expand All @@ -859,7 +864,7 @@ public static Optional<ExecutableElement> findSetterForField(
public static Optional<ExecutableElement> findConstructorForBuilder(
TypeElement annotatedType,
Class<? extends Annotation> constructorAnnotation,
ProcessingContext context) {
AnnotationProcessingContext context) {
List<ExecutableElement> ctors =
ElementFilter.constructorsIn(context.getAllMembers(annotatedType)).stream()
.filter(context::isAccessibleFromGeneratedPackage)
Expand Down Expand Up @@ -895,7 +900,7 @@ public static Optional<ExecutableElement> findConstructorForBuilder(
* @return {@code true} if an accessible constructor exists
*/
public static boolean hasAccessibleConstructor(
TypeElement typeElement, ProcessingContext context) {
TypeElement typeElement, AnnotationProcessingContext context) {
return ElementFilter.constructorsIn(context.getAllMembers(typeElement)).stream()
.anyMatch(context::isAccessibleFromGeneratedPackage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import org.javahelpers.simple.builders.processor.model.core.BuilderDefinitionDto;
import org.javahelpers.simple.builders.processor.model.type.TypeName;
import org.javahelpers.simple.builders.processor.processing.ProcessingContext;
import org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext;

/**
* Interface for enhancing or modifying generated builders beyond the basic field-based methods.
Expand Down Expand Up @@ -72,7 +72,8 @@
* @param context the processing context for configuration and utilities
* @return true if this enhancer should be applied to this builder
*/
boolean appliesTo(BuilderDefinitionDto builderDto, TypeName dtoType, ProcessingContext context);
boolean appliesTo(
BuilderDefinitionDto builderDto, TypeName dtoType, BuilderProcessingContext context);
Comment thread
AndreasIgel marked this conversation as resolved.

/**
* Enhances the builder by adding or modifying its structure.
Expand All @@ -91,5 +92,5 @@
* @param builderDto the builder to enhance (modifiable)
* @param context the processing context for configuration and utilities
*/
void enhanceBuilder(BuilderDefinitionDto builderDto, ProcessingContext context);
void enhanceBuilder(BuilderDefinitionDto builderDto, BuilderProcessingContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.javahelpers.simple.builders.processor.model.core.FieldDto;
import org.javahelpers.simple.builders.processor.model.method.BuilderMethodDto;
import org.javahelpers.simple.builders.processor.model.type.TypeName;
import org.javahelpers.simple.builders.processor.processing.ProcessingContext;
import org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext;

/**
* Service Provider Interface (SPI) for generating builder methods for fields.
Expand Down Expand Up @@ -67,7 +67,7 @@
* @param context the processing context containing configuration and utilities
* @return true if this generator should generate methods for this field, false otherwise
*/
boolean appliesTo(FieldDto field, TypeName dtoType, ProcessingContext context);
boolean appliesTo(FieldDto field, TypeName dtoType, BuilderProcessingContext context);
Comment thread
AndreasIgel marked this conversation as resolved.

/**
* Generates methods for the given field.
Expand All @@ -85,5 +85,5 @@
* @return list of generated methods (may be empty but should not be null)
*/
List<BuilderMethodDto> generateMethods(
FieldDto field, TypeName builderType, ProcessingContext context);
FieldDto field, TypeName builderType, BuilderProcessingContext context);
}
Loading
Loading