#3292 Simplify expressions, remove redundant expressions

This commit is contained in:
Anton Erofeev 2023-08-01 14:17:50 +02:00 committed by GitHub
parent 279ab22482
commit b2dc64136d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 40 additions and 53 deletions

View File

@ -44,7 +44,7 @@ public final class FullFeatureCompilationExclusionCliEnhancer implements Process
default: default:
} }
Collection<String> result = new ArrayList<String>( additionalExcludes.size() ); Collection<String> result = new ArrayList<>(additionalExcludes.size());
for ( int i = 0; i < additionalExcludes.size(); i++ ) { for ( int i = 0; i < additionalExcludes.size(); i++ ) {
result.add( "-DadditionalExclude" + i + "=" + additionalExcludes.get( i ) ); result.add( "-DadditionalExclude" + i + "=" + additionalExcludes.get( i ) );
} }

View File

@ -62,7 +62,7 @@ public class GradleIncrementalCompilationTest {
} }
private GradleRunner getRunner(String... additionalArguments) { private GradleRunner getRunner(String... additionalArguments) {
List<String> fullArguments = new ArrayList<String>( compileArgs ); List<String> fullArguments = new ArrayList<>(compileArgs);
fullArguments.addAll( Arrays.asList( additionalArguments ) ); fullArguments.addAll( Arrays.asList( additionalArguments ) );
return runner.withArguments( fullArguments ); return runner.withArguments( fullArguments );
} }

View File

@ -45,7 +45,7 @@ public class BigDecimalToStringConversion extends AbstractNumberToStringConversi
public String getFromExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) {
if ( requiresDecimalFormat( conversionContext ) ) { if ( requiresDecimalFormat( conversionContext ) ) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append( "(" + bigDecimal( conversionContext ) + ") " ); sb.append( "(" ).append( bigDecimal( conversionContext ) ).append( ") " );
appendDecimalFormatter( sb, conversionContext ); appendDecimalFormatter( sb, conversionContext );
sb.append( ".parse( <SOURCE> )" ); sb.append( ".parse( <SOURCE> )" );
return sb.toString(); return sb.toString();

View File

@ -47,7 +47,7 @@ public class BigIntegerToStringConversion extends AbstractNumberToStringConversi
public String getFromExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) {
if ( requiresDecimalFormat( conversionContext ) ) { if ( requiresDecimalFormat( conversionContext ) ) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append( "( (" + bigDecimal( conversionContext ) + ") " ); sb.append( "( (" ).append( bigDecimal( conversionContext ) ).append( ") " );
appendDecimalFormatter( sb, conversionContext ); appendDecimalFormatter( sb, conversionContext );
sb.append( ".parse( <SOURCE> )" ); sb.append( ".parse( <SOURCE> )" );
sb.append( " ).toBigInteger()" ); sb.append( " ).toBigInteger()" );

View File

@ -130,9 +130,7 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
ctx.getElementUtils(), ctx.getElementUtils(),
ctx.getTypeFactory(), ctx.getTypeFactory(),
ctx.getMessager() ); ctx.getMessager() );
List<Annotation> annotations = new ArrayList<>(); return new ArrayList<>( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) );
annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) );
return annotations;
} }
} }

View File

@ -266,9 +266,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
Map<String, ReadAccessor> readAccessors = sourceParameter.getType().getPropertyReadAccessors(); Map<String, ReadAccessor> readAccessors = sourceParameter.getType().getPropertyReadAccessors();
for ( Entry<String, ReadAccessor> entry : readAccessors.entrySet() ) { unprocessedSourceProperties.putAll( readAccessors );
unprocessedSourceProperties.put( entry.getKey(), entry.getValue() );
}
} }
// get bean mapping (when specified as annotation ) // get bean mapping (when specified as annotation )
@ -499,7 +497,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
new ArrayList<>( mappingSourceType.getPermittedSubclasses() ); new ArrayList<>( mappingSourceType.getPermittedSubclasses() );
method.getOptions().getSubclassMappings().forEach( subClassOption -> { method.getOptions().getSubclassMappings().forEach( subClassOption -> {
for (Iterator<? extends TypeMirror> iterator = unusedPermittedSubclasses.iterator(); for (Iterator<? extends TypeMirror> iterator = unusedPermittedSubclasses.iterator();
iterator.hasNext(); ) { iterator.hasNext(); ) {
if ( ctx.getTypeUtils().isSameType( iterator.next(), subClassOption.getSource() ) ) { if ( ctx.getTypeUtils().isSameType( iterator.next(), subClassOption.getSource() ) ) {
iterator.remove(); iterator.remove();
} }

View File

@ -607,7 +607,7 @@ public class NestedTargetPropertyMappingHolder {
* @param hasNoMappings parameter indicating whether there were any extracted mappings for this target property * @param hasNoMappings parameter indicating whether there were any extracted mappings for this target property
* @param sourceParameter the source parameter for which the grouping is being done * @param sourceParameter the source parameter for which the grouping is being done
* *
* @return a list with valid single target references * @return a set with valid single target references
*/ */
private Set<MappingReference> extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( private Set<MappingReference> extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings(
Set<MappingReference> singleTargetReferences, Set<MappingReference> sourceParameterMappings, Set<MappingReference> singleTargetReferences, Set<MappingReference> sourceParameterMappings,

View File

@ -1115,7 +1115,7 @@ public class PropertyMapping extends ModelElement {
this.targetType = targetType; this.targetType = targetType;
this.assignment = assignment; this.assignment = assignment;
this.dependsOn = dependsOn != null ? dependsOn : Collections.<String>emptySet(); this.dependsOn = dependsOn != null ? dependsOn : Collections.emptySet();
this.defaultValueAssignment = defaultValueAssignment; this.defaultValueAssignment = defaultValueAssignment;
this.constructorMapping = constructorMapping; this.constructorMapping = constructorMapping;
} }

View File

@ -61,13 +61,8 @@ final class DateFormatValidatorFactory {
dateFormatValidator = new JodaTimeDateFormatValidator(); dateFormatValidator = new JodaTimeDateFormatValidator();
} }
else { else {
dateFormatValidator = new DateFormatValidator() { dateFormatValidator = dateFormat -> new DateFormatValidationResult(
@Override true, Message.GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK, sourceType, targetType );
public DateFormatValidationResult validate(String dateFormat) {
return new DateFormatValidationResult( true, Message.GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK,
sourceType, targetType );
}
};
} }
return dateFormatValidator; return dateFormatValidator;

View File

@ -684,10 +684,9 @@ public class Type extends ModelElement implements Comparable<Type> {
*/ */
public Map<String, ReadAccessor> getPropertyReadAccessors() { public Map<String, ReadAccessor> getPropertyReadAccessors() {
if ( readAccessors == null ) { if ( readAccessors == null ) {
Map<String, ReadAccessor> modifiableGetters = new LinkedHashMap<>();
Map<String, ReadAccessor> recordAccessors = filters.recordAccessorsIn( getRecordComponents() ); Map<String, ReadAccessor> recordAccessors = filters.recordAccessorsIn( getRecordComponents() );
modifiableGetters.putAll( recordAccessors ); Map<String, ReadAccessor> modifiableGetters = new LinkedHashMap<>(recordAccessors);
List<ReadAccessor> getterList = filters.getterMethodsIn( getAllMethods() ); List<ReadAccessor> getterList = filters.getterMethodsIn( getAllMethods() );
for ( ReadAccessor getter : getterList ) { for ( ReadAccessor getter : getterList ) {

View File

@ -18,7 +18,7 @@ import org.mapstruct.TargetType;
*/ */
public class MappingContext { public class MappingContext {
private final List<String> invokedMethods = new ArrayList<String>(); private final List<String> invokedMethods = new ArrayList<>();
@BeforeMapping @BeforeMapping
public void beforeWithoutParameters() { public void beforeWithoutParameters() {

View File

@ -26,7 +26,7 @@ public class ParentChildBuilderTest {
public void testParentChildBuilderMapper() { public void testParentChildBuilderMapper() {
final MutableParent parent = new MutableParent(); final MutableParent parent = new MutableParent();
parent.setCount( 4 ); parent.setCount( 4 );
parent.setChildren( new ArrayList<MutableChild>() ); parent.setChildren( new ArrayList<>() );
parent.getChildren().add( new MutableChild( "Phineas" ) ); parent.getChildren().add( new MutableChild( "Phineas" ) );
parent.getChildren().add( new MutableChild( "Ferb" ) ); parent.getChildren().add( new MutableChild( "Ferb" ) );

View File

@ -22,7 +22,7 @@ public class SimpleImmutablePerson {
this.job = builder.job; this.job = builder.job;
this.city = builder.city; this.city = builder.city;
this.address = builder.address; this.address = builder.address;
this.children = new ArrayList<String>( builder.children ); this.children = new ArrayList<>(builder.children);
} }
public static Builder builder() { public static Builder builder() {
@ -59,7 +59,7 @@ public class SimpleImmutablePerson {
private String job; private String job;
private String city; private String city;
private String address; private String address;
private List<String> children = new ArrayList<String>(); private List<String> children = new ArrayList<>();
public Builder age(int age) { public Builder age(int age) {
this.age = age; this.age = age;

View File

@ -24,7 +24,7 @@ public abstract class BaseMapper {
@Qualified @Qualified
public abstract Target sourceToTargetQualified(Source source); public abstract Target sourceToTargetQualified(Source source);
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>(); private static final List<Invocation> INVOCATIONS = new ArrayList<>();
@BeforeMapping @BeforeMapping
public void noArgsBeforeMapping() { public void noArgsBeforeMapping() {

View File

@ -111,7 +111,7 @@ public class CallbackMethodTest {
SourceEnum source = SourceEnum.B; SourceEnum source = SourceEnum.B;
TargetEnum target = SourceTargetMapper.INSTANCE.toTargetEnum( source ); TargetEnum target = SourceTargetMapper.INSTANCE.toTargetEnum( source );
List<Invocation> invocations = new ArrayList<Invocation>(); List<Invocation> invocations = new ArrayList<>();
invocations.addAll( allBeforeMappingMethods( source, target, TargetEnum.class ) ); invocations.addAll( allBeforeMappingMethods( source, target, TargetEnum.class ) );
invocations.addAll( allAfterMappingMethods( source, target, TargetEnum.class ) ); invocations.addAll( allAfterMappingMethods( source, target, TargetEnum.class ) );

View File

@ -18,7 +18,7 @@ import org.mapstruct.TargetType;
* @author Andreas Gudian * @author Andreas Gudian
*/ */
public class ClassContainingCallbacks { public class ClassContainingCallbacks {
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>(); private static final List<Invocation> INVOCATIONS = new ArrayList<>();
@BeforeMapping @BeforeMapping
public void noArgsBeforeMapping() { public void noArgsBeforeMapping() {

View File

@ -50,12 +50,7 @@ class CallbacksWithReturnValuesTest {
@ProcessorTest @ProcessorTest
void mappingWithContextCorrectlyResolvesCycles() { void mappingWithContextCorrectlyResolvesCycles() {
final AtomicReference<Integer> contextLevel = new AtomicReference<>( null ); final AtomicReference<Integer> contextLevel = new AtomicReference<>( null );
ContextListener contextListener = new ContextListener() { ContextListener contextListener = (level, method, source, target) -> contextLevel.set( level );
@Override
public void methodCalled(Integer level, String method, Object source, Object target) {
contextLevel.set( level );
}
};
NodeMapperContext.addContextListener( contextListener ); NodeMapperContext.addContextListener( contextListener );
try { try {

View File

@ -19,11 +19,11 @@ import org.mapstruct.TargetType;
* @author Pascal Grün * @author Pascal Grün
*/ */
public class NodeMapperContext { public class NodeMapperContext {
private static final ThreadLocal<Integer> LEVEL = new ThreadLocal<Integer>(); private static final ThreadLocal<Integer> LEVEL = new ThreadLocal<>();
private static final ThreadLocal<Map<Object, Object>> MAPPING = new ThreadLocal<Map<Object, Object>>(); private static final ThreadLocal<Map<Object, Object>> MAPPING = new ThreadLocal<>();
/** Only for test-inspection */ /** Only for test-inspection */
private static final List<ContextListener> LISTENERS = new CopyOnWriteArrayList<ContextListener>(); private static final List<ContextListener> LISTENERS = new CopyOnWriteArrayList<>();
private NodeMapperContext() { private NodeMapperContext() {
// Only allow static access // Only allow static access

View File

@ -16,7 +16,7 @@ import org.mapstruct.ap.test.collection.adder.source.Foo;
*/ */
public class Target2 { public class Target2 {
private List<Foo> attributes = new ArrayList<Foo>(); private List<Foo> attributes = new ArrayList<>();
public Foo addAttribute( Foo foo ) { public Foo addAttribute( Foo foo ) {
attributes.add( foo ); attributes.add( foo );

View File

@ -15,8 +15,8 @@ import java.util.Map;
* *
*/ */
public class NoSetterTarget { public class NoSetterTarget {
private List<String> listValues = new ArrayList<String>(); private List<String> listValues = new ArrayList<>();
private Map<String, String> mapValues = new HashMap<String, String>(); private Map<String, String> mapValues = new HashMap<>();
public List<String> getListValues() { public List<String> getListValues() {
return listValues; return listValues;

View File

@ -77,7 +77,7 @@ public class Target {
public List<String> getStringListNoSetter() { public List<String> getStringListNoSetter() {
if ( stringListNoSetter == null ) { if ( stringListNoSetter == null ) {
stringListNoSetter = new ArrayList<String>(); stringListNoSetter = new ArrayList<>();
} }
return stringListNoSetter; return stringListNoSetter;
} }

View File

@ -5,6 +5,8 @@
*/ */
package org.mapstruct.ap.test.nestedbeans; package org.mapstruct.ap.test.nestedbeans;
import java.util.Objects;
public class HouseDto { public class HouseDto {
private String name; private String name;
@ -58,10 +60,10 @@ public class HouseDto {
if ( year != houseDto.year ) { if ( year != houseDto.year ) {
return false; return false;
} }
if ( name != null ? !name.equals( houseDto.name ) : houseDto.name != null ) { if ( !Objects.equals( name, houseDto.name ) ) {
return false; return false;
} }
return roof != null ? roof.equals( houseDto.roof ) : houseDto.roof == null; return Objects.equals( roof, houseDto.roof );
} }

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.test.nestedbeans.maps; package org.mapstruct.ap.test.nestedbeans.maps;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class AntonymsDictionaryDto { public class AntonymsDictionaryDto {
private Map<WordDto, WordDto> antonyms; private Map<WordDto, WordDto> antonyms;
@ -36,8 +37,7 @@ public class AntonymsDictionaryDto {
AntonymsDictionaryDto antonymsDictionaryDto = (AntonymsDictionaryDto) o; AntonymsDictionaryDto antonymsDictionaryDto = (AntonymsDictionaryDto) o;
return antonyms != null ? antonyms.equals( antonymsDictionaryDto.antonyms ) : return Objects.equals( antonyms, antonymsDictionaryDto.antonyms );
antonymsDictionaryDto.antonyms == null;
} }

View File

@ -192,7 +192,7 @@ public class InheritanceSelectionTest {
}) })
public void testShouldSelectResultTypeInCaseOfAmbiguityForMap() { public void testShouldSelectResultTypeInCaseOfAmbiguityForMap() {
Map<AppleDto, AppleDto> source = new HashMap<AppleDto, AppleDto>(); Map<AppleDto, AppleDto> source = new HashMap<>();
source.put( new AppleDto( "GoldenDelicious" ), new AppleDto( "AppleDto" ) ); source.put( new AppleDto( "GoldenDelicious" ), new AppleDto( "AppleDto" ) );
Map<Apple, Apple> result = FruitFamilyMapper.INSTANCE.mapToGoldenDeliciousMap( source ); Map<Apple, Apple> result = FruitFamilyMapper.INSTANCE.mapToGoldenDeliciousMap( source );

View File

@ -20,7 +20,7 @@ public class Target {
private int integerConstant; private int integerConstant;
private Long longWrapperConstant; private Long longWrapperConstant;
private Date dateConstant; private Date dateConstant;
private List<String> nameConstants = new ArrayList<String>(); private List<String> nameConstants = new ArrayList<>();
private CountryEnum country; private CountryEnum country;
public String getPropertyThatShouldBeMapped() { public String getPropertyThatShouldBeMapped() {

View File

@ -59,7 +59,7 @@ public class JavaFileAssert extends FileAssert {
return Assertions.assertThat( FileUtils.readFileToString( actual, StandardCharsets.UTF_8 ) ); return Assertions.assertThat( FileUtils.readFileToString( actual, StandardCharsets.UTF_8 ) );
} }
catch ( IOException e ) { catch ( IOException e ) {
failWithMessage( "Unable to read" + actual.toString() + ". Exception: " + e.getMessage() ); failWithMessage( "Unable to read" + actual + ". Exception: " + e.getMessage() );
} }
return null; return null;
} }

View File

@ -131,7 +131,7 @@ public class DiagnosticDescriptor {
//Make the URI absolute in case it isn't (the case with JDK 6) //Make the URI absolute in case it isn't (the case with JDK 6)
try { try {
return new URI( "file:" + uri.toString() ); return new URI( "file:" + uri );
} }
catch ( URISyntaxException e ) { catch ( URISyntaxException e ) {
throw new RuntimeException( e ); throw new RuntimeException( e );
@ -189,7 +189,7 @@ public class DiagnosticDescriptor {
if ( kind != other.kind ) { if ( kind != other.kind ) {
return false; return false;
} }
if ( line != other.line ) { if ( !Objects.equals( line, other.line ) ) {
return false; return false;
} }
if ( !Objects.equals( message, other.message ) ) { if ( !Objects.equals( message, other.message ) ) {

View File

@ -135,7 +135,7 @@ class JdkCompilingExtension extends CompilingExtension {
// The JDK 8+ compilers report all ERROR diagnostics properly. Also when there are multiple per line. // The JDK 8+ compilers report all ERROR diagnostics properly. Also when there are multiple per line.
return expectedDiagnostics; return expectedDiagnostics;
} }
List<DiagnosticDescriptor> filtered = new ArrayList<DiagnosticDescriptor>( expectedDiagnostics.size() ); List<DiagnosticDescriptor> filtered = new ArrayList<>(expectedDiagnostics.size());
// The JDK 8 compiler only reports the first message of kind ERROR that is reported for one source file line, // The JDK 8 compiler only reports the first message of kind ERROR that is reported for one source file line,
// so we filter out the surplus diagnostics. The input list is already sorted by file name and line number, // so we filter out the surplus diagnostics. The input list is already sorted by file name and line number,

View File

@ -31,7 +31,7 @@ final class ModifiableURLClassLoader extends URLClassLoader {
tryRegisterAsParallelCapable(); tryRegisterAsParallelCapable();
} }
private final ConcurrentMap<URL, URL> addedURLs = new ConcurrentHashMap<URL, URL>(); private final ConcurrentMap<URL, URL> addedURLs = new ConcurrentHashMap<>();
ModifiableURLClassLoader(ClassLoader parent) { ModifiableURLClassLoader(ClassLoader parent) {
super( new URL[] { }, parent ); super( new URL[] { }, parent );