Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
875f41b
Replacing StringUtils.equalsIgnoreCase by Strings.CI.equals
AndreasIgel Oct 9, 2025
0aa4827
Solving possible nullpointer-exception from static code analysis
AndreasIgel Oct 9, 2025
8c5c4a9
Adding private constructor for utility-class
AndreasIgel Oct 9, 2025
7bbf600
Fixing codesmells
AndreasIgel Oct 9, 2025
376fc93
Adding configuration for sonar-server of project
AndreasIgel Oct 9, 2025
11831b2
Solving sonarQube issue
AndreasIgel Oct 9, 2025
0f84416
Replacing raw type by generic
AndreasIgel Oct 9, 2025
0b4a2b6
Replacing member variable by function parameters
AndreasIgel Oct 9, 2025
bd4900e
Do not return true for processing of annotations, which could not be …
AndreasIgel Oct 9, 2025
4cc62c1
Reducing complexity of extractParamJavaDoc
AndreasIgel Oct 9, 2025
663e5f9
Replacing deprecated StringUtils.removeStart by Strings.CI.removeStart
AndreasIgel Oct 9, 2025
9ad66a3
Replacing rawtype HashSet by diamond HashSet<>
AndreasIgel Oct 9, 2025
4caf95f
Fixing serialization issue in BuilderException
AndreasIgel Oct 9, 2025
c1ef825
Replacing repeated literals by constants
AndreasIgel Oct 9, 2025
23cbab9
Adding Badges from SonarQube
AndreasIgel Oct 9, 2025
37a6b9e
Using paramized Test instead multiple tests
AndreasIgel Oct 9, 2025
8cf3228
Removing protected accessor because this is done in junit jupiter dif…
AndreasIgel Oct 9, 2025
0fca016
Replacing optional by own wrapper type, because optional should be su…
AndreasIgel Oct 9, 2025
09b3a1f
Integration of messages to be used for logging
AndreasIgel Oct 9, 2025
94604af
Refactoring to enclose typeUtils and elementUtils in ProcessingContex…
AndreasIgel Oct 9, 2025
37e56dc
Moving logger into ProcessingContext too
AndreasIgel Oct 9, 2025
25410ad
Solving todos by adding missing loggins
AndreasIgel Oct 9, 2025
7bc9283
Fixing asserts to handle compile-errors and warnings now
AndreasIgel Oct 9, 2025
de5f670
Fixing handling of methods with one parameter to not be recognized to…
AndreasIgel Oct 9, 2025
436e25c
Moving java-util package name in a constant
AndreasIgel Oct 9, 2025
dad754f
Replacing deprecated Compiler.javac() by static import
AndreasIgel Oct 9, 2025
4dcc235
Replacing call to java() by helper-function
AndreasIgel Oct 9, 2025
1db578c
Suppress warning because there is no better solution there with possi…
AndreasIgel Oct 9, 2025
6e029fc
Adding sonar-project.properties so that configuration is correctly go…
AndreasIgel Oct 9, 2025
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
5 changes: 5 additions & 0 deletions .sonarlint/connectedMode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sonarCloudOrganization": "java-helpers",
"projectKey": "java-helpers_simple-builders",
"region": "EU"
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[![Java Version](https://img.shields.io/badge/Java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/17-relnote-issues.html)
[![Maven](https://img.shields.io/badge/Maven-3.8%2B-orange)](https://maven.apache.org/)
[![codecov](https://codecov.io/gh/java-helpers/simple-builders/graph/badge.svg)](https://codecov.io/gh/java-helpers/simple-builders)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=java-helpers_simple-builders&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=java-helpers_simple-builders)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=java-helpers_simple-builders&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=java-helpers_simple-builders)

## Table of Contents
- [What is Simple Builders?](#what-is-simple-builders)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public HashSetBuilder<T> addAll(Set<T> elements) {
* @return a new HashSet containing all elements added to this builder
*/
public Set<T> build() {
return new HashSet(mSet);
return new HashSet<>(mSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@
import com.google.auto.service.AutoService;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import org.javahelpers.simple.builders.processor.dtos.BuilderDefinitionDto;
import org.javahelpers.simple.builders.processor.exceptions.BuilderException;
import org.javahelpers.simple.builders.processor.util.JavaCodeGenerator;
import org.javahelpers.simple.builders.processor.util.ProcessingContext;
import org.javahelpers.simple.builders.processor.util.ProcessingLogger;

/**
* BuilderProcessor is an annotation processor for execution in generate-sources phase. The
Expand All @@ -53,30 +50,26 @@
@AutoService(Processor.class)
@SupportedAnnotationTypes("org.javahelpers.simple.builders.core.annotations.SimpleBuilder")
public class BuilderProcessor extends AbstractProcessor {
private Types typeUtils;
private Elements elementUtils;
private Filer filer;
private Messager messager;
private ProcessingContext context;
private JavaCodeGenerator codeGenerator;
private boolean supportedJdk = true;

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
this.typeUtils = processingEnv.getTypeUtils();
this.elementUtils = processingEnv.getElementUtils();
this.filer = processingEnv.getFiler();
this.messager = processingEnv.getMessager();
this.codeGenerator = new JavaCodeGenerator(filer);
ProcessingLogger logger = new ProcessingLogger(processingEnv.getMessager());
this.context =
new ProcessingContext(
processingEnv.getElementUtils(), processingEnv.getTypeUtils(), logger);
this.codeGenerator = new JavaCodeGenerator(processingEnv.getFiler());

// Enforce minimum Java version (17+) for the processor
SourceVersion current = processingEnv.getSourceVersion();
this.supportedJdk = isAtLeastJava17(current);
if (!this.supportedJdk) {
messager.printMessage(
Diagnostic.Kind.ERROR,
context.error(
"simple-builders requires Java 17 or higher for annotation processing. Detected: "
+ String.valueOf(current)
+ current
+ ". Please upgrade to JDK 17+ or disable the processor.");
}
}
Expand All @@ -85,24 +78,24 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!supportedJdk) {
// Fail fast: we already emitted an error in init(); do not attempt any processing.
return true;
return false;
}
// Resolve annotation as TypeElement to support environments where the Class<?> overload
// of getElementsAnnotatedWith is unavailable.
TypeElement simpleBuilderAnnotation =
elementUtils.getTypeElement(
context.getTypeElement(
org.javahelpers.simple.builders.core.annotations.SimpleBuilder.class
.getCanonicalName());
if (simpleBuilderAnnotation == null) {
// TODO: Logging
// Annotation type not on classpath; nothing to do this round.
return true;
context.error(
"Annotation org.javahelpers.simple.builders.core.annotations.SimpleBuilder is not on classpath. So nothing to do here.");
return false;
}
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(simpleBuilderAnnotation)) {
try {
process(annotatedElement);
} catch (BuilderException ex) {
// TODO Logging
context.error(annotatedElement, "Failed to process annotated element: " + ex.getMessage());
}
}
return true;
Expand All @@ -114,7 +107,7 @@ public SourceVersion getSupportedSourceVersion() {
}

private void process(Element annotatedElement) throws BuilderException {
BuilderDefinitionDto builderDef = extractFromElement(annotatedElement, elementUtils, typeUtils);
BuilderDefinitionDto builderDef = extractFromElement(annotatedElement, context);
codeGenerator.generateBuilder(builderDef);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MethodCodeDto {
private String codeFormat;

/** List of placeholders in CodeFormat. Containing dynamic values too. */
private final List<MethodCodePlaceholder> codeArguments = new ArrayList<>();
private final List<MethodCodePlaceholder<?>> codeArguments = new ArrayList<>();

/**
* Setting format of code.
Expand Down Expand Up @@ -78,7 +78,8 @@ public String getCodeFormat() {
*
* @return argument values
*/
public List<MethodCodePlaceholder> getCodeArguments() {
@SuppressWarnings("java:S1452")
public List<MethodCodePlaceholder<?>> getCodeArguments() {
return codeArguments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class MethodCodePlaceholder<T> {
* @param label name of placeholder
* @param value dynamic value for placeholder
*/
public MethodCodePlaceholder(String label, T value) {
protected MethodCodePlaceholder(String label, T value) {
this.label = label;
this.value = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

/** Special exception for errors in processing of annotations. */
public class BuilderException extends Exception {
private final Element element;
private final transient Element element;

/**
* Creating an exception with location element, message and parameters.
Expand Down
Loading
Loading