mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#310 Missing sourceType import in adder functionality
This commit is contained in:
parent
69beb9a6b4
commit
99889581c4
@ -19,7 +19,9 @@
|
|||||||
package org.mapstruct.ap.model.assignment;
|
package org.mapstruct.ap.model.assignment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.Assignment;
|
import org.mapstruct.ap.model.Assignment;
|
||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
@ -69,6 +71,14 @@ public class AdderWrapper extends AssignmentWrapper {
|
|||||||
return sourceReference;
|
return sourceReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Type> getImportTypes() {
|
||||||
|
Set<Type> imported = new HashSet<Type>();
|
||||||
|
imported.addAll( super.getImportTypes() );
|
||||||
|
imported.add( sourceType );
|
||||||
|
return imported;
|
||||||
|
}
|
||||||
|
|
||||||
public String getIteratorReference() {
|
public String getIteratorReference() {
|
||||||
return getAssignment().getSourceReference();
|
return getAssignment().getSourceReference();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ package org.mapstruct.ap.test.collection.adder;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -40,9 +41,11 @@ import org.mapstruct.ap.testutil.IssueKey;
|
|||||||
import org.mapstruct.ap.testutil.WithClasses;
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import org.mapstruct.ap.test.collection.adder.source.Foo;
|
||||||
|
import org.mapstruct.ap.test.collection.adder.source.Source2;
|
||||||
|
import org.mapstruct.ap.test.collection.adder.target.Target2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
@ -239,4 +242,22 @@ public class AdderTest {
|
|||||||
assertThat( target.getPets().get( 0 ) ).isEqualTo( 2L );
|
assertThat( target.getPets().get( 0 ) ).isEqualTo( 2L );
|
||||||
assertTrue( AdderUsageObserver.isUsed() );
|
assertTrue( AdderUsageObserver.isUsed() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IssueKey( "310" )
|
||||||
|
@Test
|
||||||
|
@WithClasses( {
|
||||||
|
Target2.class,
|
||||||
|
Source2.class,
|
||||||
|
Source2Target2Mapper.class,
|
||||||
|
Foo.class
|
||||||
|
} )
|
||||||
|
public void testMissingImport() throws DogException {
|
||||||
|
|
||||||
|
Source2 source = new Source2();
|
||||||
|
source.setAttributes( Arrays.asList( new Foo() ) );
|
||||||
|
|
||||||
|
Target2 target = Source2Target2Mapper.INSTANCE.toTarget( source );
|
||||||
|
assertThat( target ).isNotNull();
|
||||||
|
assertThat( target.getAttributes().size() ).isEqualTo( 1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2014 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.adder;
|
||||||
|
|
||||||
|
import org.mapstruct.CollectionMappingStrategy;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.ap.test.collection.adder.source.Source2;
|
||||||
|
import org.mapstruct.ap.test.collection.adder.target.Target2;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
@Mapper( collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED )
|
||||||
|
public abstract class Source2Target2Mapper {
|
||||||
|
|
||||||
|
public static final Source2Target2Mapper INSTANCE = Mappers.getMapper( Source2Target2Mapper.class );
|
||||||
|
|
||||||
|
public abstract Target2 toTarget( Source2 source );
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2014 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.adder.source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
public class Foo {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2014 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.adder.source;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
public class Source2 {
|
||||||
|
|
||||||
|
private List<Foo> attributes;
|
||||||
|
|
||||||
|
public List<Foo> getAttributes() {
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributes( List<Foo> attributes ) {
|
||||||
|
this.attributes = attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Sjaak Derksen.
|
||||||
|
*
|
||||||
|
* 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.adder.target;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.mapstruct.ap.test.collection.adder.source.Foo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
public class Target2 {
|
||||||
|
|
||||||
|
private List<Foo> attributes = new ArrayList<Foo>();
|
||||||
|
|
||||||
|
public Foo addAttribute( Foo foo ) {
|
||||||
|
attributes.add( foo );
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Foo> getAttributes() {
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributes( List<Foo> attributes ) {
|
||||||
|
this.attributes = attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user