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

View File

@ -193,6 +193,6 @@ public interface Method {
* to be an update method in order for this to be true. * to be an update method in order for this to be true.
*/ */
default boolean isMappingTargetAssignableToReturnType() { 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; return false;
} }
final PropertyEntry other = (PropertyEntry) obj; final PropertyEntry other = (PropertyEntry) obj;
if ( !Arrays.deepEquals( this.fullName, other.fullName ) ) { return Arrays.deepEquals( this.fullName, other.fullName );
return false;
}
return true;
} }
@Override @Override

View File

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

View File

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

View File

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

View File

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