mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#993 Add support for disabling the generation of forged mapping methods
This commit is contained in:
parent
5fccc6c2d5
commit
267c2e98f9
@ -159,4 +159,23 @@ public @interface Mapper {
|
|||||||
* @return strategy how to do null checking
|
* @return strategy how to do null checking
|
||||||
*/
|
*/
|
||||||
NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION;
|
NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a
|
||||||
|
* sub-mapping method between the two beans. If this property is set to {@code true} MapStruct will not try to
|
||||||
|
* automatically generate sub-mapping methods.
|
||||||
|
* <p>
|
||||||
|
* Can be configured by the {@link MapperConfig#disableSubMappingMethodsGeneration()} as well.
|
||||||
|
* <p>
|
||||||
|
* Note: If you need to use {@code disableSubMappingMethodsGeneration} please contact the MapStruct team at
|
||||||
|
* <a href="http://mapstruct.org">mapstruct.org</a> or
|
||||||
|
* <a href="https://github.com/mapstruct/mapstruct">github.com/mapstruct/mapstruct</a> to share what problem you
|
||||||
|
* are facing with the automatic sub-mapping generation.
|
||||||
|
*
|
||||||
|
* @return whether the automatic generation of sub-mapping methods is disabled
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
|
*/
|
||||||
|
boolean disableSubMappingMethodsGeneration() default false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,4 +146,22 @@ public @interface MapperConfig {
|
|||||||
* @return strategy how to do null checking
|
* @return strategy how to do null checking
|
||||||
*/
|
*/
|
||||||
NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION;
|
NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a
|
||||||
|
* sub-mapping method between the two beans. If this property is set to {@code true} MapStruct will not try to
|
||||||
|
* automatically generate sub-mapping methods.
|
||||||
|
* <p>
|
||||||
|
* Can be overridden by {@link Mapper#disableSubMappingMethodsGeneration()}
|
||||||
|
* <p>
|
||||||
|
* Note: If you need to use {@code disableSubMappingMethodsGeneration} please contact the MapStruct team at
|
||||||
|
* <a href="http://mapstruct.org">mapstruct.org</a> or
|
||||||
|
* <a href="https://github.com/mapstruct/mapstruct">github.com/mapstruct/mapstruct</a> to share what problem you
|
||||||
|
* are facing with the automatic sub-mapping generation.
|
||||||
|
*
|
||||||
|
* @return whether the automatic generation of sub-mapping methods is disabled
|
||||||
|
*
|
||||||
|
* @since 1.2
|
||||||
|
*/
|
||||||
|
boolean disableSubMappingMethodsGeneration() default false;
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,12 @@ package org.mapstruct.ap.internal.model;
|
|||||||
|
|
||||||
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
||||||
import org.mapstruct.ap.internal.model.common.ParameterBinding;
|
import org.mapstruct.ap.internal.model.common.ParameterBinding;
|
||||||
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.source.ForgedMethod;
|
import org.mapstruct.ap.internal.model.source.ForgedMethod;
|
||||||
import org.mapstruct.ap.internal.model.source.MappingMethodUtils;
|
import org.mapstruct.ap.internal.model.source.MappingMethodUtils;
|
||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
|
import org.mapstruct.ap.internal.util.MapperConfiguration;
|
||||||
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Filip Hrisafov
|
* @author Filip Hrisafov
|
||||||
@ -47,6 +50,11 @@ class AbstractBaseBuilder<B extends AbstractBaseBuilder<B>> {
|
|||||||
return myself;
|
return myself;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isDisableSubMappingMethodsGeneration() {
|
||||||
|
MapperConfiguration configuration = MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() );
|
||||||
|
return configuration.isDisableSubMappingMethodsGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a forged assignment from the provided {@code sourceRHS} and {@code forgedMethod}. If a mapping method
|
* Creates a forged assignment from the provided {@code sourceRHS} and {@code forgedMethod}. If a mapping method
|
||||||
* for the {@code forgedMethod} already exists, then this method used for the assignment.
|
* for the {@code forgedMethod} already exists, then this method used for the assignment.
|
||||||
@ -109,4 +117,26 @@ class AbstractBaseBuilder<B extends AbstractBaseBuilder<B>> {
|
|||||||
|
|
||||||
return assignment;
|
return assignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports that a mapping could not be created.
|
||||||
|
*
|
||||||
|
* @param method the method that should be mapped
|
||||||
|
* @param sourceErrorMessagePart the error message part for the source
|
||||||
|
* @param sourceRHS the {@link SourceRHS}
|
||||||
|
* @param targetType the type of the target mapping
|
||||||
|
* @param targetPropertyName the name of the target property
|
||||||
|
*/
|
||||||
|
void reportCannotCreateMapping(Method method, String sourceErrorMessagePart, SourceRHS sourceRHS, Type targetType,
|
||||||
|
String targetPropertyName) {
|
||||||
|
ctx.getMessager().printMessage(
|
||||||
|
method.getExecutable(),
|
||||||
|
Message.PROPERTYMAPPING_MAPPING_NOT_FOUND,
|
||||||
|
sourceErrorMessagePart,
|
||||||
|
targetType,
|
||||||
|
targetPropertyName,
|
||||||
|
targetType,
|
||||||
|
sourceRHS.getSourceType() /* original source type */
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,9 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
|
|||||||
protected abstract boolean shouldUsePropertyNamesInHistory();
|
protected abstract boolean shouldUsePropertyNamesInHistory();
|
||||||
|
|
||||||
Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) {
|
Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) {
|
||||||
|
if ( isDisableSubMappingMethodsGeneration() ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String name = getName( sourceType, targetType );
|
String name = getName( sourceType, targetType );
|
||||||
name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() );
|
name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() );
|
||||||
|
@ -112,6 +112,21 @@ public abstract class ContainerMappingMethodBuilder<B extends ContainerMappingMe
|
|||||||
forgedMethod.addThrownTypes( assignment.getThrownTypes() );
|
forgedMethod.addThrownTypes( assignment.getThrownTypes() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( assignment == null ) {
|
||||||
|
if ( method instanceof ForgedMethod ) {
|
||||||
|
// leave messaging to calling property mapping
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reportCannotCreateMapping(
|
||||||
|
method,
|
||||||
|
String.format( "%s \"%s\"", sourceRHS.getSourceErrorMessagePart(), sourceRHS.getSourceType() ),
|
||||||
|
sourceRHS,
|
||||||
|
targetElementType,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assignment = getWrapper( assignment, method );
|
assignment = getWrapper( assignment, method );
|
||||||
|
|
||||||
|
@ -110,6 +110,27 @@ public class MapMappingMethod extends NormalTypeMappingMethod {
|
|||||||
keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType );
|
keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( keyAssignment == null ) {
|
||||||
|
if ( method instanceof ForgedMethod ) {
|
||||||
|
// leave messaging to calling property mapping
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reportCannotCreateMapping(
|
||||||
|
method,
|
||||||
|
String.format(
|
||||||
|
"%s \"%s\"",
|
||||||
|
keySourceRHS.getSourceErrorMessagePart(),
|
||||||
|
keySourceRHS.getSourceType()
|
||||||
|
),
|
||||||
|
keySourceRHS,
|
||||||
|
keyTargetType,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// find mapping method or conversion for value
|
// find mapping method or conversion for value
|
||||||
Type valueSourceType = sourceTypeParams.get( 1 ).getTypeBound();
|
Type valueSourceType = sourceTypeParams.get( 1 ).getTypeBound();
|
||||||
Type valueTargetType = resultTypeParams.get( 1 ).getTypeBound();
|
Type valueTargetType = resultTypeParams.get( 1 ).getTypeBound();
|
||||||
@ -140,6 +161,26 @@ public class MapMappingMethod extends NormalTypeMappingMethod {
|
|||||||
valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType );
|
valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( valueAssignment == null ) {
|
||||||
|
if ( method instanceof ForgedMethod ) {
|
||||||
|
// leave messaging to calling property mapping
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reportCannotCreateMapping(
|
||||||
|
method,
|
||||||
|
String.format(
|
||||||
|
"%s \"%s\"",
|
||||||
|
valueSourceRHS.getSourceErrorMessagePart(),
|
||||||
|
valueSourceRHS.getSourceType()
|
||||||
|
),
|
||||||
|
valueSourceRHS,
|
||||||
|
valueTargetType,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mapNullToDefault
|
// mapNullToDefault
|
||||||
boolean mapNullToDefault = false;
|
boolean mapNullToDefault = false;
|
||||||
if ( method.getMapperConfiguration() != null ) {
|
if ( method.getMapperConfiguration() != null ) {
|
||||||
|
@ -302,14 +302,12 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctx.getMessager().printMessage(
|
reportCannotCreateMapping(
|
||||||
method.getExecutable(),
|
method,
|
||||||
Message.PROPERTYMAPPING_MAPPING_NOT_FOUND,
|
|
||||||
rightHandSide.getSourceErrorMessagePart(),
|
rightHandSide.getSourceErrorMessagePart(),
|
||||||
|
rightHandSide,
|
||||||
targetType,
|
targetType,
|
||||||
targetPropertyName,
|
targetPropertyName
|
||||||
targetType,
|
|
||||||
rightHandSide.getSourceType() /* original source type */
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,6 +633,9 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Assignment forgeMapping(SourceRHS sourceRHS) {
|
private Assignment forgeMapping(SourceRHS sourceRHS) {
|
||||||
|
if ( forgedNamedBased && isDisableSubMappingMethodsGeneration() ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Type sourceType = sourceRHS.getSourceType();
|
Type sourceType = sourceRHS.getSourceType();
|
||||||
|
|
||||||
|
@ -194,6 +194,18 @@ public class MapperConfiguration {
|
|||||||
return mapperPrism.componentModel(); // fall back to default defined in the annotation
|
return mapperPrism.componentModel(); // fall back to default defined in the annotation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDisableSubMappingMethodsGeneration() {
|
||||||
|
if ( mapperPrism.disableSubMappingMethodsGeneration() ) {
|
||||||
|
return mapperPrism.disableSubMappingMethodsGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mapperConfigPrism != null && mapperConfigPrism.disableSubMappingMethodsGeneration() ) {
|
||||||
|
return mapperConfigPrism.disableSubMappingMethodsGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapperPrism.disableSubMappingMethodsGeneration(); // fall back to default defined in the annotation
|
||||||
|
}
|
||||||
|
|
||||||
public DeclaredType config() {
|
public DeclaredType config() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,23 @@ public class ErroneousCollectionMappingTest {
|
|||||||
public void shouldFailOnNoElementMappingFound() {
|
public void shouldFailOnNoElementMappingFound() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey("993")
|
||||||
|
@WithClasses({ ErroneousCollectionNoElementMappingFoundDisabledAuto.class })
|
||||||
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousCollectionNoElementMappingFoundDisabledAuto.class,
|
||||||
|
kind = Kind.ERROR,
|
||||||
|
line = 32,
|
||||||
|
messageRegExp =
|
||||||
|
"Can't map collection element \".*AttributedString\" to \".*String \". " +
|
||||||
|
"Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldFailOnNoElementMappingFoundWithDisabledAuto() {
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("459")
|
@IssueKey("459")
|
||||||
@WithClasses({ ErroneousCollectionNoKeyMappingFound.class })
|
@WithClasses({ ErroneousCollectionNoKeyMappingFound.class })
|
||||||
@ -139,6 +156,22 @@ public class ErroneousCollectionMappingTest {
|
|||||||
public void shouldFailOnNoKeyMappingFound() {
|
public void shouldFailOnNoKeyMappingFound() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey("993")
|
||||||
|
@WithClasses({ ErroneousCollectionNoKeyMappingFoundDisabledAuto.class })
|
||||||
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousCollectionNoKeyMappingFoundDisabledAuto.class,
|
||||||
|
kind = Kind.ERROR,
|
||||||
|
line = 32,
|
||||||
|
messageRegExp = "Can't map map key \".*AttributedString\" to \".*String \". " +
|
||||||
|
"Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() {
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("459")
|
@IssueKey("459")
|
||||||
@WithClasses({ ErroneousCollectionNoValueMappingFound.class })
|
@WithClasses({ ErroneousCollectionNoValueMappingFound.class })
|
||||||
@ -154,4 +187,20 @@ public class ErroneousCollectionMappingTest {
|
|||||||
)
|
)
|
||||||
public void shouldFailOnNoValueMappingFound() {
|
public void shouldFailOnNoValueMappingFound() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey("993")
|
||||||
|
@WithClasses({ ErroneousCollectionNoValueMappingFoundDisabledAuto.class })
|
||||||
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousCollectionNoValueMappingFoundDisabledAuto.class,
|
||||||
|
kind = Kind.ERROR,
|
||||||
|
line = 32,
|
||||||
|
messageRegExp = "Can't map map value \".*AttributedString\" to \".*String \". " +
|
||||||
|
"Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldFailOnNoValueMappingFoundWithDisabledAuto() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.collection.erroneous;
|
||||||
|
|
||||||
|
import java.text.AttributedString;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface ErroneousCollectionNoElementMappingFoundDisabledAuto {
|
||||||
|
|
||||||
|
List<String> map(List<AttributedString> source);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.collection.erroneous;
|
||||||
|
|
||||||
|
import java.text.AttributedString;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface ErroneousCollectionNoKeyMappingFoundDisabledAuto {
|
||||||
|
|
||||||
|
Map<String, String> map(Map<AttributedString, String> source);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.collection.erroneous;
|
||||||
|
|
||||||
|
import java.text.AttributedString;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface ErroneousCollectionNoValueMappingFoundDisabledAuto {
|
||||||
|
|
||||||
|
Map<String, String> map(Map<String, AttributedString> source);
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.java8stream.erroneous;
|
||||||
|
|
||||||
|
import java.text.AttributedString;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface ErroneousListToStreamNoElementMappingFoundDisabledAuto {
|
||||||
|
|
||||||
|
Stream<String> mapCollectionToStream(List<AttributedString> source);
|
||||||
|
}
|
@ -115,13 +115,30 @@ public class ErroneousStreamMappingTest {
|
|||||||
@Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class,
|
@Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 36,
|
line = 36,
|
||||||
messageRegExp = "Can't map Stream element .*AttributedString attributedString\" to .*String string\"." +
|
messageRegExp = "Can't map Stream element \".*AttributedString attributedString\" to \".*String " +
|
||||||
" Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)")
|
"string\". Consider to declare/implement a mapping method: \".*String map(.*AttributedString " +
|
||||||
|
"value)")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public void shouldFailOnNoElementMappingFoundForStreamToStream() {
|
public void shouldFailOnNoElementMappingFoundForStreamToStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey("993")
|
||||||
|
@WithClasses({ ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class })
|
||||||
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class,
|
||||||
|
kind = Kind.ERROR,
|
||||||
|
line = 32,
|
||||||
|
messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " +
|
||||||
|
"declare/implement a mapping method: \".*String map(.*AttributedString value)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() {
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ ErroneousListToStreamNoElementMappingFound.class })
|
@WithClasses({ ErroneousListToStreamNoElementMappingFound.class })
|
||||||
@ExpectedCompilationOutcome(
|
@ExpectedCompilationOutcome(
|
||||||
@ -130,13 +147,30 @@ public class ErroneousStreamMappingTest {
|
|||||||
@Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class,
|
@Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 37,
|
line = 37,
|
||||||
messageRegExp = "Can't map .*AttributedString attributedString\" to .*String string\". " +
|
messageRegExp =
|
||||||
"Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)")
|
"Can't map Stream element \".*AttributedString attributedString\" to \".*String string\". " +
|
||||||
|
"Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public void shouldFailOnNoElementMappingFoundForListToStream() {
|
public void shouldFailOnNoElementMappingFoundForListToStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey("993")
|
||||||
|
@WithClasses({ ErroneousListToStreamNoElementMappingFoundDisabledAuto.class })
|
||||||
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class,
|
||||||
|
kind = Kind.ERROR,
|
||||||
|
line = 33,
|
||||||
|
messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " +
|
||||||
|
"declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() {
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ ErroneousStreamToListNoElementMappingFound.class })
|
@WithClasses({ ErroneousStreamToListNoElementMappingFound.class })
|
||||||
@ExpectedCompilationOutcome(
|
@ExpectedCompilationOutcome(
|
||||||
@ -145,10 +179,27 @@ public class ErroneousStreamMappingTest {
|
|||||||
@Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class,
|
@Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 37,
|
line = 37,
|
||||||
messageRegExp = "Can't map Stream element .*AttributedString attributedString\" to .*String string\"." +
|
messageRegExp =
|
||||||
|
"Can't map Stream element \".*AttributedString attributedString\" to .*String string\"." +
|
||||||
" Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)")
|
" Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public void shouldFailOnNoElementMappingFoundForStreamToList() {
|
public void shouldFailOnNoElementMappingFoundForStreamToList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey("993")
|
||||||
|
@WithClasses({ ErroneousStreamToListNoElementMappingFoundDisabledAuto.class })
|
||||||
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousStreamToListNoElementMappingFoundDisabledAuto.class,
|
||||||
|
kind = Kind.ERROR,
|
||||||
|
line = 33,
|
||||||
|
messageRegExp = "Can't map stream element \".*AttributedString\" to .*String \". Consider to " +
|
||||||
|
"declare/implement a mapping method: \".*String map(.*AttributedString value)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldFailOnNoElementMappingFoundForStreamToListWithDisabledAuto() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.java8stream.erroneous;
|
||||||
|
|
||||||
|
import java.text.AttributedString;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface ErroneousStreamToListNoElementMappingFoundDisabledAuto {
|
||||||
|
|
||||||
|
List<String> mapStreamToCollection(Stream<AttributedString> source);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.java8stream.erroneous;
|
||||||
|
|
||||||
|
import java.text.AttributedString;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface ErroneousStreamToStreamNoElementMappingFoundDisabledAuto {
|
||||||
|
|
||||||
|
Stream<String> mapStreamToStream(Stream<AttributedString> source);
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.nestedbeans;
|
||||||
|
|
||||||
|
import org.mapstruct.MapperConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@MapperConfig(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface DisableConfig {
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.nestedbeans;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
|
||||||
|
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||||
|
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||||
|
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@WithClasses({
|
||||||
|
House.class, HouseDto.class,
|
||||||
|
Wheel.class, WheelDto.class,
|
||||||
|
Roof.class, RoofDto.class,
|
||||||
|
RoofType.class, ExternalRoofType.class
|
||||||
|
})
|
||||||
|
@RunWith(AnnotationProcessorTestRunner.class)
|
||||||
|
public class DisablingNestedSimpleBeansMappingTest {
|
||||||
|
|
||||||
|
@WithClasses({
|
||||||
|
ErroneousDisabledHouseMapper.class
|
||||||
|
})
|
||||||
|
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousDisabledHouseMapper.class,
|
||||||
|
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||||
|
line = 29,
|
||||||
|
messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " +
|
||||||
|
"declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\."
|
||||||
|
)
|
||||||
|
})
|
||||||
|
@Test
|
||||||
|
public void shouldUseDisabledMethodGenerationOnMapper() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithClasses({
|
||||||
|
ErroneousDisabledViaConfigHouseMapper.class,
|
||||||
|
DisableConfig.class
|
||||||
|
})
|
||||||
|
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = ErroneousDisabledViaConfigHouseMapper.class,
|
||||||
|
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||||
|
line = 29,
|
||||||
|
messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " +
|
||||||
|
"declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\."
|
||||||
|
)
|
||||||
|
})
|
||||||
|
@Test
|
||||||
|
public void shouldUseDisabledMethodGenerationOnMapperConfig() throws Exception {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.nestedbeans;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(disableSubMappingMethodsGeneration = true)
|
||||||
|
public interface ErroneousDisabledHouseMapper {
|
||||||
|
|
||||||
|
HouseDto houseToHouseDto(House house);
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.nestedbeans;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper(config = DisableConfig.class)
|
||||||
|
public interface ErroneousDisabledViaConfigHouseMapper {
|
||||||
|
|
||||||
|
HouseDto houseToHouseDto(House house);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user