Simplify conditions in org.mapstruct.ap.internal.model.source

This commit is contained in:
Andrei Arlou 2019-08-11 19:14:58 +03:00 committed by Filip Hrisafov
parent f02b3d1a42
commit 716b85aa2c
7 changed files with 22 additions and 35 deletions

View File

@ -29,7 +29,7 @@ public class MappingOptions {
null,
null,
null,
Collections.<ValueMapping>emptyList(),
Collections.emptyList(),
false
);
private Set<Mapping> mappings;
@ -182,22 +182,16 @@ public class MappingOptions {
public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse, SourceMethod method ) {
MappingOptions inherited = templateMethod.getMappingOptions();
if ( null != inherited ) {
if ( getIterableMapping() == null ) {
if ( inherited.getIterableMapping() != null ) {
setIterableMapping( inherited.getIterableMapping() );
}
if ( getIterableMapping() == null && inherited.getIterableMapping() != null) {
setIterableMapping( inherited.getIterableMapping() );
}
if ( getMapMapping() == null ) {
if ( inherited.getMapMapping() != null ) {
setMapMapping( inherited.getMapMapping() );
}
if ( getMapMapping() == null && inherited.getMapMapping() != null) {
setMapMapping( inherited.getMapMapping() );
}
if ( getBeanMapping() == null ) {
if ( inherited.getBeanMapping() != null ) {
setBeanMapping( BeanMapping.forInheritance( inherited.getBeanMapping() ) );
}
if ( getBeanMapping() == null && inherited.getBeanMapping() != null ) {
setBeanMapping( BeanMapping.forInheritance( inherited.getBeanMapping() ) );
}
if ( getValueMappings() == null ) {
@ -206,7 +200,7 @@ public class MappingOptions {
setValueMappings( inherited.getValueMappings() );
}
else {
setValueMappings( Collections.<ValueMapping>emptyList() );
setValueMappings( Collections.emptyList() );
}
}
else {

View File

@ -193,6 +193,6 @@ public interface Method {
* to be an update method in order for this to be true.
*/
default boolean isMappingTargetAssignableToReturnType() {
return isUpdateMethod() ? getResultType().isAssignableTo( getReturnType() ) : false;
return isUpdateMethod() && getResultType().isAssignableTo( getReturnType() );
}
}

View File

@ -129,10 +129,7 @@ public class PropertyEntry {
return false;
}
final PropertyEntry other = (PropertyEntry) obj;
if ( !Arrays.deepEquals( this.fullName, other.fullName ) ) {
return false;
}
return true;
return Arrays.deepEquals( this.fullName, other.fullName );
}
@Override

View File

@ -94,7 +94,7 @@ public class TargetReference {
public TargetReference build() {
boolean isInverse = mapping.getInheritContext() != null ? mapping.getInheritContext().isReversed() : false;
boolean isInverse = mapping.getInheritContext() != null && mapping.getInheritContext().isReversed();
String targetName = mapping.getTargetName();
if ( targetName == null ) {

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.internal.model.source;
import java.util.List;
import java.util.Objects;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
@ -142,9 +143,6 @@ public class ValueMapping {
return false;
}
final ValueMapping other = (ValueMapping) obj;
if ( (this.source == null) ? (other.source != null) : !this.source.equals( other.source ) ) {
return false;
}
return true;
return Objects.equals( this.source, other.source );
}
}

View File

@ -49,10 +49,8 @@ public class CreateOrUpdateSelector implements MethodSelector {
updateCandidates.add( method );
}
}
if ( criteria.isPreferUpdateMapping() ) {
if ( !updateCandidates.isEmpty() ) {
return updateCandidates;
}
if ( criteria.isPreferUpdateMapping() && !updateCandidates.isEmpty() ) {
return updateCandidates;
}
return createCandidates;
}

View File

@ -62,14 +62,14 @@ public class XmlElementDeclSelector implements MethodSelector {
}
SourceMethod candidateMethod = (SourceMethod) candidate.getMethod();
XmlElementDeclPrism xmlElememtDecl = XmlElementDeclPrism.getInstanceOn( candidateMethod.getExecutable() );
XmlElementDeclPrism xmlElementDecl = XmlElementDeclPrism.getInstanceOn( candidateMethod.getExecutable() );
if ( xmlElememtDecl == null ) {
if ( xmlElementDecl == null ) {
continue;
}
String name = xmlElememtDecl.name();
TypeMirror scope = xmlElememtDecl.scope();
String name = xmlElementDecl.name();
TypeMirror scope = xmlElementDecl.scope();
boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() );
boolean scopeIsSetAndMatches =
@ -88,13 +88,13 @@ public class XmlElementDeclSelector implements MethodSelector {
}
}
if ( nameAndScopeMatches.size() > 0 ) {
if ( !nameAndScopeMatches.isEmpty() ) {
return nameAndScopeMatches;
}
else if ( scopeMatches.size() > 0 ) {
else if ( !scopeMatches.isEmpty() ) {
return scopeMatches;
}
else if ( nameMatches.size() > 0 ) {
else if ( !nameMatches.isEmpty() ) {
return nameMatches;
}
else {