mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3292 Simplify expressions, remove redundant expressions
This commit is contained in:
parent
279ab22482
commit
b2dc64136d
@ -44,7 +44,7 @@ public final class FullFeatureCompilationExclusionCliEnhancer implements Process
|
||||
default:
|
||||
}
|
||||
|
||||
Collection<String> result = new ArrayList<String>( additionalExcludes.size() );
|
||||
Collection<String> result = new ArrayList<>(additionalExcludes.size());
|
||||
for ( int i = 0; i < additionalExcludes.size(); i++ ) {
|
||||
result.add( "-DadditionalExclude" + i + "=" + additionalExcludes.get( i ) );
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class GradleIncrementalCompilationTest {
|
||||
}
|
||||
|
||||
private GradleRunner getRunner(String... additionalArguments) {
|
||||
List<String> fullArguments = new ArrayList<String>( compileArgs );
|
||||
List<String> fullArguments = new ArrayList<>(compileArgs);
|
||||
fullArguments.addAll( Arrays.asList( additionalArguments ) );
|
||||
return runner.withArguments( fullArguments );
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class BigDecimalToStringConversion extends AbstractNumberToStringConversi
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
if ( requiresDecimalFormat( conversionContext ) ) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append( "(" + bigDecimal( conversionContext ) + ") " );
|
||||
sb.append( "(" ).append( bigDecimal( conversionContext ) ).append( ") " );
|
||||
appendDecimalFormatter( sb, conversionContext );
|
||||
sb.append( ".parse( <SOURCE> )" );
|
||||
return sb.toString();
|
||||
|
@ -47,7 +47,7 @@ public class BigIntegerToStringConversion extends AbstractNumberToStringConversi
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
if ( requiresDecimalFormat( conversionContext ) ) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append( "( (" + bigDecimal( conversionContext ) + ") " );
|
||||
sb.append( "( (" ).append( bigDecimal( conversionContext ) ).append( ") " );
|
||||
appendDecimalFormatter( sb, conversionContext );
|
||||
sb.append( ".parse( <SOURCE> )" );
|
||||
sb.append( " ).toBigInteger()" );
|
||||
|
@ -130,9 +130,7 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
|
||||
ctx.getElementUtils(),
|
||||
ctx.getTypeFactory(),
|
||||
ctx.getMessager() );
|
||||
List<Annotation> annotations = new ArrayList<>();
|
||||
annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) );
|
||||
return annotations;
|
||||
return new ArrayList<>( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -266,9 +266,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
|
||||
Map<String, ReadAccessor> readAccessors = sourceParameter.getType().getPropertyReadAccessors();
|
||||
|
||||
for ( Entry<String, ReadAccessor> entry : readAccessors.entrySet() ) {
|
||||
unprocessedSourceProperties.put( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
unprocessedSourceProperties.putAll( readAccessors );
|
||||
}
|
||||
|
||||
// get bean mapping (when specified as annotation )
|
||||
@ -499,7 +497,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
new ArrayList<>( mappingSourceType.getPermittedSubclasses() );
|
||||
method.getOptions().getSubclassMappings().forEach( subClassOption -> {
|
||||
for (Iterator<? extends TypeMirror> iterator = unusedPermittedSubclasses.iterator();
|
||||
iterator.hasNext(); ) {
|
||||
iterator.hasNext(); ) {
|
||||
if ( ctx.getTypeUtils().isSameType( iterator.next(), subClassOption.getSource() ) ) {
|
||||
iterator.remove();
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ public class NestedTargetPropertyMappingHolder {
|
||||
* @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
|
||||
*
|
||||
* @return a list with valid single target references
|
||||
* @return a set with valid single target references
|
||||
*/
|
||||
private Set<MappingReference> extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings(
|
||||
Set<MappingReference> singleTargetReferences, Set<MappingReference> sourceParameterMappings,
|
||||
|
@ -1115,7 +1115,7 @@ public class PropertyMapping extends ModelElement {
|
||||
this.targetType = targetType;
|
||||
|
||||
this.assignment = assignment;
|
||||
this.dependsOn = dependsOn != null ? dependsOn : Collections.<String>emptySet();
|
||||
this.dependsOn = dependsOn != null ? dependsOn : Collections.emptySet();
|
||||
this.defaultValueAssignment = defaultValueAssignment;
|
||||
this.constructorMapping = constructorMapping;
|
||||
}
|
||||
|
@ -61,13 +61,8 @@ final class DateFormatValidatorFactory {
|
||||
dateFormatValidator = new JodaTimeDateFormatValidator();
|
||||
}
|
||||
else {
|
||||
dateFormatValidator = new DateFormatValidator() {
|
||||
@Override
|
||||
public DateFormatValidationResult validate(String dateFormat) {
|
||||
return new DateFormatValidationResult( true, Message.GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK,
|
||||
sourceType, targetType );
|
||||
}
|
||||
};
|
||||
dateFormatValidator = dateFormat -> new DateFormatValidationResult(
|
||||
true, Message.GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK, sourceType, targetType );
|
||||
}
|
||||
return dateFormatValidator;
|
||||
|
||||
|
@ -684,10 +684,9 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
*/
|
||||
public Map<String, ReadAccessor> getPropertyReadAccessors() {
|
||||
if ( readAccessors == null ) {
|
||||
Map<String, ReadAccessor> modifiableGetters = new LinkedHashMap<>();
|
||||
|
||||
Map<String, ReadAccessor> recordAccessors = filters.recordAccessorsIn( getRecordComponents() );
|
||||
modifiableGetters.putAll( recordAccessors );
|
||||
Map<String, ReadAccessor> modifiableGetters = new LinkedHashMap<>(recordAccessors);
|
||||
|
||||
List<ReadAccessor> getterList = filters.getterMethodsIn( getAllMethods() );
|
||||
for ( ReadAccessor getter : getterList ) {
|
||||
|
@ -18,7 +18,7 @@ import org.mapstruct.TargetType;
|
||||
*/
|
||||
public class MappingContext {
|
||||
|
||||
private final List<String> invokedMethods = new ArrayList<String>();
|
||||
private final List<String> invokedMethods = new ArrayList<>();
|
||||
|
||||
@BeforeMapping
|
||||
public void beforeWithoutParameters() {
|
||||
|
@ -26,7 +26,7 @@ public class ParentChildBuilderTest {
|
||||
public void testParentChildBuilderMapper() {
|
||||
final MutableParent parent = new MutableParent();
|
||||
parent.setCount( 4 );
|
||||
parent.setChildren( new ArrayList<MutableChild>() );
|
||||
parent.setChildren( new ArrayList<>() );
|
||||
parent.getChildren().add( new MutableChild( "Phineas" ) );
|
||||
parent.getChildren().add( new MutableChild( "Ferb" ) );
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class SimpleImmutablePerson {
|
||||
this.job = builder.job;
|
||||
this.city = builder.city;
|
||||
this.address = builder.address;
|
||||
this.children = new ArrayList<String>( builder.children );
|
||||
this.children = new ArrayList<>(builder.children);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
@ -59,7 +59,7 @@ public class SimpleImmutablePerson {
|
||||
private String job;
|
||||
private String city;
|
||||
private String address;
|
||||
private List<String> children = new ArrayList<String>();
|
||||
private List<String> children = new ArrayList<>();
|
||||
|
||||
public Builder age(int age) {
|
||||
this.age = age;
|
||||
|
@ -24,7 +24,7 @@ public abstract class BaseMapper {
|
||||
@Qualified
|
||||
public abstract Target sourceToTargetQualified(Source source);
|
||||
|
||||
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>();
|
||||
private static final List<Invocation> INVOCATIONS = new ArrayList<>();
|
||||
|
||||
@BeforeMapping
|
||||
public void noArgsBeforeMapping() {
|
||||
|
@ -111,7 +111,7 @@ public class CallbackMethodTest {
|
||||
SourceEnum source = SourceEnum.B;
|
||||
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( allAfterMappingMethods( source, target, TargetEnum.class ) );
|
||||
|
||||
|
@ -18,7 +18,7 @@ import org.mapstruct.TargetType;
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public class ClassContainingCallbacks {
|
||||
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>();
|
||||
private static final List<Invocation> INVOCATIONS = new ArrayList<>();
|
||||
|
||||
@BeforeMapping
|
||||
public void noArgsBeforeMapping() {
|
||||
|
@ -50,12 +50,7 @@ class CallbacksWithReturnValuesTest {
|
||||
@ProcessorTest
|
||||
void mappingWithContextCorrectlyResolvesCycles() {
|
||||
final AtomicReference<Integer> contextLevel = new AtomicReference<>( null );
|
||||
ContextListener contextListener = new ContextListener() {
|
||||
@Override
|
||||
public void methodCalled(Integer level, String method, Object source, Object target) {
|
||||
contextLevel.set( level );
|
||||
}
|
||||
};
|
||||
ContextListener contextListener = (level, method, source, target) -> contextLevel.set( level );
|
||||
|
||||
NodeMapperContext.addContextListener( contextListener );
|
||||
try {
|
||||
|
@ -19,11 +19,11 @@ import org.mapstruct.TargetType;
|
||||
* @author Pascal Grün
|
||||
*/
|
||||
public class NodeMapperContext {
|
||||
private static final ThreadLocal<Integer> LEVEL = new ThreadLocal<Integer>();
|
||||
private static final ThreadLocal<Map<Object, Object>> MAPPING = new ThreadLocal<Map<Object, Object>>();
|
||||
private static final ThreadLocal<Integer> LEVEL = new ThreadLocal<>();
|
||||
private static final ThreadLocal<Map<Object, Object>> MAPPING = new ThreadLocal<>();
|
||||
|
||||
/** Only for test-inspection */
|
||||
private static final List<ContextListener> LISTENERS = new CopyOnWriteArrayList<ContextListener>();
|
||||
private static final List<ContextListener> LISTENERS = new CopyOnWriteArrayList<>();
|
||||
|
||||
private NodeMapperContext() {
|
||||
// Only allow static access
|
||||
|
@ -16,7 +16,7 @@ import org.mapstruct.ap.test.collection.adder.source.Foo;
|
||||
*/
|
||||
public class Target2 {
|
||||
|
||||
private List<Foo> attributes = new ArrayList<Foo>();
|
||||
private List<Foo> attributes = new ArrayList<>();
|
||||
|
||||
public Foo addAttribute( Foo foo ) {
|
||||
attributes.add( foo );
|
||||
|
@ -15,8 +15,8 @@ import java.util.Map;
|
||||
*
|
||||
*/
|
||||
public class NoSetterTarget {
|
||||
private List<String> listValues = new ArrayList<String>();
|
||||
private Map<String, String> mapValues = new HashMap<String, String>();
|
||||
private List<String> listValues = new ArrayList<>();
|
||||
private Map<String, String> mapValues = new HashMap<>();
|
||||
|
||||
public List<String> getListValues() {
|
||||
return listValues;
|
||||
|
@ -77,7 +77,7 @@ public class Target {
|
||||
|
||||
public List<String> getStringListNoSetter() {
|
||||
if ( stringListNoSetter == null ) {
|
||||
stringListNoSetter = new ArrayList<String>();
|
||||
stringListNoSetter = new ArrayList<>();
|
||||
}
|
||||
return stringListNoSetter;
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.nestedbeans;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class HouseDto {
|
||||
|
||||
private String name;
|
||||
@ -58,10 +60,10 @@ public class HouseDto {
|
||||
if ( year != houseDto.year ) {
|
||||
return false;
|
||||
}
|
||||
if ( name != null ? !name.equals( houseDto.name ) : houseDto.name != null ) {
|
||||
if ( !Objects.equals( name, houseDto.name ) ) {
|
||||
return false;
|
||||
}
|
||||
return roof != null ? roof.equals( houseDto.roof ) : houseDto.roof == null;
|
||||
return Objects.equals( roof, houseDto.roof );
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
package org.mapstruct.ap.test.nestedbeans.maps;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AntonymsDictionaryDto {
|
||||
private Map<WordDto, WordDto> antonyms;
|
||||
@ -36,8 +37,7 @@ public class AntonymsDictionaryDto {
|
||||
|
||||
AntonymsDictionaryDto antonymsDictionaryDto = (AntonymsDictionaryDto) o;
|
||||
|
||||
return antonyms != null ? antonyms.equals( antonymsDictionaryDto.antonyms ) :
|
||||
antonymsDictionaryDto.antonyms == null;
|
||||
return Objects.equals( antonyms, antonymsDictionaryDto.antonyms );
|
||||
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ public class InheritanceSelectionTest {
|
||||
})
|
||||
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" ) );
|
||||
|
||||
Map<Apple, Apple> result = FruitFamilyMapper.INSTANCE.mapToGoldenDeliciousMap( source );
|
||||
|
@ -20,7 +20,7 @@ public class Target {
|
||||
private int integerConstant;
|
||||
private Long longWrapperConstant;
|
||||
private Date dateConstant;
|
||||
private List<String> nameConstants = new ArrayList<String>();
|
||||
private List<String> nameConstants = new ArrayList<>();
|
||||
private CountryEnum country;
|
||||
|
||||
public String getPropertyThatShouldBeMapped() {
|
||||
|
@ -59,7 +59,7 @@ public class JavaFileAssert extends FileAssert {
|
||||
return Assertions.assertThat( FileUtils.readFileToString( actual, StandardCharsets.UTF_8 ) );
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
failWithMessage( "Unable to read" + actual.toString() + ". Exception: " + e.getMessage() );
|
||||
failWithMessage( "Unable to read" + actual + ". Exception: " + e.getMessage() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class DiagnosticDescriptor {
|
||||
|
||||
//Make the URI absolute in case it isn't (the case with JDK 6)
|
||||
try {
|
||||
return new URI( "file:" + uri.toString() );
|
||||
return new URI( "file:" + uri );
|
||||
}
|
||||
catch ( URISyntaxException e ) {
|
||||
throw new RuntimeException( e );
|
||||
@ -189,7 +189,7 @@ public class DiagnosticDescriptor {
|
||||
if ( kind != other.kind ) {
|
||||
return false;
|
||||
}
|
||||
if ( line != other.line ) {
|
||||
if ( !Objects.equals( line, other.line ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( !Objects.equals( message, other.message ) ) {
|
||||
|
@ -135,7 +135,7 @@ class JdkCompilingExtension extends CompilingExtension {
|
||||
// The JDK 8+ compilers report all ERROR diagnostics properly. Also when there are multiple per line.
|
||||
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,
|
||||
// so we filter out the surplus diagnostics. The input list is already sorted by file name and line number,
|
||||
|
@ -31,7 +31,7 @@ final class ModifiableURLClassLoader extends URLClassLoader {
|
||||
tryRegisterAsParallelCapable();
|
||||
}
|
||||
|
||||
private final ConcurrentMap<URL, URL> addedURLs = new ConcurrentHashMap<URL, URL>();
|
||||
private final ConcurrentMap<URL, URL> addedURLs = new ConcurrentHashMap<>();
|
||||
|
||||
ModifiableURLClassLoader(ClassLoader parent) {
|
||||
super( new URL[] { }, parent );
|
||||
|
Loading…
x
Reference in New Issue
Block a user