#1946 Simplify conditions in classes: Parameter, SelectionParameters, MethodReference, PropertyMapping

This commit is contained in:
Andrei Arlou 2019-10-19 01:35:59 +03:00 committed by Filip Hrisafov
parent e8a7832d5b
commit 74a2e358e8
4 changed files with 16 additions and 31 deletions

View File

@ -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.<Type>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() : "";

View File

@ -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<Type> 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;
}

View File

@ -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 );
}

View File

@ -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<TypeMirror> mirrors1, List<TypeMirror> mirrors2) {
if ( mirrors1 == null ) {
return (mirrors2 == null);