From 0081a8786deb8337c60f21321c1ce5b28b82e711 Mon Sep 17 00:00:00 2001 From: h908714124 Date: Tue, 3 Aug 2021 15:02:05 +0200 Subject: [PATCH] refactoring --- .../{AutoMappings.java => AutoMapper.java} | 4 +-- .../jbock/convert/matching/AutoValidator.java | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) rename compiler/src/main/java/net/jbock/convert/matching/{AutoMappings.java => AutoMapper.java} (99%) diff --git a/compiler/src/main/java/net/jbock/convert/matching/AutoMappings.java b/compiler/src/main/java/net/jbock/convert/matching/AutoMapper.java similarity index 99% rename from compiler/src/main/java/net/jbock/convert/matching/AutoMappings.java rename to compiler/src/main/java/net/jbock/convert/matching/AutoMapper.java index 6c120ee49..afe12f6e9 100644 --- a/compiler/src/main/java/net/jbock/convert/matching/AutoMappings.java +++ b/compiler/src/main/java/net/jbock/convert/matching/AutoMapper.java @@ -29,7 +29,7 @@ import static net.jbock.common.Constants.STRING; @ValidateScope -public class AutoMappings { +public class AutoMapper { private static final String NEW = "new"; private static final String CREATE = "create"; @@ -42,7 +42,7 @@ public class AutoMappings { private final List conversions; @Inject - AutoMappings( + AutoMapper( TypeTool tool, Util util) { this.tool = tool; diff --git a/compiler/src/main/java/net/jbock/convert/matching/AutoValidator.java b/compiler/src/main/java/net/jbock/convert/matching/AutoValidator.java index b534e6a85..8041ea84c 100644 --- a/compiler/src/main/java/net/jbock/convert/matching/AutoValidator.java +++ b/compiler/src/main/java/net/jbock/convert/matching/AutoValidator.java @@ -24,16 +24,16 @@ @ValidateScope public class AutoValidator { - private final AutoMappings autoConverter; + private final AutoMapper autoMapper; private final Util util; private final MatchFinder matchFinder; @Inject AutoValidator( - AutoMappings autoConverter, + AutoMapper autoMapper, Util util, MatchFinder matchFinder) { - this.autoConverter = autoConverter; + this.autoMapper = autoMapper; this.util = util; this.matchFinder = matchFinder; } @@ -42,21 +42,22 @@ public class AutoValidator { Either> findMapping( M sourceMethod) { return matchFinder.findMatch(sourceMethod) - .flatMap(m -> findMapping(sourceMethod, m)); + .flatMap(m -> findEnumOrAutoMapping(sourceMethod, m)); } private - Either> findMapping( + Either> findEnumOrAutoMapping( M sourceMethod, ValidMatch match) { - return autoConverter.findAutoMapping(sourceMethod, match) - .flatMapLeft(message -> findEnumMapping(sourceMethod, match.baseType())); + return autoMapper.findAutoMapping(sourceMethod, match) + .flatMapLeft(message -> findEnumMapping(sourceMethod, match)); } private Either> findEnumMapping( M sourceMethod, - TypeMirror baseType) { + ValidMatch match) { + TypeMirror baseType = match.baseType(); return TypeTool.AS_DECLARED.visit(baseType) .map(DeclaredType::asElement) .flatMap(TypeTool.AS_TYPE_ELEMENT::visit) @@ -64,14 +65,13 @@ Either> findEnumMapping( .map(TypeElement::asType) .>map(Either::right) .orElseGet(() -> left(sourceMethod.fail(util.noMatchError(baseType)))) - .flatMap(enumType -> matchFinder.findMatch(sourceMethod) - .map(match -> { - CodeBlock code = enumConvertBlock(enumType); - return Mapping.create(code, match, true); - })); + .map(enumType -> { + CodeBlock code = enumConversionCode(enumType); + return Mapping.create(code, match, true); + }); } - private CodeBlock enumConvertBlock(TypeMirror enumType) { + private CodeBlock enumConversionCode(TypeMirror enumType) { ParameterSpec token = ParameterSpec.builder(STRING, "token").build(); ParameterSpec e = ParameterSpec.builder(IllegalArgumentException.class, "e").build(); ParameterSpec values = ParameterSpec.builder(STRING, "values").build();