mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#538 Add missing imports for a collection/map implementation and the parameter types
This commit is contained in:
parent
8816b380c3
commit
edac1b17cc
@ -21,6 +21,7 @@ package org.mapstruct.ap.model.common;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -234,15 +235,23 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
|
||||
@Override
|
||||
public Set<Type> getImportTypes() {
|
||||
Set<Type> result = new HashSet<Type>();
|
||||
|
||||
result.add( this );
|
||||
|
||||
if ( implementationType != null ) {
|
||||
return Collections.singleton( implementationType );
|
||||
result.addAll( implementationType.getImportTypes() );
|
||||
}
|
||||
else if ( componentType != null ) {
|
||||
return Collections.singleton( componentType );
|
||||
|
||||
if ( componentType != null ) {
|
||||
result.addAll( componentType.getImportTypes() );
|
||||
}
|
||||
else {
|
||||
return Collections.<Type>emptySet();
|
||||
|
||||
for ( Type parameter : typeParameters ) {
|
||||
result.addAll( parameter.getImportTypes() );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -495,7 +504,8 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
|
||||
List<ExecutableElement> result = new ArrayList<ExecutableElement>();
|
||||
List<ExecutableElement> setterMethods = getSetters();
|
||||
List<ExecutableElement> getterMethods = new ArrayList( getPropertyReadAccessors().values() );
|
||||
List<ExecutableElement> getterMethods =
|
||||
new ArrayList<ExecutableElement>( getPropertyReadAccessors().values() );
|
||||
|
||||
// there could be a getter method for a list/map that is not present as setter.
|
||||
// a getter could substitute the setter in that case and act as setter.
|
||||
|
@ -18,9 +18,6 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.collection.map;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
import static org.fest.assertions.MapAssert.entry;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
@ -28,16 +25,21 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.test.collection.map.other.ImportedType;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import static org.fest.assertions.MapAssert.entry;
|
||||
|
||||
/**
|
||||
* Test for implementation of {@code Map} mapping methods.
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
@WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class })
|
||||
@WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class, ImportedType.class })
|
||||
@IssueKey("44")
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
public class MapMappingTest {
|
||||
|
@ -19,11 +19,15 @@
|
||||
package org.mapstruct.ap.test.collection.map;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mapstruct.ap.test.collection.map.other.ImportedType;
|
||||
|
||||
public class Source {
|
||||
|
||||
private Map<Long, Date> values;
|
||||
private LinkedHashMap<String, ImportedType> stringEnumMap;
|
||||
|
||||
public Map<Long, Date> getValues() {
|
||||
return values;
|
||||
@ -32,4 +36,12 @@ public class Source {
|
||||
public void setValues(Map<Long, Date> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, ImportedType> getStringEnumMap() {
|
||||
return stringEnumMap;
|
||||
}
|
||||
|
||||
public void setStringEnumMap(LinkedHashMap<String, ImportedType> stringEnumMap) {
|
||||
this.stringEnumMap = stringEnumMap;
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,15 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.collection.map;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mapstruct.ap.test.collection.map.other.ImportedType;
|
||||
|
||||
public class Target {
|
||||
|
||||
private Map<String, String> values;
|
||||
private LinkedHashMap<String, ImportedType> stringEnumMap;
|
||||
|
||||
public Map<String, String> getValues() {
|
||||
return values;
|
||||
@ -31,4 +35,12 @@ public class Target {
|
||||
public void setValues(Map<String, String> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, ImportedType> getStringEnumMap() {
|
||||
return stringEnumMap;
|
||||
}
|
||||
|
||||
public void setStringEnumMap(LinkedHashMap<String, ImportedType> stringEnumMap) {
|
||||
this.stringEnumMap = stringEnumMap;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright 2012-2015 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.map.other;
|
||||
|
||||
/**
|
||||
* A type that needs to be imported by the mapper implementation
|
||||
*
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public enum ImportedType {
|
||||
A, B, C;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user