From 74a2e358e8f8ef04061e9ea290a07352c3e7d28e Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 19 Oct 2019 01:35:59 +0300 Subject: [PATCH] #1946 Simplify conditions in classes: Parameter, SelectionParameters, MethodReference, PropertyMapping --- .../ap/internal/model/MethodReference.java | 20 ++++++------------- .../ap/internal/model/PropertyMapping.java | 8 ++++---- .../ap/internal/model/common/Parameter.java | 5 +++-- .../model/source/SelectionParameters.java | 14 +++---------- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 69b9b81dc..dc2bf5218 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -84,7 +85,7 @@ public class MethodReference extends ModelElement implements Assignment { imported.addAll( binding.getImportTypes() ); } - this.importTypes = Collections.unmodifiableSet( imported ); + this.importTypes = Collections.unmodifiableSet( imported ); this.thrownTypes = method.getThrownTypes(); this.isUpdateMethod = method.getMappingTargetParameter() != null; this.definingType = method.getDefiningType(); @@ -304,22 +305,13 @@ public class MethodReference extends ModelElement implements Assignment { return false; } MethodReference other = (MethodReference) obj; - if ( declaringMapper == null ) { - if ( other.declaringMapper != null ) { - return false; - } - } - else if ( !declaringMapper.equals( other.declaringMapper ) ) { + if ( !Objects.equals( declaringMapper, other.declaringMapper ) ) { return false; } - if ( providingParameter == null ) { - if ( other.providingParameter != null ) { - return false; - } - } - else if ( !providingParameter.equals( other.providingParameter ) ) { + if ( !Objects.equals( providingParameter, other.providingParameter ) ) { return false; } + return true; } @@ -351,7 +343,7 @@ public class MethodReference extends ModelElement implements Assignment { @Override public String toString() { - String mapper = declaringMapper != null ? declaringMapper.getType().getName().toString() : ""; + String mapper = declaringMapper != null ? declaringMapper.getType().getName() : ""; String argument = getAssignment() != null ? getAssignment().toString() : ( getSourceReference() != null ? getSourceReference() : "" ); String returnTypeAsString = returnType != null ? returnType.toString() : ""; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 7fc619bac..3bec3eb46 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; import javax.lang.model.element.AnnotationMirror; @@ -1026,7 +1027,6 @@ public class PropertyMapping extends ModelElement { } @Override - @SuppressWarnings("unchecked") public Set getImportTypes() { if ( defaultValueAssignment == null ) { return assignment.getImportTypes(); @@ -1062,13 +1062,13 @@ public class PropertyMapping extends ModelElement { return false; } final PropertyMapping other = (PropertyMapping) obj; - if ( (this.name == null) ? (other.name != null) : !this.name.equals( other.name ) ) { + if ( !Objects.equals( name, other.name ) ) { return false; } - if ( this.targetType != other.targetType && (this.targetType == null || - !this.targetType.equals( other.targetType )) ) { + if ( !Objects.equals( targetType, other.targetType ) ) { return false; } + return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index f93ae8095..0f3000913 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model.common; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import javax.lang.model.element.VariableElement; @@ -105,10 +106,10 @@ public class Parameter extends ModelElement { Parameter parameter = (Parameter) o; - if ( name != null ? !name.equals( parameter.name ) : parameter.name != null ) { + if ( !Objects.equals( name, parameter.name ) ) { return false; } - return type != null ? type.equals( parameter.type ) : parameter.type == null; + return Objects.equals( type, parameter.type ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index 34eb0a7d8..ed6851d9a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -7,6 +7,7 @@ package org.mapstruct.ap.internal.model.source; import java.util.Collections; import java.util.List; +import java.util.Objects; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; @@ -114,26 +115,17 @@ public class SelectionParameters { return false; } - if ( !equals( this.qualifyingNames, other.qualifyingNames ) ) { + if ( !Objects.equals( this.qualifyingNames, other.qualifyingNames ) ) { return false; } - if ( !equals( this.sourceRHS, other.sourceRHS ) ) { + if ( !Objects.equals( this.sourceRHS, other.sourceRHS ) ) { return false; } return equals( this.resultType, other.resultType ); } - private boolean equals(Object object1, Object object2) { - if ( object1 == null ) { - return (object2 == null); - } - else { - return object1.equals( object2 ); - } - } - private boolean equals(List mirrors1, List mirrors2) { if ( mirrors1 == null ) { return (mirrors2 == null);