diff --git a/stylesniffer-annotation-processor/src/main/java/dev/cookiecode/stylesniffer/annotation/processor/RegisterCaseStyleAnnotationProcessor.java b/stylesniffer-annotation-processor/src/main/java/dev/cookiecode/stylesniffer/annotation/processor/RegisterCaseStyleAnnotationProcessor.java index 8f2ec46..8372ce7 100644 --- a/stylesniffer-annotation-processor/src/main/java/dev/cookiecode/stylesniffer/annotation/processor/RegisterCaseStyleAnnotationProcessor.java +++ b/stylesniffer-annotation-processor/src/main/java/dev/cookiecode/stylesniffer/annotation/processor/RegisterCaseStyleAnnotationProcessor.java @@ -25,7 +25,6 @@ import static java.time.LocalDateTime.now; import static java.time.ZoneOffset.UTC; import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME; -import static java.util.stream.Collectors.toList; import dev.cookiecode.stylesniffer.annotation.RegisterCaseStyle; import dev.cookiecode.stylesniffer.api.CaseStyle; @@ -128,13 +127,14 @@ private Context prepareTemplateContext(final Set elements) { List.class.getCanonicalName(), ArrayList.class.getCanonicalName(), IMPLEMENTED_INTERFACE_CLASS.getCanonicalName()); - context.setVariable(TEMPLATE_VARIABLE_IMPORTS, imports.stream().sorted().collect(toList())); + + context.setVariable(TEMPLATE_VARIABLE_IMPORTS, imports.stream().sorted().toList()); context.setVariable(TEMPLATE_VARIABLE_CLASS_NAME, GENERATED_CLASS_NAME); final var classesList = elements.stream() .map(element -> ((TypeElement) element).getQualifiedName().toString()) - .collect(toList()); + .toList(); context.setVariable(TEMPLATE_VARIABLE_ELEMENTS, classesList); diff --git a/stylesniffer-api/src/main/java/dev/cookiecode/stylesniffer/api/exception/StyleSnifferException.java b/stylesniffer-api/src/main/java/dev/cookiecode/stylesniffer/api/exception/StyleSnifferException.java new file mode 100644 index 0000000..d6fc1d5 --- /dev/null +++ b/stylesniffer-api/src/main/java/dev/cookiecode/stylesniffer/api/exception/StyleSnifferException.java @@ -0,0 +1,31 @@ +/* + * 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.api.exception; + +import lombok.experimental.StandardException; + +/** + * @author Sebastien Vermeille + */ +@StandardException +public class StyleSnifferException extends RuntimeException {} diff --git a/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/StyleSniffer.java b/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/StyleSniffer.java index cfc7c64..54ea600 100644 --- a/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/StyleSniffer.java +++ b/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/StyleSniffer.java @@ -26,6 +26,7 @@ import static java.util.stream.Collectors.toSet; import dev.cookiecode.stylesniffer.api.CaseStyle; +import dev.cookiecode.stylesniffer.api.exception.StyleSnifferException; import dev.cookiecode.stylesniffer.generated.CaseStyleInjector; import java.util.ArrayList; import java.util.List; @@ -60,7 +61,7 @@ public class StyleSniffer { try { this.registerAllAnnotatedCaseStyles(); } catch (final Exception e) { - throw new RuntimeException("Failed to initialize CaseStyleRecognizer", e); + throw new StyleSnifferException("Failed to initialize CaseStyleRecognizer", e); } } @@ -82,7 +83,7 @@ private void registerAllAnnotatedCaseStyles() { try { this.caseStyles.add(clazz.getDeclaredConstructor().newInstance()); } catch (final Exception e) { - throw new RuntimeException( + throw new StyleSnifferException( String.format("Failed to instantiate case style: %s", clazz.getName()), e); } } diff --git a/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/impl/PascalCaseStyle.java b/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/impl/PascalCaseStyle.java index 07d9e5c..92b9800 100644 --- a/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/impl/PascalCaseStyle.java +++ b/stylesniffer-impl/src/main/java/dev/cookiecode/stylesniffer/impl/PascalCaseStyle.java @@ -87,7 +87,7 @@ private boolean isPascalCase(@NonNull final String name) { if (seenLowercase && isUpperCase(previousChar)) { continue; } - if (!seenLowercase || (seenLowercase && isLowerCase(previousChar))) { + if (!seenLowercase || isLowerCase(previousChar)) { continue; } }