mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Remove unnecessary generic type in Collections.empty*,
replace "for" on Stream API, replace anonymous classes on lambda
This commit is contained in:
parent
e5c5550182
commit
f02b3d1a42
@ -341,10 +341,7 @@ public class MappingProcessor extends AbstractProcessor {
|
||||
|
||||
@Override
|
||||
public int compare(ModelElementProcessor<?, ?> o1, ModelElementProcessor<?, ?> o2) {
|
||||
return
|
||||
o1.getPriority() < o2.getPriority() ? -1 :
|
||||
o1.getPriority() == o2.getPriority() ? 0 :
|
||||
1;
|
||||
return Integer.compare( o1.getPriority(), o2.getPriority() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import org.mapstruct.ap.internal.model.HelperMethod;
|
||||
import org.mapstruct.ap.internal.model.TypeConversion;
|
||||
import org.mapstruct.ap.internal.model.common.Assignment;
|
||||
import org.mapstruct.ap.internal.model.common.ConversionContext;
|
||||
import org.mapstruct.ap.internal.model.common.Type;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mapstruct.ap.internal.util.Collections.asSet;
|
||||
@ -31,7 +30,7 @@ public class DateToStringConversion implements ConversionProvider {
|
||||
@Override
|
||||
public Assignment to(ConversionContext conversionContext) {
|
||||
return new TypeConversion( asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ),
|
||||
Collections.<Type>emptyList(),
|
||||
Collections.emptyList(),
|
||||
getConversionExpression( conversionContext, "format" )
|
||||
);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class Annotation extends ModelElement {
|
||||
private List<String> properties;
|
||||
|
||||
public Annotation(Type type) {
|
||||
this( type, Collections.<String>emptyList() );
|
||||
this( type, Collections.emptyList() );
|
||||
}
|
||||
|
||||
public Annotation(Type type, List<String> properties) {
|
||||
|
@ -17,9 +17,11 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
@ -104,7 +106,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
singleMapping =
|
||||
targetName -> getMappingByTargetName( targetName, sourceMethod.getMappingOptions().getMappings() );
|
||||
mappingsInitializer =
|
||||
mappings -> mappings.stream().forEach( mapping -> initReferencesForSourceMethodMapping( mapping ) );
|
||||
mappings -> mappings.stream().forEach( this::initReferencesForSourceMethodMapping );
|
||||
this.method = sourceMethod;
|
||||
return this;
|
||||
}
|
||||
@ -112,7 +114,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
public Builder forgedMethod(Method method) {
|
||||
singleMapping = targetPropertyName -> null;
|
||||
mappingsInitializer =
|
||||
mappings -> mappings.stream().forEach( mapping -> initReferencesForForgedMethodMapping( mapping ) );
|
||||
mappings -> mappings.stream().forEach( this::initReferencesForForgedMethodMapping );
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
@ -177,8 +179,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
continue;
|
||||
}
|
||||
Map<String, Accessor> readAccessors = sourceParameter.getType().getPropertyReadAccessors();
|
||||
for ( String key : readAccessors.keySet() ) {
|
||||
unprocessedSourceProperties.put( key, readAccessors.get( key ) );
|
||||
|
||||
for ( Entry<String, Accessor> entry : readAccessors.entrySet() ) {
|
||||
unprocessedSourceProperties.put( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
existingVariableNames.addAll( method.getParameterNames() );
|
||||
@ -191,8 +194,8 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
}
|
||||
|
||||
// map properties with mapping
|
||||
boolean mappingErrorOccured = handleDefinedMappings();
|
||||
if ( mappingErrorOccured ) {
|
||||
boolean mappingErrorOccurred = handleDefinedMappings();
|
||||
if ( mappingErrorOccurred ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -366,13 +369,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
}
|
||||
else {
|
||||
Collections.sort(
|
||||
propertyMappings, new Comparator<PropertyMapping>() {
|
||||
@Override
|
||||
public int compare(PropertyMapping o1, PropertyMapping o2) {
|
||||
return graphAnalyzer.getTraversalSequence( o1.getName() )
|
||||
- graphAnalyzer.getTraversalSequence( o2.getName() );
|
||||
}
|
||||
}
|
||||
propertyMappings,
|
||||
Comparator.comparingInt( propertyMapping ->
|
||||
graphAnalyzer.getTraversalSequence( propertyMapping.getName() ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -512,9 +511,8 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
*/
|
||||
private static boolean isValidWhenReversed(Mapping mapping) {
|
||||
if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) {
|
||||
return mapping.getTargetReference().isValid() && ( mapping.getSourceReference() != null ?
|
||||
mapping.getSourceReference().isValid() :
|
||||
true );
|
||||
return mapping.getTargetReference().isValid() && ( mapping.getSourceReference() == null ||
|
||||
mapping.getSourceReference().isValid() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1051,24 +1049,15 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
}
|
||||
|
||||
public List<Parameter> getSourceParametersExcludingPrimitives() {
|
||||
List<Parameter> sourceParameters = new ArrayList<>();
|
||||
for ( Parameter sourceParam : getSourceParameters() ) {
|
||||
if ( !sourceParam.getType().isPrimitive() ) {
|
||||
sourceParameters.add( sourceParam );
|
||||
}
|
||||
}
|
||||
|
||||
return sourceParameters;
|
||||
return getSourceParameters().stream()
|
||||
.filter( parameter -> !parameter.getType().isPrimitive() )
|
||||
.collect( Collectors.toList() );
|
||||
}
|
||||
|
||||
public List<Parameter> getSourcePrimitiveParameters() {
|
||||
List<Parameter> sourceParameters = new ArrayList<>();
|
||||
for ( Parameter sourceParam : getSourceParameters() ) {
|
||||
if ( sourceParam.getType().isPrimitive() ) {
|
||||
sourceParameters.add( sourceParam );
|
||||
}
|
||||
}
|
||||
return sourceParameters;
|
||||
return getSourceParameters().stream()
|
||||
.filter( parameter -> parameter.getType().isPrimitive() )
|
||||
.collect( Collectors.toList() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1092,8 +1081,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
if ( !super.equals( obj ) ) {
|
||||
return false;
|
||||
}
|
||||
return propertyMappings != null ? propertyMappings.equals( that.propertyMappings ) :
|
||||
that.propertyMappings == null;
|
||||
return Objects.equals( propertyMappings, that.propertyMappings );
|
||||
}
|
||||
|
||||
private interface SingleMappingByTargetPropertyNameFunction {
|
||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
||||
import org.mapstruct.ap.internal.model.common.Type;
|
||||
@ -123,9 +124,7 @@ public final class LifecycleMethodResolver {
|
||||
List<SourceMethod> availableMethods =
|
||||
new ArrayList<>( methodsProvidedByParams.size() + sourceModelMethods.size() );
|
||||
|
||||
for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) {
|
||||
availableMethods.add( methodProvidedByParams );
|
||||
}
|
||||
availableMethods.addAll( methodsProvidedByParams );
|
||||
availableMethods.addAll( sourceModelMethods );
|
||||
|
||||
return availableMethods;
|
||||
@ -141,7 +140,7 @@ public final class LifecycleMethodResolver {
|
||||
List<SelectedMethod<SourceMethod>> matchingMethods = selectors.getMatchingMethods(
|
||||
method,
|
||||
callbackMethods,
|
||||
Collections.<Type> emptyList(),
|
||||
Collections.emptyList(),
|
||||
targetType,
|
||||
SelectionCriteria.forLifecycleMethods( selectionParameters ) );
|
||||
|
||||
@ -185,24 +184,14 @@ public final class LifecycleMethodResolver {
|
||||
}
|
||||
|
||||
private static List<SourceMethod> filterBeforeMappingMethods(List<SourceMethod> methods) {
|
||||
List<SourceMethod> result = new ArrayList<>();
|
||||
for ( SourceMethod method : methods ) {
|
||||
if ( method.isBeforeMappingMethod() ) {
|
||||
result.add( method );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return methods.stream()
|
||||
.filter( SourceMethod::isBeforeMappingMethod )
|
||||
.collect( Collectors.toList() );
|
||||
}
|
||||
|
||||
private static List<SourceMethod> filterAfterMappingMethods(List<SourceMethod> methods) {
|
||||
List<SourceMethod> result = new ArrayList<>();
|
||||
for ( SourceMethod method : methods ) {
|
||||
if ( method.isAfterMappingMethod() ) {
|
||||
result.add( method );
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return methods.stream()
|
||||
.filter( SourceMethod::isAfterMappingMethod )
|
||||
.collect( Collectors.toList() );
|
||||
}
|
||||
}
|
||||
|
@ -235,8 +235,7 @@ public class MethodReference extends ModelElement implements Assignment {
|
||||
|
||||
@Override
|
||||
public List<Type> getThrownTypes() {
|
||||
List<Type> exceptions = new ArrayList<>();
|
||||
exceptions.addAll( thrownTypes );
|
||||
List<Type> exceptions = new ArrayList<>( thrownTypes );
|
||||
if ( assignment != null ) {
|
||||
exceptions.addAll( assignment.getThrownTypes() );
|
||||
}
|
||||
|
@ -68,12 +68,7 @@ import static org.mapstruct.ap.internal.model.common.ImplementationType.withLoad
|
||||
public class TypeFactory {
|
||||
|
||||
private static final Extractor<BuilderInfo, String> BUILDER_INFO_CREATION_METHOD_EXTRACTOR =
|
||||
new Extractor<BuilderInfo, String>() {
|
||||
@Override
|
||||
public String apply(BuilderInfo builderInfo) {
|
||||
return builderInfo.getBuilderCreationMethod().toString();
|
||||
}
|
||||
};
|
||||
builderInfo -> builderInfo.getBuilderCreationMethod().toString();
|
||||
|
||||
private final Elements elementUtils;
|
||||
private final Types typeUtils;
|
||||
|
@ -85,7 +85,7 @@ public class MappingOptions {
|
||||
null,
|
||||
null,
|
||||
forForgedMethods ? BeanMapping.forForgedMethods() : null,
|
||||
Collections.<ValueMapping>emptyList(),
|
||||
Collections.emptyList(),
|
||||
restrictToDefinedMappings
|
||||
);
|
||||
|
||||
|
@ -144,8 +144,8 @@ public class SelectionParameters {
|
||||
|
||||
public static SelectionParameters forSourceRHS(SourceRHS sourceRHS) {
|
||||
return new SelectionParameters(
|
||||
Collections.<TypeMirror>emptyList(),
|
||||
Collections.<String>emptyList(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
null,
|
||||
null,
|
||||
sourceRHS
|
||||
|
@ -20,7 +20,6 @@ import javax.lang.model.type.DeclaredType;
|
||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
||||
import org.mapstruct.ap.internal.model.common.Type;
|
||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||
import org.mapstruct.ap.internal.util.Extractor;
|
||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||
import org.mapstruct.ap.internal.util.Message;
|
||||
import org.mapstruct.ap.internal.util.Strings;
|
||||
@ -214,12 +213,7 @@ public class SourceReference {
|
||||
Strings.join(
|
||||
method.getSourceParameters(),
|
||||
", ",
|
||||
new Extractor<Parameter, String>() {
|
||||
@Override
|
||||
public String apply(Parameter parameter) {
|
||||
return parameter.getName();
|
||||
}
|
||||
}
|
||||
Parameter::getName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
package org.mapstruct.ap.internal.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
@ -113,8 +112,8 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen
|
||||
AstModifyingAnnotationProcessor.class, AnnotationProcessorContext.class.getClassLoader()
|
||||
);
|
||||
|
||||
for ( Iterator<AstModifyingAnnotationProcessor> it = loader.iterator(); it.hasNext(); ) {
|
||||
processors.add( it.next() );
|
||||
for ( AstModifyingAnnotationProcessor astModifyingAnnotationProcessor : loader ) {
|
||||
processors.add( astModifyingAnnotationProcessor );
|
||||
}
|
||||
|
||||
return processors;
|
||||
|
@ -84,9 +84,7 @@ public class Fields {
|
||||
|
||||
private static void addFields(List<VariableElement> alreadyCollected, List<VariableElement> variablesToAdd) {
|
||||
List<VariableElement> safeToAdd = new ArrayList<>( variablesToAdd.size() );
|
||||
for ( VariableElement toAdd : variablesToAdd ) {
|
||||
safeToAdd.add( toAdd );
|
||||
}
|
||||
safeToAdd.addAll( variablesToAdd );
|
||||
|
||||
alreadyCollected.addAll( 0, safeToAdd );
|
||||
}
|
||||
|
@ -99,8 +99,7 @@ public class MapperConfiguration {
|
||||
}
|
||||
|
||||
public List<TypeMirror> imports() {
|
||||
List<TypeMirror> imports = new ArrayList<>();
|
||||
imports.addAll( mapperPrism.imports() );
|
||||
List<TypeMirror> imports = new ArrayList<>( mapperPrism.imports() );
|
||||
if ( mapperConfigPrism != null ) {
|
||||
imports.addAll( mapperConfigPrism.imports() );
|
||||
}
|
||||
@ -262,7 +261,7 @@ public class MapperConfiguration {
|
||||
|
||||
public boolean isDisableSubMappingMethodsGeneration() {
|
||||
if ( mapperPrism.disableSubMappingMethodsGeneration() ) {
|
||||
return mapperPrism.disableSubMappingMethodsGeneration();
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( mapperConfigPrism != null && mapperConfigPrism.disableSubMappingMethodsGeneration() ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user