#81 Formatting

This commit is contained in:
Gunnar Morling 2014-02-09 11:21:52 +01:00
parent 4bd1022b89
commit f122daec6d
30 changed files with 94 additions and 116 deletions

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
@ -76,7 +75,7 @@ public class Method {
}
public static Method forFactoryMethod(Type declaringMapper, ExecutableElement executable,
Type returnType ) {
Type returnType) {
return new Method(
declaringMapper,
@ -89,8 +88,6 @@ public class Method {
);
}
private Method(Type declaringMapper, ExecutableElement executable, List<Parameter> parameters, Type returnType,
Map<String, List<Mapping>> mappings, IterableMapping iterableMapping, MapMapping mapMapping) {
this.declaringMapper = declaringMapper;

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.model.source;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;

View File

@ -19,7 +19,6 @@
package org.mapstruct.ap.processor;
import java.util.ListIterator;
import javax.lang.model.element.TypeElement;
import org.mapstruct.ap.model.Annotation;

View File

@ -27,6 +27,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
@ -180,7 +181,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
method.setIterableMapping( reverseMappingMethod.getIterableMapping() );
}
IterableMappingMethod iterableMappingMethod
= getIterableMappingMethod( mapperReferences, methods, method );
= getIterableMappingMethod( mapperReferences, methods, method );
hasFactoryMethod = iterableMappingMethod.getFactoryMethod() != null;
mappingMethods.add( iterableMappingMethod );
}
@ -222,36 +223,36 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
}
private MethodReference getFactoryMethod(List<MapperReference> mapperReferences, List<Method> methods,
Type returnType) {
Type returnType) {
MethodReference result = null;
for ( Method method : methods ) {
if ( !method.requiresImplementation() && !method.isIterableMapping() && !method.isMapMapping()
&& method.getMappings().isEmpty() && method.getParameters().isEmpty() ) {
if ( method.getReturnType().equals( returnType ) ) {
if ( result == null ) {
MapperReference mapperReference = null;
for ( MapperReference ref : mapperReferences ) {
if ( ref.getMapperType().equals( method.getDeclaringMapper() ) ) {
mapperReference = ref;
break;
}
if ( method.getReturnType().equals( returnType ) ) {
if ( result == null ) {
MapperReference mapperReference = null;
for ( MapperReference ref : mapperReferences ) {
if ( ref.getMapperType().equals( method.getDeclaringMapper() ) ) {
mapperReference = ref;
break;
}
result = new MethodReference(method, mapperReference);
}
else {
messager.printMessage(
Kind.ERROR,
String.format(
"Ambigious factory method: \"%s\" conflicts with \"%s\".",
result,
method
),
method.getExecutable()
);
}
}
}
result = new MethodReference( method, mapperReference );
}
else {
messager.printMessage(
Kind.ERROR,
String.format(
"Ambigious factory methods: \"%s\" conflicts with \"%s\".",
result,
method
),
method.getExecutable()
);
}
}
}
}
return result;
}
@ -333,7 +334,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
}
private BeanMappingMethod getBeanMappingMethod(List<MapperReference> mapperReferences, List<Method> methods,
Method method, ReportingPolicy unmappedTargetPolicy) {
Method method, ReportingPolicy unmappedTargetPolicy) {
List<PropertyMapping> propertyMappings = new ArrayList<PropertyMapping>();
Set<String> mappedTargetProperties = new HashSet<String>();
@ -591,7 +592,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
}
private IterableMappingMethod getIterableMappingMethod(List<MapperReference> mapperReferences, List<Method> methods,
Method method) {
Method method) {
Type sourceElementType = method.getSourceParameters().iterator().next().getType().getTypeParameters().get( 0 );
Type targetElementType = method.getResultType().getTypeParameters().get( 0 );
@ -631,7 +632,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
}
private MapMappingMethod getMapMappingMethod(List<MapperReference> mapperReferences, List<Method> methods,
Method method) {
Method method) {
List<Type> sourceTypeParams = method.getSourceParameters().iterator().next().getType().getTypeParameters();
Type sourceKeyType = sourceTypeParams.get( 0 );
Type sourceValueType = sourceTypeParams.get( 1 );
@ -689,9 +690,11 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
);
}
MethodReference factoryMethod = getFactoryMethod( mapperReferences, methods, method.getReturnType() );
return new MapMappingMethod( method, keyMappingMethod, keyConversion, valueMappingMethod, valueConversion,
factoryMethod );
MethodReference factoryMethod = getFactoryMethod( mapperReferences, methods, method.getReturnType() );
return new MapMappingMethod(
method, keyMappingMethod, keyConversion, valueMappingMethod, valueConversion,
factoryMethod
);
}
private TypeConversion getConversion(Type sourceType, Type targetType, String dateFormat, String sourceReference) {
@ -708,8 +711,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
}
private MethodReference getMappingMethodReference(List<MapperReference> mapperReferences,
Iterable<Method> methods, Type parameterType,
Type returnType) {
Iterable<Method> methods, Type parameterType,
Type returnType) {
List<Method> candidatesWithMathingTargetType = new ArrayList<Method>();
for ( Method method : methods ) {

View File

@ -18,13 +18,10 @@
*/
package org.mapstruct.ap.processor;
import static javax.lang.model.util.ElementFilter.methodsIn;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.processing.Messager;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
@ -48,6 +45,8 @@ import org.mapstruct.ap.prism.MappingPrism;
import org.mapstruct.ap.prism.MappingsPrism;
import org.mapstruct.ap.util.AnnotationProcessingException;
import static javax.lang.model.util.ElementFilter.methodsIn;
/**
* A {@link ModelElementProcessor} which retrieves a list of {@link Method}s
* representing all the mapping methods of the given bean mapper type as well as

View File

@ -42,4 +42,4 @@ public <@includeModel object=returnType/> ${name}(<#list parameters as param><@i
return ${resultName};
</#if>
}
}

View File

@ -20,14 +20,13 @@ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Bar {
private String prop;
private final String someTypeProp;
public Bar( String someTypeProp ) {
public Bar(String someTypeProp) {
this.someTypeProp = someTypeProp;
}

View File

@ -19,7 +19,6 @@
package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a.BarFactory;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
@ -30,11 +29,12 @@ import org.testng.annotations.Test;
/**
* @author Sjaak Derksen
*
*/
@IssueKey( "81" )
@WithClasses( { Bar.class, Foo.class, BarFactory.class, Source.class, SourceTargetMapperAndBarFactory.class,
Target.class } )
@IssueKey("81")
@WithClasses({
Bar.class, Foo.class, BarFactory.class, Source.class, SourceTargetMapperAndBarFactory.class,
Target.class
})
public class FactoryTest extends MapperTestBase {
@ -45,12 +45,12 @@ public class FactoryTest extends MapperTestBase {
diagnostics = {
@Diagnostic(type = BarFactory.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 30,
messageRegExp = "^Ambigious factory method: \"org\\.mapstruct\\.ap\\.test\\.erroneous\\."
+ "ambiguousfactorymethod\\.Bar createBar\\(\\)\" conflicts with "
+ "\"org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod\\.Bar "
+ "org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod"
+ "\\.a\\.BarFactory\\.createBar\\(\\)\"\\.$")
line = 29,
messageRegExp = "^Ambigious factory methods: \"org\\.mapstruct\\.ap\\.test\\.erroneous\\."
+ "ambiguousfactorymethod\\.Bar createBar\\(\\)\" conflicts with "
+ "\"org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod\\.Bar "
+ "org\\.mapstruct\\.ap\\.test\\.erroneous\\.ambiguousfactorymethod"
+ "\\.a\\.BarFactory\\.createBar\\(\\)\"\\.$")
}
)
public void shouldUseTwoFactoryMethods() {

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Foo {
private String prop;

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Source {
@ -31,7 +30,7 @@ public class Source {
return prop;
}
public void setProp( Foo prop ) {
public void setProp(Foo prop) {
this.prop = prop;
}
}

View File

@ -24,18 +24,17 @@ import org.mapstruct.factory.Mappers;
/**
* @author Sjaak Derksen
*
*/
@Mapper( uses = BarFactory.class )
@Mapper(uses = BarFactory.class)
public abstract class SourceTargetMapperAndBarFactory {
public static final SourceTargetMapperAndBarFactory INSTANCE =
Mappers.getMapper( SourceTargetMapperAndBarFactory.class );
Mappers.getMapper( SourceTargetMapperAndBarFactory.class );
public abstract Target sourceToTarget(Source source);
public abstract Bar fooToBar(Foo foo);
public Bar createBar() {
return new Bar("BAR");
return new Bar( "BAR" );
}
}

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod;
/**
* @author Sjaak Derksen
*
*/
public class Target {

View File

@ -22,13 +22,12 @@ import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar;
/**
*
* @author Sjaak Derksen
*/
public class BarFactory {
public Bar createBar() {
return new Bar("BAR");
return new Bar( "BAR" );
}
}

View File

@ -20,14 +20,13 @@ package org.mapstruct.ap.test.factories;
/**
* @author Sjaak Derksen
*
*/
public class Bar1 {
private String prop;
private final String someTypeProp;
public Bar1( String someTypeProp ) {
public Bar1(String someTypeProp) {
this.someTypeProp = someTypeProp;
}

View File

@ -20,13 +20,12 @@ package org.mapstruct.ap.test.factories;
/**
* @author Sjaak Derksen
*
*/
public class Bar2 {
private String prop;
private final String someTypeProp;
public Bar2( String someTypeProp ) {
public Bar2(String someTypeProp) {
this.someTypeProp = someTypeProp;
}

View File

@ -20,14 +20,13 @@ package org.mapstruct.ap.test.factories;
/**
* @author Sjaak Derksen
*
*/
public class Bar3 {
private String prop;
private final String someTypeProp;
public Bar3( String someTypeProp ) {
public Bar3(String someTypeProp) {
this.someTypeProp = someTypeProp;
}

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.factories;
import java.util.List;
/**
*
* @author Sjaak Derksen
*/
public interface CustomList<T> extends List<T> {

View File

@ -21,14 +21,13 @@ package org.mapstruct.ap.test.factories;
import java.util.LinkedList;
/**
*
* @author Sjaak Derksen
*/
public class CustomListImpl<T> extends LinkedList<T> implements CustomList<T> {
private final String typeProp;
public CustomListImpl( String typeProp ) {
public CustomListImpl(String typeProp) {
this.typeProp = typeProp;
}

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.factories;
import java.util.Map;
/**
*
* @author Sjaak Derksen
*/
public interface CustomMap<K, V> extends Map<K, V> {

View File

@ -21,14 +21,13 @@ package org.mapstruct.ap.test.factories;
import java.util.HashMap;
/**
*
* @author Sjaak Derksen
*/
public class CustomMapImpl<K, V> extends HashMap<K, V> implements CustomMap<K, V> {
private final String typeProp;
public CustomMapImpl( String typeProp ) {
public CustomMapImpl(String typeProp) {
this.typeProp = typeProp;
}

View File

@ -22,22 +22,24 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mapstruct.ap.test.factories.a.BarFactory;
import static org.fest.assertions.Assertions.assertThat;
import org.mapstruct.ap.test.factories.a.BarFactory;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
/**
* @author Sjaak Derksen
*
*/
@IssueKey( "81" )
@WithClasses( { Bar1.class, Foo1.class, Bar2.class, Foo2.class, Bar3.class, Foo3.class, BarFactory.class,
@IssueKey("81")
@WithClasses({
Bar1.class, Foo1.class, Bar2.class, Foo2.class, Bar3.class, Foo3.class, BarFactory.class,
org.mapstruct.ap.test.factories.b.BarFactory.class, Source.class, SourceTargetMapperAndBar2Factory.class,
Target.class, CustomList.class, CustomListImpl.class, CustomMap.class, CustomMapImpl.class } )
Target.class, CustomList.class, CustomListImpl.class, CustomMap.class, CustomMapImpl.class
})
public class FactoryTest extends MapperTestBase {
@Test
public void shouldUseTwoFactoryMethods() {
@ -46,19 +48,19 @@ public class FactoryTest extends MapperTestBase {
assertThat( target ).isNotNull();
assertThat( target.getProp1() ).isNotNull();
assertThat( target.getProp1().getProp() ).isEqualTo( "foo1" );
assertThat( target.getProp1().getSomeTypeProp()).isEqualTo( "BAR1" );
assertThat( target.getProp1().getSomeTypeProp() ).isEqualTo( "BAR1" );
assertThat( target.getProp2() ).isNotNull();
assertThat( target.getProp2().getProp() ).isEqualTo( "foo2" );
assertThat( target.getProp2().getSomeTypeProp()).isEqualTo( "BAR2" );
assertThat( target.getProp2().getSomeTypeProp() ).isEqualTo( "BAR2" );
assertThat( target.getProp3() ).isNotNull();
assertThat( target.getProp3().getProp() ).isEqualTo( "foo3" );
assertThat( target.getProp3().getSomeTypeProp()).isEqualTo( "BAR3" );
assertThat( target.getProp3().getSomeTypeProp() ).isEqualTo( "BAR3" );
assertThat( target.getPropList() ).isNotNull();
assertThat( target.getPropList().get( 0 ) ).isEqualTo( "fooListEntry" );
assertThat( target.getPropList().getTypeProp()).isEqualTo( "CUSTOMLIST" );
assertThat( target.getPropList().getTypeProp() ).isEqualTo( "CUSTOMLIST" );
assertThat( target.getPropMap() ).isNotNull();
assertThat( target.getPropMap().get( "key" ) ).isEqualTo( "fooValue" );
assertThat( target.getPropMap().getTypeProp()).isEqualTo( "CUSTOMMAP" );
assertThat( target.getPropMap().getTypeProp() ).isEqualTo( "CUSTOMMAP" );
}
private Source createSource() {
@ -81,7 +83,7 @@ public class FactoryTest extends MapperTestBase {
source.setPropList( fooList );
Map<String, String> fooMap = new HashMap<String, String>();
fooMap.put( "key", "fooValue");
fooMap.put( "key", "fooValue" );
source.setPropMap( fooMap );
return source;
}

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.factories;
/**
* @author Sjaak Derksen
*
*/
public class Foo1 {
private String prop;

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.factories;
/**
* @author Sjaak Derksen
*
*/
public class Foo2 {
private String prop;

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.factories;
/**
* @author Sjaak Derksen
*
*/
public class Foo3 {
private String prop;

View File

@ -23,7 +23,6 @@ import java.util.Map;
/**
* @author Sjaak Derksen
*
*/
public class Source {
@ -37,7 +36,7 @@ public class Source {
return prop1;
}
public void setProp1( Foo1 prop1 ) {
public void setProp1(Foo1 prop1) {
this.prop1 = prop1;
}
@ -45,7 +44,7 @@ public class Source {
return prop2;
}
public void setProp2( Foo2 prop2 ) {
public void setProp2(Foo2 prop2) {
this.prop2 = prop2;
}
@ -53,7 +52,7 @@ public class Source {
return prop3;
}
public void setProp3( Foo3 prop3 ) {
public void setProp3(Foo3 prop3) {
this.prop3 = prop3;
}
@ -61,7 +60,7 @@ public class Source {
return propList;
}
public void setPropList( List<String> propList ) {
public void setPropList(List<String> propList) {
this.propList = propList;
}
@ -69,7 +68,7 @@ public class Source {
return propMap;
}
public void setPropMap( Map<String, String> propMap ) {
public void setPropMap(Map<String, String> propMap) {
this.propMap = propMap;
}

View File

@ -20,18 +20,18 @@ package org.mapstruct.ap.test.factories;
import java.util.List;
import java.util.Map;
import org.mapstruct.ap.test.factories.a.BarFactory;
import org.mapstruct.Mapper;
import org.mapstruct.ap.test.factories.a.BarFactory;
import org.mapstruct.factory.Mappers;
/**
* @author Sjaak Derksen
*
*/
@Mapper( uses = { BarFactory.class, org.mapstruct.ap.test.factories.b.BarFactory.class } )
@Mapper(uses = { BarFactory.class, org.mapstruct.ap.test.factories.b.BarFactory.class })
public abstract class SourceTargetMapperAndBar2Factory {
public static final SourceTargetMapperAndBar2Factory INSTANCE =
Mappers.getMapper( SourceTargetMapperAndBar2Factory.class );
Mappers.getMapper( SourceTargetMapperAndBar2Factory.class );
public abstract Target sourceToTarget(Source source);
@ -46,14 +46,14 @@ public abstract class SourceTargetMapperAndBar2Factory {
public abstract CustomMap<String, String> customMapToMap(Map<String, String> list);
public Bar2 createBar2() {
return new Bar2("BAR2");
return new Bar2( "BAR2" );
}
public CustomList<String> createCustomList() {
return new CustomListImpl<String>("CUSTOMLIST");
return new CustomListImpl<String>( "CUSTOMLIST" );
}
public CustomMap<String, String> createCustomMap() {
return new CustomMapImpl<String, String>("CUSTOMMAP");
return new CustomMapImpl<String, String>( "CUSTOMMAP" );
}
}

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.factories;
/**
* @author Sjaak Derksen
*
*/
public class Target {
@ -42,7 +41,7 @@ public class Target {
return prop2;
}
public void setProp2( Bar2 prop2 ) {
public void setProp2(Bar2 prop2) {
this.prop2 = prop2;
}
@ -50,7 +49,7 @@ public class Target {
return prop3;
}
public void setProp3( Bar3 prop3 ) {
public void setProp3(Bar3 prop3) {
this.prop3 = prop3;
}
@ -58,7 +57,7 @@ public class Target {
return propList;
}
public void setPropList( CustomList<String> propList ) {
public void setPropList(CustomList<String> propList) {
this.propList = propList;
}
@ -66,7 +65,7 @@ public class Target {
return propMap;
}
public void setPropMap( CustomMap<String, String> propMap ) {
public void setPropMap(CustomMap<String, String> propMap) {
this.propMap = propMap;
}

View File

@ -21,13 +21,12 @@ package org.mapstruct.ap.test.factories.a;
import org.mapstruct.ap.test.factories.Bar1;
/**
*
* @author Sjaak Derksen
*/
public class BarFactory {
public Bar1 createBar1() {
return new Bar1("BAR1");
return new Bar1( "BAR1" );
}
}

View File

@ -21,13 +21,12 @@ package org.mapstruct.ap.test.factories.b;
import org.mapstruct.ap.test.factories.Bar3;
/**
*
* @author Sjaak Derksen
*/
public class BarFactory {
public Bar3 createBar3() {
return new Bar3("BAR3");
return new Bar3( "BAR3" );
}
}