Skip to content

Commit

Permalink
Merge pull request #6884 from pascalgrimaud/refactoring-improve-engin…
Browse files Browse the repository at this point in the history
…e-code

Refactoring improve engine code
  • Loading branch information
pascalgrimaud authored Jul 14, 2023
2 parents efd4012 + 99e6dbc commit 898f20f
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/tech/jhipster/lite/common/domain/Enums.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ private <From extends Enum<From>, To extends Enum<To>> To get(Enum<From> from, C
};
}

private static record CacheKey<From extends Enum<From>, To extends Enum<To>>(Class<From> from, Class<To> to) {}
private record CacheKey<From extends Enum<From>, To extends Enum<To>>(Class<From> from, Class<To> to) {}
}
}
4 changes: 2 additions & 2 deletions src/main/java/tech/jhipster/lite/common/domain/Memoizers.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private MemoizedResult<Result> toMemoizedResult(MemoizedInput<Input> input) {
return new MemoizedResult<>(function.apply(input.input()));
}

private static record MemoizedInput<Input>(Input input) {}
private record MemoizedInput<Input>(Input input) {}

private static record MemoizedResult<Result>(Result result) {}
private record MemoizedResult<Result>(Result result) {}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tech.jhipster.lite.error.infrastructure.primary;

import java.util.Locale;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -33,7 +34,7 @@ public GeneratorErrorsHandler(@Qualifier("generatorErrorMessageSource") MessageS

@ExceptionHandler(GeneratorException.class)
ProblemDetail handleGeneratorException(GeneratorException exception) {
HttpStatus status = Enums.map(exception.status(), HttpStatus.class);
HttpStatus status = Optional.ofNullable(Enums.map(exception.status(), HttpStatus.class)).orElse(HttpStatus.INTERNAL_SERVER_ERROR);
ProblemDetail problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));

problem.setTitle(getMessage(exception.key(), "title"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private JHipsterModule buildModule(JHipsterModuleProperties properties, SpringDo
//@formatter:on
}

private static record SpringDocDependencies(JavaDependency ui, JavaDependency api) {
private record SpringDocDependencies(JavaDependency ui, JavaDependency api) {
private static final String SPRINGDOC_GROUP_ID = "org.springdoc";
private static final String SPRINGDOC_OPENAPI_WEBMVC_VERSION_KEY = "springdoc-openapi-starter-webmvc";
private static final String SPRINGDOC_OPENAPI_WEBFLUX_VERSION_KEY = "springdoc-openapi-starter-webflux";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,5 @@ public JHipsterModule build() {
}
}

private static record PropertiesKey(SpringProfile profile, SpringPropertyType type) {}
private record PropertiesKey(SpringProfile profile, SpringPropertyType type) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private int buildPort(Integer port) {
return DEFAULT_PORT;
}

return port.intValue();
return port;
}

public int get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected ContentReplacer buildReplacer(JHipsterProjectFilePath file, ElementRep
}
}

private static record MandatoryFileReplacer(JHipsterProjectFilePath file, MandatoryReplacer replacement) implements ContentReplacer {
private record MandatoryFileReplacer(JHipsterProjectFilePath file, MandatoryReplacer replacement) implements ContentReplacer {
public MandatoryFileReplacer {
Assert.notNull("file", file);
Assert.notNull("replacement", replacement);
Expand All @@ -70,7 +70,7 @@ public void handleError(Throwable e) {
}
}

private static record MandatoryReplacer(ElementReplacer replacer, String updatedValue) {
private record MandatoryReplacer(ElementReplacer replacer, String updatedValue) {
public MandatoryReplacer {
Assert.notNull("replacer", replacer);
Assert.notNull("updatedValue", updatedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public final class Enums {
};
}

private static record CacheKey<From extends Enum<From>, To extends Enum<To>>(Class<From> from, Class<To> to) {}
private record CacheKey<From extends Enum<From>, To extends Enum<To>>(Class<From> from, Class<To> to) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public final class Memoizers {
return new MemoizedResult<>(function.apply(input.input()));
}

private static record MemoizedInput<Input>(Input input) {}
private record MemoizedInput<Input>(Input input) {}

private static record MemoizedResult<Result>(Result result) {}
private record MemoizedResult<Result>(Result result) {}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package {{ packageName }}.error.infrastructure.primary;

import java.util.Locale;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -33,7 +34,7 @@ class {{ baseName }}ErrorsHandler {

@ExceptionHandler({{ baseName }}Exception.class)
ProblemDetail handle{{ baseName }}Exception({{ baseName }}Exception exception) {
HttpStatus status = Enums.map(exception.status(), HttpStatus.class);
HttpStatus status = Optional.ofNullable(Enums.map(exception.status(), HttpStatus.class)).orElse(HttpStatus.INTERNAL_SERVER_ERROR);
ProblemDetail problem = ProblemDetail.forStatusAndDetail(status, buildDetail(exception));
problem.setTitle(getMessage(exception.key(), "title"));
Expand Down

0 comments on commit 898f20f

Please sign in to comment.