From 33beb525af3a9721da10f86ee5c3aef9e52253ba Mon Sep 17 00:00:00 2001 From: levik Date: Fri, 1 Dec 2023 14:27:30 +0200 Subject: [PATCH 1/3] BLZT-43: small sonar fixes. --- .../bfpp/BeanPostProcessorDefinitionFactory.java | 4 ++-- .../bring/web/servlet/http/HttpHeaders.java | 4 ++-- .../bring/web/servlet/http/HttpStatus.java | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/bobocode/bring/core/bfpp/BeanPostProcessorDefinitionFactory.java b/core/src/main/java/com/bobocode/bring/core/bfpp/BeanPostProcessorDefinitionFactory.java index 68d5f561..635f004c 100644 --- a/core/src/main/java/com/bobocode/bring/core/bfpp/BeanPostProcessorDefinitionFactory.java +++ b/core/src/main/java/com/bobocode/bring/core/bfpp/BeanPostProcessorDefinitionFactory.java @@ -43,7 +43,7 @@ public class BeanPostProcessorDefinitionFactory { /** * The list of bean factory post-processors created by this factory. */ - private final List beanFactoryPostProcessors; + private final List beanFactoryPostProcessors; /** * Constructs a new BeanPostProcessorDefinitionFactory and initializes the list of post-processors. @@ -57,7 +57,7 @@ public BeanPostProcessorDefinitionFactory(Reflections reflections) { .stream() .sorted(ORDER_COMPARATOR) .map(clazz -> clazz.cast(getConstructorWithOutParameters(clazz))) - .collect(Collectors.toList()); + .toList(); log.info("Register BeanFactoryPostProcessors {}", Arrays.toString(beanFactoryPostProcessors.toArray())); } diff --git a/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpHeaders.java b/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpHeaders.java index b5f68a77..bf133484 100644 --- a/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpHeaders.java +++ b/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpHeaders.java @@ -19,12 +19,12 @@ public class HttpHeaders { /** * Map to store header name-value pairs. */ - Map headers; + private final Map headers; /** * List containing all header names as strings. */ - private List headersNameList; + private final List headersNameList; /** * Constructs a new HttpHeaders object with an empty header map and initializes the list of header names. diff --git a/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpStatus.java b/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpStatus.java index 84c794b9..3d6e7b85 100644 --- a/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpStatus.java +++ b/web/src/main/java/com/bobocode/bring/web/servlet/http/HttpStatus.java @@ -12,7 +12,6 @@ * @author Blyzhnytsia Team * @since 1.0 */ -@Getter public enum HttpStatus { // 1xx Informational @@ -354,6 +353,17 @@ public enum HttpStatus { this.reasonPhrase = reasonPhrase; } + public int getValue() { + return value; + } + + public Series getSeries() { + return series; + } + + public String getReasonPhrase() { + return reasonPhrase; + } public enum Series { @@ -368,5 +378,9 @@ public enum Series { } private final int value; + + public int getValue() { + return value; + } } } From 4d919c42e34ee4622b9baa0a25d0a98fcc009bb1 Mon Sep 17 00:00:00 2001 From: levik Date: Fri, 1 Dec 2023 15:18:55 +0200 Subject: [PATCH 2/3] BLZT-43: add more javadoc. --- .../bring/core/annotation/Autowired.java | 28 ++++++++++++++++++- .../bring/core/annotation/BeanProcessor.java | 3 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java b/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java index 3041c240..9db19497 100644 --- a/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java +++ b/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java @@ -18,9 +18,35 @@ *

This annotation is part of the Bring Framework's dependency injection mechanism, enabling the creation of loosely * coupled and easily testable components. * - *

Usage Example: + *

When we have a class possesses only one constructor, explicitly adding the @Autowired annotation isn't mandatory. + * Bring inherently knows which constructor to invoke and handles it accordingly.

+ * + *

For classes with multiple constructors, it becomes imperative to specify to Bring which constructor should be utilized + * through the @Autowired annotation. This annotation acts as a directive for Bing to identify + * and use the designated constructor to resolve dependencies properly.

+ * + *

This way, when Bring encounters multiple constructors within a class, the @Autowired annotation guides it in selecting the appropriate constructor for dependency resolution.

+ * + *

Usage Examples: + * *

  * {@code
+ *  import com.bobocode.bring.core.annotation.Service;
+ *
+ * import java.util.List;
+ * import java.util.stream.Collectors;
+ *
+ * @Service
+ * public class Barista {
+ *     private final List drinks;
+ *
+ *     public Barista(List drinks) {
+ *         this.drinks = drinks;
+ *     }
+ * }
+ * 
+ *
+ * {@code
  *  @Component
  *  public class MyComponent {
  *
diff --git a/core/src/main/java/com/bobocode/bring/core/annotation/BeanProcessor.java b/core/src/main/java/com/bobocode/bring/core/annotation/BeanProcessor.java
index 7a841b61..4e80994d 100644
--- a/core/src/main/java/com/bobocode/bring/core/annotation/BeanProcessor.java
+++ b/core/src/main/java/com/bobocode/bring/core/annotation/BeanProcessor.java
@@ -9,7 +9,8 @@
  * Annotation used to mark extensions for custom scanners, resolvers, or processors in the client's application.
  * These extensions can be used to perform specific tasks related to bean scanning, resolving, or processing.
  * In addition, we have some limitation on constructor some of the classes should have only default or one field.
- * for instance RestControllerBeanPostProcessor
+ * for instance RestControllerBeanPostProcessor.
+ * This limitation only for customization scanners, resolvers, or processors
  *
  *  @author Blyzhnytsia Team
  *  @since 1.0

From ee8400b167e468c6035189b97788ab08efa367ed Mon Sep 17 00:00:00 2001
From: levik 
Date: Fri, 1 Dec 2023 19:13:54 +0200
Subject: [PATCH 3/3] BLZT-43: add more javadoc.

---
 .../bring/core/annotation/Autowired.java      | 50 +++----------------
 .../type/AbstractValueTypeInjector.java       |  2 +-
 2 files changed, 8 insertions(+), 44 deletions(-)

diff --git a/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java b/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java
index 9db19497..5b5056f1 100644
--- a/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java
+++ b/core/src/main/java/com/bobocode/bring/core/annotation/Autowired.java
@@ -10,57 +10,21 @@
  * This annotation can be applied to fields, constructors, and methods in a Bring bean class to let Bring automatically
  * inject the dependencies at runtime.
  *
- * 

When applied to a field, the Bring IoC container will automatically inject a compatible bean, resolved by type, + * When applied to a field, the Bring IoC container will automatically inject a compatible bean, resolved by type, * into the annotated field. When applied to a constructor, the container will use constructor injection to provide * the required dependencies. If applied to a method, the container will invoke the method after initializing the bean, * injecting the necessary dependencies into the method parameters. * - *

This annotation is part of the Bring Framework's dependency injection mechanism, enabling the creation of loosely + * This annotation is part of the Bring Framework's dependency injection mechanism, enabling the creation of loosely * coupled and easily testable components. * - *

When we have a class possesses only one constructor, explicitly adding the @Autowired annotation isn't mandatory. - * Bring inherently knows which constructor to invoke and handles it accordingly.

+ * When we have a class possesses only one constructor, explicitly adding the @Autowired annotation isn't mandatory. + * Bring inherently knows which constructor to invoke and handles it accordingly. * - *

For classes with multiple constructors, it becomes imperative to specify to Bring which constructor should be utilized + * For classes with multiple constructors, it becomes imperative to specify to Bring which constructor should be utilized * through the @Autowired annotation. This annotation acts as a directive for Bing to identify - * and use the designated constructor to resolve dependencies properly.

- * - *

This way, when Bring encounters multiple constructors within a class, the @Autowired annotation guides it in selecting the appropriate constructor for dependency resolution.

- * - *

Usage Examples: - * - *

- * {@code
- *  import com.bobocode.bring.core.annotation.Service;
- *
- * import java.util.List;
- * import java.util.stream.Collectors;
- *
- * @Service
- * public class Barista {
- *     private final List drinks;
- *
- *     public Barista(List drinks) {
- *         this.drinks = drinks;
- *     }
- * }
- * 
- *
- * {@code
- *  @Component
- *  public class MyComponent {
- *
- *      @Autowired
- *      private MyDependency myDependency;
- *
- *      // Constructors and methods can also be annotated
- *      @Autowired
- *      public MyComponent(MyDependency myDependency) {
- *          this.myDependency = myDependency;
- *      }
- *  }
- * }
- * 
+ * and use the designated constructor to resolve dependencies properly. + * This way, when Bring encounters multiple constructors within a class, the @Autowired annotation guides it in selecting the appropriate constructor for dependency resolution. * * @author Blyzhnytsia Team * @since 1.0 diff --git a/core/src/main/java/com/bobocode/bring/core/context/type/AbstractValueTypeInjector.java b/core/src/main/java/com/bobocode/bring/core/context/type/AbstractValueTypeInjector.java index 162dc88d..be329a88 100644 --- a/core/src/main/java/com/bobocode/bring/core/context/type/AbstractValueTypeInjector.java +++ b/core/src/main/java/com/bobocode/bring/core/context/type/AbstractValueTypeInjector.java @@ -26,7 +26,7 @@ */ public abstract class AbstractValueTypeInjector { - private final static BiFunction, String, List> PRIMARY_FILTER_FUNCTION = + private static final BiFunction, String, List> PRIMARY_FILTER_FUNCTION = (beanDefinitions, qualifier) -> beanDefinitions.stream() .filter(BeanDefinition::isPrimary ).toList();