From 2e09944b19360d417623a93aee13f797d76d7cc1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 May 2017 14:15:46 +0200 Subject: [PATCH] #1213 General code cleanups: * #122 Use util methods when possible * Fix some warnings in Javadoc generation * Don't use raw classes when not needed * Add .yml, binding.xjb and .asciidoc files to license check exclusion --- .../org/mapstruct/NullValueCheckStrategy.java | 5 ++-- parent/pom.xml | 3 +++ .../BigDecimalToStringConversion.java | 2 +- .../BigIntegerToStringConversion.java | 2 +- .../ap/internal/model/IterableCreation.java | 2 +- .../model/common/ImplementationType.java | 2 +- .../ap/internal/model/common/Type.java | 8 +++--- .../ap/internal/model/common/TypeFactory.java | 8 +++--- .../model/source/SourceReference.java | 26 ++++++++----------- .../model/source/TargetReference.java | 8 +++--- .../test/collection/wildcard/BeanMapper.java | 2 +- .../collection/wildcard/WildCardTest.java | 2 +- 12 files changed, 34 insertions(+), 36 deletions(-) diff --git a/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java b/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java index c6294ffff..c6c0dbfd5 100644 --- a/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java +++ b/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java @@ -30,12 +30,13 @@ public enum NullValueCheckStrategy { /** * This option includes a null check. When: - *

+ *
+ *
*

    *
  1. a source value is directly assigned to a target
  2. *
  3. a source value assigned to a target by calling a type conversion on the target first
  4. *
- *

+ *
* NOTE: mapping methods (generated or hand written) are excluded from this null check. They are intended to * handle a null source value as 'valid' input. * diff --git a/parent/pom.xml b/parent/pom.xml index b8cd6ebca..531714a9f 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -534,6 +534,9 @@ .gitignore .factorypath .checkstyle + *.yml + **/*.asciidoc + **/binding.xjb diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index c3b7953b0..2e19ee8aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -74,7 +74,7 @@ public class BigDecimalToStringConversion extends AbstractNumberToStringConversi @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - List helpers = new ArrayList(); + List helpers = new ArrayList(); if ( conversionContext.getNumberFormat() != null ) { helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index e55bb3eee..6b99b0fd1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -81,7 +81,7 @@ public class BigIntegerToStringConversion extends AbstractNumberToStringConversi @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - List helpers = new ArrayList(); + List helpers = new ArrayList(); if ( conversionContext.getNumberFormat() != null ) { helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java index e54cd98b8..a1afac6f7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java @@ -27,7 +27,7 @@ import org.mapstruct.ap.internal.model.common.Type; /** * Model element that can be used to create a type of {@link Iterable} or {@link java.util.Map}. If an implementation - * type is used and the target type has a constructor with {@link int} as parameter and the source parameter is of + * type is used and the target type has a constructor with {@code int} as parameter and the source parameter is of * {@link java.util.Collection}, {@link java.util.Map} or {@code Array} type then MapStruct will use that constructor * with the {@code size} / {@code length} from the source parameter. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java index 8ddb2356b..15fb300b9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java @@ -68,7 +68,7 @@ public class ImplementationType { } /** - * @return {@code true} if the underlying type has a constructor for {@link int} {@code initialCapacity}, {@code + * @return {@code true} if the underlying type has a constructor for {@code int} {@code initialCapacity}, {@code * false} otherwise */ public boolean hasInitialCapacityConstructor() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index cb089e6e7..a0dad2c0e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -838,10 +838,10 @@ public class Type extends ModelElement implements Comparable { /** * Establishes the type bound: *

    - *
  1. {@code}, returns Number
  2. - *
  3. {@code}, returns Number
  4. - *
  5. {@code}, returns Object
  6. - *
  7. {@code, returns Number}
  8. + *
  9. {@code }, returns Number
  10. + *
  11. {@code }, returns Number
  12. + *
  13. {@code }, returns Object
  14. + *
  15. {@code , returns Number}
  16. *
* @return the bound for this parameter */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index b8a40333d..a2dc7709f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -521,10 +521,10 @@ public class TypeFactory { /** * Establishes the type bound: *
    - *
  1. {@code}, returns Number
  2. - *
  3. {@code}, returns Number
  4. - *
  5. {@code}, returns Object
  6. - *
  7. {@code, returns Number}
  8. + *
  9. {@code }, returns Number
  10. + *
  11. {@code }, returns Number
  12. + *
  13. {@code }, returns Object
  14. + *
  15. {@code , returns Number}
  16. *
* * @param typeMirror the type to return the bound for diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 582e0fed7..c8374db8a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -20,6 +20,7 @@ package org.mapstruct.ap.internal.model.source; import static org.mapstruct.ap.internal.model.source.PropertyEntry.forSourceReference; import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.last; import java.util.ArrayList; import java.util.Arrays; @@ -165,28 +166,23 @@ public class SourceReference { ); } else { - int notFoundPropertyIndex; - Type sourceType; - if ( entries.isEmpty() ) { - notFoundPropertyIndex = 0; - sourceType = method.getParameters().get( 0 ).getType(); - } - else { - int lastFoundEntryIndex = entries.size() - 1; - notFoundPropertyIndex = lastFoundEntryIndex + 1; - sourceType = entries.get( lastFoundEntryIndex ).getType(); + int notFoundPropertyIndex = 0; + Type sourceType = method.getParameters().get( 0 ).getType(); + if ( !entries.isEmpty() ) { + notFoundPropertyIndex = entries.size(); + sourceType = last( entries ).getType(); } String mostSimilarWord = Strings.getMostSimilarWord( sourcePropertyNames[notFoundPropertyIndex], sourceType.getPropertyReadAccessors().keySet() ); - String prefix = ""; - for ( int i = 0; i < notFoundPropertyIndex; i++ ) { - prefix += sourcePropertyNames[i] + "."; - } + List elements = new ArrayList( + Arrays.asList( sourcePropertyNames ).subList( 0, notFoundPropertyIndex ) + ); + elements.add( mostSimilarWord ); reportMappingError( Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(), - prefix + mostSimilarWord + Strings.join( elements, "." ) ); } isValid = false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index e04bae36c..5e17c7cd1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -411,12 +411,10 @@ public class TargetReference { readAccessors ); - String prefix = ""; - for ( int i = 0; i < index; i++ ) { - prefix += entryNames[i] + "."; - } + List elements = new ArrayList( Arrays.asList( entryNames ).subList( 0, index ) ); + elements.add( mostSimilarProperty ); - printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, prefix + mostSimilarProperty ); + printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, Strings.join( elements, "." ) ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java index 1f94bab64..d759020eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java @@ -42,7 +42,7 @@ public abstract class BeanMapper { } JAXBElement map(BigDecimal value) { - return new JAXBElement( new QName( "test" ), BigDecimal.class, value ); + return new JAXBElement( new QName( "test" ), BigDecimal.class, value ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index e35bcc668..cf6758ece 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -153,7 +153,7 @@ public class WildCardTest { public void shouldMapBean() { GoodIdea aGoodIdea = new GoodIdea(); - aGoodIdea.setContent( new JAXBElement( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) ); + aGoodIdea.setContent( new JAXBElement( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) ); aGoodIdea.setDescription( BigDecimal.ZERO ); CunningPlan aCunningPlan = BeanMapper.STM.transformA( aGoodIdea );