Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #21

Merged
merged 12 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion docs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ values={[
<TabItem value="java">

```java
// Create an instance of StyleSniffer
var styleSniffer = StyleSnifferFactory.createStyleSniffer();

// Retrieve a CaseStyle and handle the result
Optional<CaseStyle> caseStyle = styleSniffer.getCaseStyle("myVariableName");
caseStyle.ifPresent(style -> System.out.println("Matched style: " + style.getName()));

// Retrieve and print supported case styles
Set<String> supportedStyles = styleSniffer.getSupportedCaseStyles();
System.out.println("Supported styles: " + supportedStyles);
```
Expand All @@ -64,7 +67,18 @@ System.out.println("Supported styles: " + supportedStyles);

**gradle.properties**
```kotlin
// TODO: document this code for Kotlin
// Create an instance of StyleSniffer
val styleSniffer = StyleSnifferFactory.createStyleSniffer()

// Retrieve a CaseStyle and handle the result
val caseStyle: CaseStyle? = styleSniffer.getCaseStyle("myVariableName")
caseStyle?.let {
println("Matched style: ${it.getName()}")
}

// Retrieve and print supported case styles
val supportedStyles: Set<String> = styleSniffer.getSupportedCaseStyles()
println("Supported styles: $supportedStyles")
```

</TabItem>
Expand Down
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true
108 changes: 71 additions & 37 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@
<packaging>pom</packaging>

<modules>
<module>stylesniffer-api</module>
<module>stylesniffer-impl</module>
<module>stylesniffer-annotation-processor</module>
<module>stylesniffer-api</module>
<module>stylesniffer-testkit</module>
<module>stylesniffer-report-aggregate</module>
</modules>

<properties>
<!-- Java and Encoding -->
<java.sdk.version>21</java.sdk.version>
<source.encoding>UTF-8</source.encoding>
<stylesniffer.root>${basedir}</stylesniffer.root>

<maven.compiler.source>${java.sdk.version}</maven.compiler.source>
<maven.compiler.target>${java.sdk.version}</maven.compiler.target>
<project.build.sourceEncoding>${source.encoding}</project.build.sourceEncoding>

<!-- sonar analysis -->
<!-- Sonar Configuration -->
<sonar.organization>sebastienvermeille</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.language>java</sonar.language>
Expand All @@ -58,22 +56,25 @@
<sonar.tests>src/test/java</sonar.tests>
<sonar.links.homepage>https://stylesniffer.cookiecode.dev/</sonar.links.homepage>
<sonar.links.scm>https://github.com/sebastienvermeille/StyleSniffer</sonar.links.scm>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/report-aggregate/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

<!-- dependencies versions -->
<!-- Dependencies Versions -->
<flogger.version>0.8</flogger.version>
<google-auto-service.version>1.1.1</google-auto-service.version>
<logback.version>1.5.7</logback.version>
<slf4j.version>2.0.16</slf4j.version>
<thymeleaf.version>3.1.2.RELEASE</thymeleaf.version>
<jakarta.annotation.version>3.0.0</jakarta.annotation.version>

<!-- test dependencies versions -->
<!-- Test Dependencies Versions -->
<assertj-core.version>3.26.3</assertj-core.version>
<junit.version>5.11.0</junit.version>
<mockito.version>5.12.0</mockito.version>

<!-- dependencies codegen versions -->
<!-- Code Generation Dependencies -->
<lombok.version>1.18.34</lombok.version>

<!-- maven plugins versions -->
<!-- Maven Plugins Versions -->
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.4.0</maven-surefire-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
Expand All @@ -93,6 +94,12 @@
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.annotation.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
Expand Down Expand Up @@ -127,7 +134,7 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>compile</scope>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
Expand All @@ -141,6 +148,18 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -155,26 +174,66 @@
<release>${java.sdk.version}</release>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${maven-jacoco-plugin.version}</version>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<goals>
<goal>report</goal>
</goals>
<phase>test</phase>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
Expand Down Expand Up @@ -225,6 +284,7 @@
</properties>
</configuration>
</plugin>

<plugin>
<groupId>se.ayoy.maven-plugins</groupId>
<artifactId>ayoy-license-verifier-maven-plugin</artifactId>
Expand All @@ -246,32 +306,6 @@
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${maven-jacoco-plugin.version}</version>
<configuration>
<formats>
<format>HTML</format>
<format>XML</format>
</formats>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
<id>agent</id>
</execution>
<execution>
<goals>
<goal>report</goal>
</goals>
<id>jacoco-report</id>
<phase>test</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
Expand Down
53 changes: 38 additions & 15 deletions stylesniffer-annotation-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>stylesniffer-annotation-processor</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
Expand All @@ -38,15 +39,24 @@
</parent>

<properties>
<maven.compiler.source>${java.sdk.version}</maven.compiler.source>
<maven.compiler.target>${java.sdk.version}</maven.compiler.target>
<project.build.sourceEncoding>${source.encoding}</project.build.sourceEncoding>
<stylesniffer.root>${basedir}/..</stylesniffer.root>
<!-- sonar analysis -->
<sonar.projectKey>${project.sonar.root.projectKey}-${project.groupId}-${project.artifactId}</sonar.projectKey>
</properties>

<dependencies>
<!-- Core Dependencies -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>dev.cookiecode</groupId>
<artifactId>stylesniffer-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

<!-- Annotation Processing -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -55,32 +65,45 @@
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
</dependency>
<dependency>
<artifactId>flogger</artifactId>
<groupId>com.google.flogger</groupId>
<artifactId>flogger</artifactId>
</dependency>
<dependency>
<artifactId>flogger-slf4j-backend</artifactId>
<groupId>com.google.flogger</groupId>
<artifactId>flogger-slf4j-backend</artifactId>
</dependency>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<!-- Testing -->
<dependency>
<groupId>dev.cookiecode</groupId>
<artifactId>stylesniffer-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* The MIT License
* Copyright © 2024 Sebastien Vermeille
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package dev.cookiecode.stylesniffer.annotation.processor;

import dev.cookiecode.stylesniffer.annotation.RegisterCaseStyle;
import java.lang.annotation.Annotation;
import java.util.List;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.TypeElement;
import lombok.NonNull;

/**
* Collects elements annotated with {@link
* dev.cookiecode.stylesniffer.annotation.RegisterCaseStyle}.
*
* <p>This class is responsible for scanning the {@link RoundEnvironment} and extracting the fully
* qualified class names of elements annotated with {@code @RegisterCaseStyle}.
*
* <p>The collected class names are used in the template rendering process.
*
* @author Sebastien Vermeille
* @see dev.cookiecode.stylesniffer.annotation.RegisterCaseStyle
*/
public class CaseStyleElementsCollector {

static final Class<? extends Annotation> ANNOTATION_CLASS = RegisterCaseStyle.class;

public List<String> collectElements(@NonNull RoundEnvironment roundEnv) {
return roundEnv.getElementsAnnotatedWith(ANNOTATION_CLASS).stream()
.map(element -> ((TypeElement) element).getQualifiedName().toString())
.toList();
}
}
Loading
Loading