From b560b953cff639828a3f4eef38d5b7ac3bb3adc3 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sun, 26 Oct 2014 22:41:04 +0100 Subject: [PATCH] #330 Formatting --- .../mapstruct/ap/model/EnumMappingMethod.java | 110 +++++++++--------- .../ap/model/source/SourceMethod.java | 19 +-- .../source/constants/SourceConstantsTest.java | 10 +- 3 files changed, 72 insertions(+), 67 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/EnumMappingMethod.java index 9c04b63b0..b848420b5 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/EnumMappingMethod.java @@ -20,7 +20,6 @@ package org.mapstruct.ap.model; import java.util.ArrayList; import java.util.List; - import javax.tools.Diagnostic; import org.mapstruct.ap.model.common.Parameter; @@ -45,12 +44,12 @@ public class EnumMappingMethod extends MappingMethod { private SourceMethod method; private MappingBuilderContext ctx; - public Builder mappingContext( MappingBuilderContext mappingContext ) { + public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; return this; } - public Builder souceMethod( SourceMethod sourceMethod ) { + public Builder souceMethod(SourceMethod sourceMethod) { this.method = sourceMethod; return this; } @@ -58,14 +57,14 @@ public class EnumMappingMethod extends MappingMethod { public EnumMappingMethod build() { if ( !reportErrorIfMappedEnumConstantsDontExist( method ) - || !reportErrorIfSourceEnumConstantsWithoutCorrespondingTargetConstantAreNotMapped( method ) ) { + || !reportErrorIfSourceEnumConstantsWithoutCorrespondingTargetConstantAreNotMapped( method ) ) { return null; } List enumMappings = new ArrayList(); List sourceEnumConstants - = method.getSourceParameters().iterator().next().getType().getEnumConstants(); + = method.getSourceParameters().iterator().next().getType().getEnumConstants(); for ( String enumConstant : sourceEnumConstants ) { List mappedConstants = method.getMappingBySourcePropertyName( enumConstant ); @@ -74,8 +73,11 @@ public class EnumMappingMethod extends MappingMethod { enumMappings.add( new EnumMapping( enumConstant, enumConstant ) ); } else if ( mappedConstants.size() == 1 ) { - enumMappings.add( new EnumMapping( - enumConstant, mappedConstants.iterator().next().getTargetName() ) ); + enumMappings.add( + new EnumMapping( + enumConstant, mappedConstants.iterator().next().getTargetName() + ) + ); } else { List targetConstants = new ArrayList( mappedConstants.size() ); @@ -83,14 +85,14 @@ public class EnumMappingMethod extends MappingMethod { targetConstants.add( mapping.getTargetName() ); } ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - String.format( - "One enum constant must not be mapped to more than one target constant, " - + "but constant %s is mapped to %s.", - enumConstant, - Strings.join( targetConstants, ", " ) - ), - method.getExecutable() + Diagnostic.Kind.ERROR, + String.format( + "One enum constant must not be mapped to more than one target constant, " + + "but constant %s is mapped to %s.", + enumConstant, + Strings.join( targetConstants, ", " ) + ), + method.getExecutable() ); } } @@ -98,14 +100,14 @@ public class EnumMappingMethod extends MappingMethod { return new EnumMappingMethod( method, enumMappings ); } - private boolean reportErrorIfMappedEnumConstantsDontExist( SourceMethod method ) { + private boolean reportErrorIfMappedEnumConstantsDontExist(SourceMethod method) { // only report errors if this method itself is configured if ( method.isConfiguredByReverseMappingMethod() ) { return true; } List sourceEnumConstants = - method.getSourceParameters().iterator().next().getType().getEnumConstants(); + method.getSourceParameters().iterator().next().getType().getEnumConstants(); List targetEnumConstants = method.getReturnType().getEnumConstants(); boolean foundIncorrectMapping = false; @@ -114,47 +116,47 @@ public class EnumMappingMethod extends MappingMethod { for ( Mapping mappedConstant : mappedConstants ) { if ( mappedConstant.getSourceName() == null ) { ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - "A source constant must be specified for mappings of an enum mapping method.", - method.getExecutable(), - mappedConstant.getMirror() + Diagnostic.Kind.ERROR, + "A source constant must be specified for mappings of an enum mapping method.", + method.getExecutable(), + mappedConstant.getMirror() ); foundIncorrectMapping = true; } else if ( !sourceEnumConstants.contains( mappedConstant.getSourceName() ) ) { ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - String.format( - "Constant %s doesn't exist in enum type %s.", - mappedConstant.getSourceName(), - method.getSourceParameters().iterator().next().getType() - ), - method.getExecutable(), - mappedConstant.getMirror(), - mappedConstant.getSourceAnnotationValue() + Diagnostic.Kind.ERROR, + String.format( + "Constant %s doesn't exist in enum type %s.", + mappedConstant.getSourceName(), + method.getSourceParameters().iterator().next().getType() + ), + method.getExecutable(), + mappedConstant.getMirror(), + mappedConstant.getSourceAnnotationValue() ); foundIncorrectMapping = true; } if ( mappedConstant.getTargetName() == null ) { ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - "A target constant must be specified for mappings of an enum mapping method.", - method.getExecutable(), - mappedConstant.getMirror() + Diagnostic.Kind.ERROR, + "A target constant must be specified for mappings of an enum mapping method.", + method.getExecutable(), + mappedConstant.getMirror() ); foundIncorrectMapping = true; } else if ( !targetEnumConstants.contains( mappedConstant.getTargetName() ) ) { ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - String.format( - "Constant %s doesn't exist in enum type %s.", - mappedConstant.getTargetName(), - method.getReturnType() - ), - method.getExecutable(), - mappedConstant.getMirror(), - mappedConstant.getTargetAnnotationValue() + Diagnostic.Kind.ERROR, + String.format( + "Constant %s doesn't exist in enum type %s.", + mappedConstant.getTargetName(), + method.getReturnType() + ), + method.getExecutable(), + mappedConstant.getMirror(), + mappedConstant.getTargetAnnotationValue() ); foundIncorrectMapping = true; } @@ -165,29 +167,29 @@ public class EnumMappingMethod extends MappingMethod { } private boolean reportErrorIfSourceEnumConstantsWithoutCorrespondingTargetConstantAreNotMapped( - SourceMethod method ) { + SourceMethod method) { List sourceEnumConstants = - method.getSourceParameters().iterator().next().getType().getEnumConstants(); + method.getSourceParameters().iterator().next().getType().getEnumConstants(); List targetEnumConstants = method.getReturnType().getEnumConstants(); List unmappedSourceEnumConstants = new ArrayList(); for ( String sourceEnumConstant : sourceEnumConstants ) { if ( !targetEnumConstants.contains( sourceEnumConstant ) - && method.getMappingBySourcePropertyName( sourceEnumConstant ).isEmpty() ) { + && method.getMappingBySourcePropertyName( sourceEnumConstant ).isEmpty() ) { unmappedSourceEnumConstants.add( sourceEnumConstant ); } } if ( !unmappedSourceEnumConstants.isEmpty() ) { ctx.getMessager().printMessage( - Diagnostic.Kind.ERROR, - String.format( - "The following constants from the source enum have no corresponding constant in the " - + "target enum and must be be mapped via @Mapping: %s", - Strings.join( unmappedSourceEnumConstants, ", " ) - ), - method.getExecutable() + Diagnostic.Kind.ERROR, + String.format( + "The following constants from the source enum have no corresponding constant in the " + + "target enum and must be be mapped via @Mapping: %s", + Strings.join( unmappedSourceEnumConstants, ", " ) + ), + method.getExecutable() ); } @@ -196,7 +198,7 @@ public class EnumMappingMethod extends MappingMethod { } - private EnumMappingMethod( Method method, List enumMappings ) { + private EnumMappingMethod(Method method, List enumMappings) { super( method ); this.enumMappings = enumMappings; } diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/model/source/SourceMethod.java index c334566a6..b3498febb 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/SourceMethod.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; - import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.util.Types; @@ -76,7 +75,8 @@ public class SourceMethod implements Method { mappings, iterableMapping, mapMapping, - typeUtils ); + typeUtils + ); } public static SourceMethod forReferencedMethod(Type declaringMapper, ExecutableElement executable, @@ -89,10 +89,11 @@ public class SourceMethod implements Method { parameters, returnType, exceptionTypes, - Collections.> emptyMap(), + Collections.>emptyMap(), null, null, - typeUtils ); + typeUtils + ); } public static SourceMethod forFactoryMethod(Type declaringMapper, ExecutableElement executable, Type returnType, @@ -101,13 +102,14 @@ public class SourceMethod implements Method { return new SourceMethod( declaringMapper, executable, - Collections. emptyList(), + Collections.emptyList(), returnType, exceptionTypes, - Collections.> emptyMap(), + Collections.>emptyMap(), null, null, - typeUtils ); + typeUtils + ); } private SourceMethod(Type declaringMapper, ExecutableElement executable, List parameters, @@ -214,7 +216,7 @@ public class SourceMethod implements Method { /** * @return the {@link Mapping}s configured for this method, keyed by target property name. Only for enum mapping - * methods a target will be mapped by several sources. + * methods a target will be mapped by several sources. */ public Map> getMappings() { return mappings; @@ -352,6 +354,7 @@ public class SourceMethod implements Method { /** * @param parameters the parameter list to check + * * @return true, iff the parameter list contains a parameter annotated with {@code @TargetType} */ public static boolean containsTargetTypeParameter(List parameters) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index 9d37d8f94..09baef7d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -18,13 +18,10 @@ */ package org.mapstruct.ap.test.source.constants; -import static org.fest.assertions.Assertions.assertThat; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; - import javax.tools.Diagnostic.Kind; import org.junit.Test; @@ -36,6 +33,8 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.fest.assertions.Assertions.assertThat; + /** * @author Sjaak Derksen */ @@ -124,8 +123,9 @@ public class SourceConstantsTest { @Diagnostic(type = ErroneousMapper3.class, kind = Kind.ERROR, line = 41, - messageRegExp = "Expression and constant are both defined in @Mapping, either define an expression or a " - + "constant"), + messageRegExp = + "Expression and constant are both defined in @Mapping, either define an expression or a " + + "constant"), @Diagnostic(type = ErroneousMapper3.class, kind = Kind.WARNING, line = 41,