#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
This commit is contained in:
Filip Hrisafov 2017-05-24 14:15:46 +02:00 committed by GitHub
parent f2ad90042c
commit 2e09944b19
12 changed files with 34 additions and 36 deletions

View File

@ -30,12 +30,13 @@ public enum NullValueCheckStrategy {
/** /**
* This option includes a null check. When: * This option includes a null check. When:
* <p> * <br>
* <br>
* <ol> * <ol>
* <li>a source value is directly assigned to a target</li> * <li>a source value is directly assigned to a target</li>
* <li>a source value assigned to a target by calling a type conversion on the target first</li> * <li>a source value assigned to a target by calling a type conversion on the target first</li>
* </ol> * </ol>
* <p> * <br>
* <b>NOTE:</b> mapping methods (generated or hand written) are excluded from this null check. They are intended to * <b>NOTE:</b> mapping methods (generated or hand written) are excluded from this null check. They are intended to
* handle a null source value as 'valid' input. * handle a null source value as 'valid' input.
* *

View File

@ -534,6 +534,9 @@
<exclude>.gitignore</exclude> <exclude>.gitignore</exclude>
<exclude>.factorypath</exclude> <exclude>.factorypath</exclude>
<exclude>.checkstyle</exclude> <exclude>.checkstyle</exclude>
<exclude>*.yml</exclude>
<exclude>**/*.asciidoc</exclude>
<exclude>**/binding.xjb</exclude>
</excludes> </excludes>
</configuration> </configuration>
<executions> <executions>

View File

@ -74,7 +74,7 @@ public class BigDecimalToStringConversion extends AbstractNumberToStringConversi
@Override @Override
public List<HelperMethod> getRequiredHelperMethods(ConversionContext conversionContext) { public List<HelperMethod> getRequiredHelperMethods(ConversionContext conversionContext) {
List<HelperMethod> helpers = new ArrayList(); List<HelperMethod> helpers = new ArrayList<HelperMethod>();
if ( conversionContext.getNumberFormat() != null ) { if ( conversionContext.getNumberFormat() != null ) {
helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) );
} }

View File

@ -81,7 +81,7 @@ public class BigIntegerToStringConversion extends AbstractNumberToStringConversi
@Override @Override
public List<HelperMethod> getRequiredHelperMethods(ConversionContext conversionContext) { public List<HelperMethod> getRequiredHelperMethods(ConversionContext conversionContext) {
List<HelperMethod> helpers = new ArrayList(); List<HelperMethod> helpers = new ArrayList<HelperMethod>();
if ( conversionContext.getNumberFormat() != null ) { if ( conversionContext.getNumberFormat() != null ) {
helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) );
} }

View File

@ -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 * 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 * {@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. * with the {@code size} / {@code length} from the source parameter.
* *

View File

@ -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 * false} otherwise
*/ */
public boolean hasInitialCapacityConstructor() { public boolean hasInitialCapacityConstructor() {

View File

@ -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.model.source.PropertyEntry.forSourceReference;
import static org.mapstruct.ap.internal.util.Collections.first; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -165,28 +166,23 @@ public class SourceReference {
); );
} }
else { else {
int notFoundPropertyIndex; int notFoundPropertyIndex = 0;
Type sourceType; Type sourceType = method.getParameters().get( 0 ).getType();
if ( entries.isEmpty() ) { if ( !entries.isEmpty() ) {
notFoundPropertyIndex = 0; notFoundPropertyIndex = entries.size();
sourceType = method.getParameters().get( 0 ).getType(); sourceType = last( entries ).getType();
}
else {
int lastFoundEntryIndex = entries.size() - 1;
notFoundPropertyIndex = lastFoundEntryIndex + 1;
sourceType = entries.get( lastFoundEntryIndex ).getType();
} }
String mostSimilarWord = Strings.getMostSimilarWord( String mostSimilarWord = Strings.getMostSimilarWord(
sourcePropertyNames[notFoundPropertyIndex], sourcePropertyNames[notFoundPropertyIndex],
sourceType.getPropertyReadAccessors().keySet() sourceType.getPropertyReadAccessors().keySet()
); );
String prefix = ""; List<String> elements = new ArrayList<String>(
for ( int i = 0; i < notFoundPropertyIndex; i++ ) { Arrays.asList( sourcePropertyNames ).subList( 0, notFoundPropertyIndex )
prefix += sourcePropertyNames[i] + "."; );
} elements.add( mostSimilarWord );
reportMappingError( reportMappingError(
Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(), Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(),
prefix + mostSimilarWord Strings.join( elements, "." )
); );
} }
isValid = false; isValid = false;

View File

@ -411,12 +411,10 @@ public class TargetReference {
readAccessors readAccessors
); );
String prefix = ""; List<String> elements = new ArrayList<String>( Arrays.asList( entryNames ).subList( 0, index ) );
for ( int i = 0; i < index; i++ ) { elements.add( mostSimilarProperty );
prefix += entryNames[i] + ".";
}
printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, prefix + mostSimilarProperty ); printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, Strings.join( elements, "." ) );
} }
} }

View File

@ -42,7 +42,7 @@ public abstract class BeanMapper {
} }
JAXBElement<? super BigDecimal> map(BigDecimal value) { JAXBElement<? super BigDecimal> map(BigDecimal value) {
return new JAXBElement( new QName( "test" ), BigDecimal.class, value ); return new JAXBElement<BigDecimal>( new QName( "test" ), BigDecimal.class, value );
} }
} }

View File

@ -153,7 +153,7 @@ public class WildCardTest {
public void shouldMapBean() { public void shouldMapBean() {
GoodIdea aGoodIdea = new GoodIdea(); GoodIdea aGoodIdea = new GoodIdea();
aGoodIdea.setContent( new JAXBElement( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) ); aGoodIdea.setContent( new JAXBElement<BigDecimal>( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) );
aGoodIdea.setDescription( BigDecimal.ZERO ); aGoodIdea.setDescription( BigDecimal.ZERO );
CunningPlan aCunningPlan = BeanMapper.STM.transformA( aGoodIdea ); CunningPlan aCunningPlan = BeanMapper.STM.transformA( aGoodIdea );