Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- to get jacoco report we need to set argLine in surefire,
without this snippet the jacoco argLine is lost -->
<!-- <configuration>
to get jacoco report we need to set argLine in surefire,
without this snippet the jacoco argLine is lost
<argLine>@{argLine} -Xms1024m -Xmx3072m</argLine>
</configuration>
</configuration>-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, Mapp
if ( mappingMethod == null ) {
return null;
}
if ( !ctx.getMappingsToGenerate().contains( mappingMethod ) ) {
if (!ctx.getMappingsToGenerate().contains( mappingMethod )) {
ctx.getMappingsToGenerate().add( mappingMethod );
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -887,4 +887,3 @@ public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,37 @@ public NestedTargetPropertyMappingHolder build() {
// However, here we do not forge name based mappings and we only
// do update on the defined Mappings.
if ( !groupedSourceReferences.nonNested.isEmpty() ) {

// SJDE: here we go from sourceparam to prop.
List<Mapping> newNonNested = new ArrayList<Mapping>();

for ( Mapping newNN : groupedSourceReferences.nonNested ) {
newNonNested.add( newNN.popSourceReferenceIntoParam() );
}

MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly(
groupByTargetName( groupedSourceReferences.nonNested ),
groupByTargetName( newNonNested ),
true
);
SourceReference reference = new SourceReference.BuilderFromProperty()
.sourceParameter( sourceParameter )
.name( targetProperty.getName() )
.build();

PropertyMapping propertyMapping = createPropertyMappingForNestedTarget(
nonNestedOptions,
targetProperty,
reference,
forceUpdateMethod
);
for ( Mapping mapping : groupedSourceReferences.nonNested ) {

if ( propertyMapping != null ) {
propertyMappings.add( propertyMapping );
PropertyMapping propertyMapping = createPropertyMappingForNestedTarget(
nonNestedOptions,
targetProperty,
mapping.getSourceReference(),
forceUpdateMethod
);

if ( propertyMapping != null ) {
propertyMappings.add( propertyMapping );
}

handledTargets.add( entryByTP.getKey().getName() );
}

handledTargets.add( entryByTP.getKey().getName() );
unprocessedDefinedTarget.put( targetProperty, groupedSourceReferences.notProcessedAppliesToAll );
}

unprocessedDefinedTarget.put( targetProperty, groupedSourceReferences.notProcessedAppliesToAll );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) {
Type sourceType = sourceRHS.getSourceType();

//Fail fast. If we could not find the method by now, no need to try
if ( sourceType.isPrimitive() || targetType.isPrimitive() ) {
if ( targetType.isPrimitive() ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@ public Mapping popSourceReference() {
return null;
}

public Mapping popSourceReferenceIntoParam() {
if ( sourceReference != null ) {
SourceReference newSourceReference = sourceReference.popIntoParameter();
if (newSourceReference != null ) {
return new Mapping(this, newSourceReference );
}
}
return null;
}

public List<String> getDependsOn() {
return dependsOn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,8 @@ public boolean equals(Object obj) {
return true;
}

@Override
public String toString() {
return type + " " + Strings.join( Arrays.asList( fullName ), "." );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ public SourceReference pop() {
}
}

public SourceReference popIntoParameter() {
if ( propertyEntries.size() == 1 ) {
Type paramType = propertyEntries.get( 0 ).getType();
String paramName = Strings.getSaveVariableName( paramType.getName() );
Parameter param = new Parameter( paramName, paramType );
return new SourceReference( param, new ArrayList<PropertyEntry>( ), isValid );
}
else {
return null;
}
}

@Override
public String toString() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

</#if>
</#list>
<#if !mapNullToDefault>
<#if !mapNullToDefault && !sourceParametersExcludingPrimitives.empty>
if ( <#list sourceParametersExcludingPrimitives as sourceParam>${sourceParam.name} == null<#if sourceParam_has_next> && </#if></#list> ) {
return<#if returnType.name != "void"> null</#if>;
}
Expand Down
115 changes: 115 additions & 0 deletions processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* 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.bugs._1148;

/**
* @author Filip Hrisafov
*/
class Entity {

static class NestedClient {
//CHECKSTYLE:OFF
public long id;
//CHECKSTYLE:ON
}

static class Client {

//CHECKSTYLE:OFF
public NestedClient nestedClient;
//CHECKSTYLE:ON
}

static class Dto {

//CHECKSTYLE:OFF
public long recipientId;
public long senderId;
public NestedDto nestedDto;
public NestedDto nestedDto2;
public ClientDto sameLevel;
public ClientDto sameLevel2;
public ClientDto level;
public ClientDto level2;
//CHECKSTYLE:ON
}

static class ClientDto {
//CHECKSTYLE:OFF
public NestedDto client;

//CHECKSTYLE:ON
ClientDto(NestedDto client) {
this.client = client;
}
}

static class NestedDto {
//CHECKSTYLE:OFF
public long id;
//CHECKSTYLE:ON

NestedDto(long id) {
this.id = id;
}
}

//CHECKSTYLE:OFF
public Client client;
public Client client2;
public NestedClient nested;
public NestedClient nested2;
private Client recipient;
private Client sender;
private long id;
private long id2;
//CHECKSTYLE:OFF

public Client getRecipient() {
return recipient;
}

public void setRecipient(Client recipient) {
this.recipient = recipient;
}

public Client getSender() {
return sender;
}

public void setSender(Client sender) {
this.sender = sender;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public long getId2() {
return id2;
}

public void setId2(long id2) {
this.id2 = id2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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.bugs._1148;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
* @author Filip Hrisafov
*/
@Mapper
public interface Issue1148Mapper {

Issue1148Mapper INSTANCE = Mappers.getMapper( Issue1148Mapper.class );

@Mappings({
@Mapping(source = "senderId", target = "sender.nestedClient.id"),
@Mapping(source = "recipientId", target = "recipient.nestedClient.id"),
@Mapping(source = "sameLevel.client.id", target = "client.nestedClient.id"),
@Mapping(source = "sameLevel2.client.id", target = "client2.nestedClient.id"),
@Mapping(source = "level.client.id", target = "nested.id"),
@Mapping(source = "level2.client.id", target = "nested2.id"),
@Mapping(source = "nestedDto.id", target = "id"),
@Mapping(source = "nestedDto2.id", target = "id2")
})
Entity toEntity(Entity.Dto dto);

@Mappings({
@Mapping(source = "dto2.senderId", target = "sender.nestedClient.id"),
@Mapping(source = "dto1.recipientId", target = "recipient.nestedClient.id"),
@Mapping(source = "dto1.sameLevel.client.id", target = "client.nestedClient.id"),
@Mapping(source = "dto2.sameLevel2.client.id", target = "client2.nestedClient.id"),
@Mapping(source = "dto1.level.client.id", target = "nested.id"),
@Mapping(source = "dto2.level2.client.id", target = "nested2.id"),
@Mapping(source = "dto1.nestedDto.id", target = "id"),
@Mapping(source = "dto2.nestedDto2.id", target = "id2")
})
Entity toEntity(Entity.Dto dto1, Entity.Dto dto2);
}
Loading