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

Cleanup #18

Merged
merged 10 commits into from
Aug 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,13 +127,14 @@ private Context prepareTemplateContext(final Set<? extends Element> 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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading