Issue #79 Adding generics solution for custom mappers

This commit is contained in:
sjaak 2013-12-31 13:17:29 +01:00 committed by Gunnar Morling
parent 260a685f65
commit b249c2ced1
33 changed files with 1769 additions and 5 deletions

View File

@ -61,6 +61,7 @@ import org.mapstruct.ap.model.source.Mapping;
import org.mapstruct.ap.model.source.Method;
import org.mapstruct.ap.util.Executables;
import org.mapstruct.ap.util.Filters;
import org.mapstruct.ap.util.MethodMatcher;
import org.mapstruct.ap.util.Strings;
import org.mapstruct.ap.util.TypeFactory;
@ -546,13 +547,11 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
continue;
}
Parameter singleSourceParam = method.getSourceParameters().iterator().next();
if ( singleSourceParam.getType().equals( parameterType ) && method.getResultType().equals( returnType ) ) {
return new MappingMethodReference( method );
MethodMatcher m = new MethodMatcher(typeUtils, method, returnType, parameterType);
if (m.matches()) {
return new MappingMethodReference(method);
}
}
return null;
}

View File

@ -0,0 +1,326 @@
/**
* Copyright 2012-2013 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.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.ErrorType;
import javax.lang.model.type.ExecutableType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.NullType;
import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import static javax.lang.model.type.TypeKind.DECLARED;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.WildcardType;
import javax.lang.model.util.AbstractTypeVisitor6;
import javax.lang.model.util.Types;
import org.mapstruct.ap.model.Type;
import org.mapstruct.ap.model.source.Method;
/**
* MethodMatcher
*
* $8.4 of the JavaLanguage specification describes a method body as such:
*
* MethodDeclaration:
* MethodHeader MethodBody
*
* MethodHeader:
* MethodModifiers TypeParameters Result MethodDeclarator Throws
*
* MethodDeclarator:
* Identifier ( FormalParameterList )
*
* example <T extends String & Serializable> T getResult(? extends T) throws Exception
* \-------------------------------/ \-/ \---------/
* TypeParameters Result ParameterList
*
* Matches a given method with given ParameterList and Result type obeying the
* constraints in the TypeParameters block.
*
* For more info on java-generics:
* http://www.javacodegeeks.com/2011/04/java-generics-quick-tutorial.html
* http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html
*
* The following situations is not supported / tested:
* 1) Multiple bounds were the bound itself is again a generic type.
*
* @author Sjaak Derksen
*/
public class MethodMatcher {
private final Type[] parameters;
private final Type returnType;
private final Method candidateMethod;
private final Types typeUtils;
private boolean typesMatch = true;
private Map<TypeVariable, TypeMirror> genericTypesMap = new HashMap<TypeVariable, TypeMirror>();
public MethodMatcher(Types typeUtils, Method candidateMethod, Type returnType, Type... arguments) {
this.typeUtils = typeUtils;
this.candidateMethod = candidateMethod;
this.parameters = arguments;
this.returnType = returnType;
}
public boolean matches() {
// check & collect generic types.
List<? extends VariableElement> candidateParameters = candidateMethod.getExecutable().getParameters();
if ( candidateParameters.size() == parameters.length ) {
for ( int i = 0; i < parameters.length; i++ ) {
TypeMatcher parameterMatcher = new TypeMatcher();
parameterMatcher.visit( candidateParameters.get( i ).asType(), parameters[i].getTypeMirror() );
if ( !typesMatch ) {
break;
}
}
}
else {
typesMatch = false;
}
// check return type
if ( typesMatch ) {
TypeMirror candidateReturnType = candidateMethod.getExecutable().getReturnType();
TypeMatcher returnTypeMatcher = new TypeMatcher();
returnTypeMatcher.visit( candidateReturnType, returnType.getTypeMirror() );
}
// check if all type parameters are indeed mapped
if ( candidateMethod.getExecutable().getTypeParameters().size() != this.genericTypesMap.size() ) {
typesMatch = false;
}
else {
// check if all entries are in the bounds
for (Map.Entry<TypeVariable, TypeMirror> entry : genericTypesMap.entrySet()) {
if (!isWithinBounds( entry.getValue(), getTypeParamFromCandite( entry.getKey() ) ) ) {
// checks if the found Type is in bounds of the TypeParameters bounds.
typesMatch = false;
}
}
}
return typesMatch;
}
public class TypeMatcher extends AbstractTypeVisitor6<TypeMirror, TypeMirror> {
@Override
public TypeMirror visitPrimitive(PrimitiveType t, TypeMirror p) {
if ( !typeUtils.isSameType( t, p ) ) {
typesMatch = false;
}
return null;
}
@Override
public TypeMirror visitNull(NullType t, TypeMirror p) {
// not interesting
return null;
}
@Override
public TypeMirror visitArray(ArrayType t, TypeMirror p) {
if ( p instanceof ArrayType ) {
t.getComponentType().accept( this, ( (ArrayType) p ).getComponentType() );
}
else {
typesMatch = false;
}
return null;
}
@Override
public TypeMirror visitDeclared(DeclaredType t, TypeMirror p) {
// its a match when: 1) same kind of type, name is equals, nr of type args are the same
// (type args are checked later).
if ( p instanceof DeclaredType ) {
DeclaredType t1 = (DeclaredType) p;
if ( t.asElement().getSimpleName().equals( t1.asElement().getSimpleName() )
&& t.getTypeArguments().size() == t1.getTypeArguments().size() ) {
for ( int i = 0; i < t.getTypeArguments().size(); i++ ) {
t.getTypeArguments().get( i ).accept( this, t1.getTypeArguments().get( i ) );
}
}
else {
typesMatch = false;
}
}
else {
typesMatch = false;
}
return null;
}
@Override
public TypeMirror visitError(ErrorType t, TypeMirror p) {
// not interesting
return null;
}
@Override
public TypeMirror visitTypeVariable(TypeVariable t, TypeMirror p) {
if ( genericTypesMap.containsKey( t ) ) {
// when already found, the same mapping should apply
TypeMirror p1 = genericTypesMap.get( t );
if ( !typeUtils.isSameType( p, p1 ) ) {
typesMatch = false;
}
}
else {
// check if types are in bound
if ( typeUtils.isSubtype( t.getLowerBound(), p ) && typeUtils.isSubtype( p, t.getUpperBound() ) ) {
genericTypesMap.put( t, p );
}
else {
typesMatch = false;
}
}
return null;
}
@Override
public TypeMirror visitWildcard(WildcardType t, TypeMirror p) {
// check extends bound
TypeMirror extendsBound = t.getExtendsBound();
if ( extendsBound != null ) {
switch ( extendsBound.getKind() ) {
case DECLARED:
// for example method: String method(? extends String)
if ( !typeUtils.isSubtype( p, extendsBound ) ) {
// isSubType checks range [subtype, type], e.g. isSubtype [Object, String]==true
typesMatch = false;
}
break;
case TYPEVAR:
// for exampe method: <T extends String & Serializable> T method(? extends T)
// this can be done the directly by checking: ? extends String & Serializable
if ( !isWithinBounds( p, getTypeParamFromCandite( extendsBound ) ) ) {
// this checks the part? <T extends String & Serializable>
typesMatch = false;
}
break;
default:
// does this situation occur?
typesMatch = false;
}
}
// check super bound
TypeMirror superBound = t.getSuperBound();
if ( superBound != null ) {
switch ( superBound.getKind() ) {
case DECLARED:
// for example method: String method(? super String)
if ( !( typeUtils.isSubtype( superBound, p ) || typeUtils.isSameType( p, superBound ) ) ) {
// to check super type, we can simply reverse the argument, but that would initially yield
// a result: <type, superType] (so type not included) so we need to check sameType also.
typesMatch = false;
}
break;
case TYPEVAR:
TypeParameterElement typeParameter = getTypeParamFromCandite( superBound );
// for exampe method: <T extends String & Serializable> T method(? super T)
if ( !isWithinBounds( p, typeParameter ) ) {
// this checks the part? <T extends String & Serializable>
typesMatch = false;
}
// now, it becoms a bit more hairy. We have the relation (? super T). From T we know that
// it is a subclass of String & Serializable. However, The Java Language Secification,
// Chapter 4.4, states that a bound is either: 'A type variable-', 'A class-' or 'An
// interface-' type followed by further interface types. So we must compare with the first
// argument in the Expression String & Serializable & ..., so, in this case String.
TypeMirror superBoundAsDeclared = typeParameter.getBounds().get( 0 );
if ( !( typeUtils.isSubtype( superBoundAsDeclared, p ) ||
typeUtils.isSameType( p, superBoundAsDeclared ) ) ) {
// to check super type, we can simply reverse the argument, but that would initially yield
// a result: <type, superType] (so type not included) so we need to check sameType also.
typesMatch = false;
}
break;
default:
// does this situation occur?
typesMatch = false;
}
}
return null;
}
@Override
public TypeMirror visitExecutable(ExecutableType t, TypeMirror p) {
// not interesting
return null;
}
@Override
public TypeMirror visitNoType(NoType t, TypeMirror p) {
// not interesting
return null;
}
}
/**
* Looks through the list of type parameters of the candidate method for a match
*
* @param t type parameter to match
* @return matching type parameter
*/
private TypeParameterElement getTypeParamFromCandite(TypeMirror t) {
for ( TypeParameterElement candidateTypeParam : candidateMethod.getExecutable().getTypeParameters() ) {
if ( candidateTypeParam.asType().equals( t ) ) {
return candidateTypeParam;
}
}
return null;
}
/**
* checks whether a type t is in bounds of the typeParameter tpe
*
* @param t
* @param tpe
* @return true if within bounds
*/
private boolean isWithinBounds(TypeMirror t, TypeParameterElement tpe) {
List<? extends TypeMirror> bounds = tpe.getBounds();
if ( t != null && bounds != null ) {
for ( TypeMirror bound : bounds ) {
if ( !( bound.getKind().equals( TypeKind.DECLARED ) &&
typeUtils.isSubtype( t, (DeclaredType) bound ) ) ) {
return false;
}
}
return true;
}
return false;
}
}

View File

@ -0,0 +1,39 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ArrayWrapper<T> {
public ArrayWrapper() {
}
public ArrayWrapper(T[] wrapped) {
this.wrapped = wrapped;
}
private T[] wrapped;
public T[] getWrapped() {
return wrapped;
}
public void setWrapped(T[] wrapped) {
this.wrapped = wrapped;
}
}

View File

@ -0,0 +1,179 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import java.math.BigDecimal;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
public class ConversionTest extends MapperTestBase {
@Test
@WithClasses( { ErroneousSource1.class, ErroneousTarget1.class, ErroneousSource2.class, ErroneousTarget2.class,
ErroneousSource3.class, ErroneousTarget3.class, ErroneousSource4.class, ErroneousTarget4.class,
ErroneousSource5.class, ErroneousTarget5.class,
GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
TypeA.class, TypeB.class, TypeC.class, UpperBoundWrapper.class, Source.class, Target.class,
WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
SourceTargetMapper.class } )
public void shouldApplyGenericTypeMapper() {
// setup used types
TypeB typeB = new TypeB();
TypeC typeC = new TypeC();
// setup source
Source source = new Source();
source.setFooInteger( new Wrapper<Integer>( 5 ) );
source.setFooString( new Wrapper<String>( "test" ) );
source.setFooStringArray( new Wrapper<String[]>( new String[] { "test1", "test2" } ) );
source.setFooLongArray( new ArrayWrapper<Long>( new Long[] { 5L, 3L } ) );
source.setFooTwoArgs( new TwoArgWrapper<Integer, Boolean>( new TwoArgHolder<Integer, Boolean>( 3, true ) ) );
source.setFooNested( new Wrapper<Wrapper<BigDecimal>>( new Wrapper<BigDecimal>( new BigDecimal( 5 ) ) ) );
source.setFooUpperBoundCorrect( new UpperBoundWrapper<TypeB>( typeB ) );
source.setFooWildCardExtendsString( new WildCardExtendsWrapper<String>( "test3" ) );
source.setFooWildCardExtendsTypeCCorrect( new WildCardExtendsWrapper<TypeC>( typeC ) );
source.setFooWildCardExtendsTypeBCorrect( new WildCardExtendsWrapper<TypeB>( typeB ) );
source.setFooWildCardSuperString( new WildCardSuperWrapper<String>( "test4" ) );
source.setFooWildCardExtendsMBTypeCCorrect( new WildCardExtendsMBWrapper<TypeC>( typeC ) );
source.setFooWildCardSuperTypeBCorrect( new WildCardSuperWrapper<TypeB>( typeB ) );
// define wrapper
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
// assert results
assertThat( target ).isNotNull();
assertThat( target.getFooInteger() ).isEqualTo( 5 );
assertThat( target.getFooString() ).isEqualTo( "test" );
assertThat( target.getFooStringArray() ).isEqualTo( new String[] { "test1", "test2" } );
assertThat( target.getFooLongArray() ).isEqualTo( new Long[] { 5L, 3L } );
assertThat( target.getFooTwoArgs().getArg1() ).isEqualTo( 3 );
assertThat( target.getFooTwoArgs().getArg2() ).isEqualTo( true );
assertThat( target.getFooNested() ).isEqualTo( new BigDecimal( 5 ) );
assertThat( target.getFooUpperBoundCorrect() ).isEqualTo( typeB );
assertThat( target.getFooWildCardExtendsString() ).isEqualTo( "test3" );
assertThat( target.getFooWildCardExtendsTypeCCorrect() ).isEqualTo( typeC );
assertThat( target.getFooWildCardExtendsTypeBCorrect() ).isEqualTo( typeB );
assertThat( target.getFooWildCardSuperString() ).isEqualTo( "test4" );
assertThat( target.getFooWildCardExtendsMBTypeCCorrect() ).isEqualTo( typeC );
assertThat( target.getFooWildCardSuperTypeBCorrect() ).isEqualTo( typeB );
}
@Test
@WithClasses({ErroneousSource1.class, ErroneousTarget1.class, ErroneousSource2.class, ErroneousTarget2.class,
ErroneousSource3.class, ErroneousTarget3.class, ErroneousSource4.class, ErroneousTarget4.class,
ErroneousSource5.class, ErroneousTarget5.class,
GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
TypeA.class, TypeB.class, TypeC.class, UpperBoundWrapper.class, Source.class, Target.class,
WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
ErroneousSourceTargetMapper1.class } )
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper1.class,
kind = javax.tools.Diagnostic.Kind.ERROR, line = 29,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.UpperBoundWrapper"
+ "<org.mapstruct.ap.test.conversion.generics.TypeA> fooUpperBoundFailure\" to "
+ "\"org.mapstruct.ap.test.conversion.generics.TypeA fooUpperBoundFailure\"") } )
public void shouldFailOnUpperBound() {
}
@Test
@WithClasses({ErroneousSource1.class, ErroneousTarget1.class, ErroneousSource2.class, ErroneousTarget2.class,
ErroneousSource3.class, ErroneousTarget3.class, ErroneousSource4.class, ErroneousTarget4.class,
ErroneousSource5.class, ErroneousTarget5.class,
GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
TypeA.class, TypeB.class, TypeC.class, UpperBoundWrapper.class, Source.class, Target.class,
WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
ErroneousSourceTargetMapper2.class } )
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper2.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 29,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.WildCardExtendsWrapper"
+ "<org.mapstruct.ap.test.conversion.generics.TypeA> fooWildCardExtendsTypeAFailure\" to"
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardExtendsTypeAFailure\"" ) } )
public void shouldFailOnWildCardBound() {
}
@Test
@WithClasses({ErroneousSource1.class, ErroneousTarget1.class, ErroneousSource2.class, ErroneousTarget2.class,
ErroneousSource3.class, ErroneousTarget3.class, ErroneousSource4.class, ErroneousTarget4.class,
ErroneousSource5.class, ErroneousTarget5.class,
GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
TypeA.class, TypeB.class, TypeC.class, UpperBoundWrapper.class, Source.class, Target.class,
WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
ErroneousSourceTargetMapper3.class } )
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper3.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 29,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics."
+ "WildCardExtendsMBWrapper<org.mapstruct.ap.test.conversion.generics.TypeB> "
+ "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.conversion.generics.TypeB "
+ "fooWildCardExtendsMBTypeBFailure\"" ) } )
public void shouldFailOnWildCardMultipleBounds() {
}
@Test
@WithClasses({ErroneousSource1.class, ErroneousTarget1.class, ErroneousSource2.class, ErroneousTarget2.class,
ErroneousSource3.class, ErroneousTarget3.class, ErroneousSource4.class, ErroneousTarget4.class,
ErroneousSource5.class, ErroneousTarget5.class,
GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
TypeA.class, TypeB.class, TypeC.class, UpperBoundWrapper.class, Source.class, Target.class,
WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
ErroneousSourceTargetMapper4.class } )
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper4.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 29,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.WildCardSuperWrapper"
+ "<org.mapstruct.ap.test.conversion.generics.TypeA> fooWildCardSuperTypeAFailure\" to"
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardSuperTypeAFailure\"" ) } )
public void shouldFailOnSuperBounds1() {
}
@Test
@WithClasses({ErroneousSource1.class, ErroneousTarget1.class, ErroneousSource2.class, ErroneousTarget2.class,
ErroneousSource3.class, ErroneousTarget3.class, ErroneousSource4.class, ErroneousTarget4.class,
ErroneousSource5.class, ErroneousTarget5.class,
GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
TypeA.class, TypeB.class, TypeC.class, UpperBoundWrapper.class, Source.class, Target.class,
WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
ErroneousSourceTargetMapper5.class } )
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = ErroneousSourceTargetMapper5.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 29,
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.WildCardSuperWrapper"
+ "<org.mapstruct.ap.test.conversion.generics.TypeC> fooWildCardSuperTypeCFailure\" to"
+ " \"org.mapstruct.ap.test.conversion.generics.TypeC fooWildCardSuperTypeCFailure\"" ) } )
public void shouldFailOnSuperBounds2() {
}
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousSource1 {
private UpperBoundWrapper<TypeA> fooUpperBoundFailure;
public UpperBoundWrapper<TypeA> getFooUpperBoundFailure() {
return fooUpperBoundFailure;
}
public void setFooUpperBoundFailure(UpperBoundWrapper<TypeA> fooUpperBoundFailure) {
this.fooUpperBoundFailure = fooUpperBoundFailure;
}
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousSource2 {
private WildCardExtendsWrapper<TypeA> fooWildCardExtendsTypeAFailure;
public WildCardExtendsWrapper<TypeA> getFooWildCardExtendsTypeAFailure() {
return fooWildCardExtendsTypeAFailure;
}
public void setFooWildCardExtendsTypeAFailure(WildCardExtendsWrapper<TypeA> fooWildCardExtendsTypeAFailure) {
this.fooWildCardExtendsTypeAFailure = fooWildCardExtendsTypeAFailure;
}
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousSource3 {
private WildCardExtendsMBWrapper<TypeB> fooWildCardExtendsMBTypeBFailure;
public WildCardExtendsMBWrapper<TypeB> getFooWildCardExtendsMBTypeBFailure() {
return fooWildCardExtendsMBTypeBFailure;
}
public void setFooWildCardExtendsMBTypeBFailure(WildCardExtendsMBWrapper<TypeB> fooWildCardExtendsMBTypeBFailure) {
this.fooWildCardExtendsMBTypeBFailure = fooWildCardExtendsMBTypeBFailure;
}
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousSource4 {
private WildCardSuperWrapper<TypeA> fooWildCardSuperTypeAFailure;
public WildCardSuperWrapper<TypeA> getFooWildCardSuperTypeAFailure() {
return fooWildCardSuperTypeAFailure;
}
public void setFooWildCardSuperTypeAFailure(WildCardSuperWrapper<TypeA> fooWildCardSuperTypeAFailure) {
this.fooWildCardSuperTypeAFailure = fooWildCardSuperTypeAFailure;
}
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousSource5 {
private WildCardSuperWrapper<TypeC> fooWildCardSuperTypeCFailure;
public WildCardSuperWrapper<TypeC> getFooWildCardSuperTypeCFailure() {
return fooWildCardSuperTypeCFailure;
}
public void setFooWildCardSuperTypeCFailure(WildCardSuperWrapper<TypeC> fooWildCardSuperTypeCFailure) {
this.fooWildCardSuperTypeCFailure = fooWildCardSuperTypeCFailure;
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = GenericTypeMapper.class )
public interface ErroneousSourceTargetMapper1 {
ErroneousSourceTargetMapper1 INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper1.class );
ErroneousTarget1 sourceToTarget(ErroneousSource1 source);
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = GenericTypeMapper.class )
public interface ErroneousSourceTargetMapper2 {
ErroneousSourceTargetMapper2 INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper2.class );
ErroneousTarget2 sourceToTarget(ErroneousSource2 source);
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = GenericTypeMapper.class )
public interface ErroneousSourceTargetMapper3 {
ErroneousSourceTargetMapper3 INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper3.class );
ErroneousTarget3 sourceToTarget(ErroneousSource3 source);
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = GenericTypeMapper.class )
public interface ErroneousSourceTargetMapper4 {
ErroneousSourceTargetMapper4 INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper4.class );
ErroneousTarget4 sourceToTarget(ErroneousSource4 source);
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = GenericTypeMapper.class )
public interface ErroneousSourceTargetMapper5 {
ErroneousSourceTargetMapper5 INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper5.class );
ErroneousTarget5 sourceToTarget(ErroneousSource5 source);
}

View File

@ -0,0 +1,32 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousTarget1 {
private TypeA fooUpperBoundFailure;
public TypeA getFooUpperBoundFailure() {
return fooUpperBoundFailure;
}
public void setFooUpperBoundFailure(TypeA fooUpperBoundFailure) {
this.fooUpperBoundFailure = fooUpperBoundFailure;
}
}

View File

@ -0,0 +1,33 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousTarget2 {
private TypeA fooWildCardExtendsTypeAFailure;
public TypeA getFooWildCardExtendsTypeAFailure() {
return fooWildCardExtendsTypeAFailure;
}
public void setFooWildCardExtendsTypeAFailure(TypeA fooWildCardExtendsTypeAFailure) {
this.fooWildCardExtendsTypeAFailure = fooWildCardExtendsTypeAFailure;
}
}

View File

@ -0,0 +1,33 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousTarget3 {
private TypeB fooWildCardExtendsMBTypeBFailure;
public TypeB getFooWildCardExtendsMBTypeBFailure() {
return fooWildCardExtendsMBTypeBFailure;
}
public void setFooWildCardExtendsMBTypeBFailure(TypeB fooWildCardExtendsMBTypeBFailure) {
this.fooWildCardExtendsMBTypeBFailure = fooWildCardExtendsMBTypeBFailure;
}
}

View File

@ -0,0 +1,33 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousTarget4 {
private TypeA fooWildCardSuperTypeAFailure;
public TypeA getFooWildCardSuperTypeAFailure() {
return fooWildCardSuperTypeAFailure;
}
public void setFooWildCardSuperTypeAFailure(TypeA fooWildCardSuperTypeAFailure) {
this.fooWildCardSuperTypeAFailure = fooWildCardSuperTypeAFailure;
}
}

View File

@ -0,0 +1,33 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class ErroneousTarget5 {
private TypeC fooWildCardSuperTypeCFailure;
public TypeC getFooWildCardSuperTypeCFailure() {
return fooWildCardSuperTypeCFailure;
}
public void setFooWildCardSuperTypeCFailure(TypeC fooWildCardSuperTypeCFailure) {
this.fooWildCardSuperTypeCFailure = fooWildCardSuperTypeCFailure;
}
}

View File

@ -0,0 +1,72 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import java.io.Serializable;
public class GenericTypeMapper {
public <T> T getWrapped(Wrapper<T> source) {
return source.getWrapped();
}
public <T> T[] getArrayWrapped(ArrayWrapper<T> t) {
return t.getWrapped();
}
public <T1, T2> TwoArgHolder<T1, T2> getTwoArgWrapped(TwoArgWrapper<T1, T2> t) {
return t.getWrapped();
}
public <T> T getNestedWrapped(Wrapper<Wrapper<T>> t) {
return t.getWrapped().getWrapped();
}
public <T extends TypeB> T getUpperBounded(UpperBoundWrapper<T> t) {
return t.getWrapped();
}
// TODO Lower bound test? The javadoc states: Returns the lower bound of this type variable.
// While a type parameter cannot include an explicit lower bound declaration, capture conversion can produce
// a type variable with a non-trivial lower bound. Type variables otherwise have a lower bound of NullType.
public String getWildCardExtendsString(WildCardExtendsWrapper<? extends String> t) {
return t.getWrapped();
}
public <T extends TypeB> T getWildCardExtendsType(WildCardExtendsWrapper<? extends T> t) {
return t.getWrapped();
}
/**
* TODO.. My own IDE compiler actually allows all TypeA, TypeB, TypeC. However, I assume
* that only TypeB is allowed here. This is what the code actually enforces.
*/
public <T extends TypeB> T getWildCardSuperType(WildCardSuperWrapper<? super T> t) {
return (T) t.getWrapped();
}
public String getWildCardSupersString(WildCardSuperWrapper<? super String> t) {
return (String) t.getWrapped();
}
public <T extends TypeB & Serializable> T getWildCardExtendsMBType(WildCardExtendsMBWrapper<? extends T> t) {
return t.getWrapped();
}
}

View File

@ -0,0 +1,142 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import java.math.BigDecimal;
public class Source {
private Wrapper<Integer> fooInteger;
private Wrapper<String> fooString;
private Wrapper<String[]> fooStringArray;
private ArrayWrapper<Long> fooLongArray;
private TwoArgWrapper<Integer, Boolean> fooTwoArgs;
private Wrapper<Wrapper<BigDecimal>> fooNested;
private UpperBoundWrapper<TypeB> fooUpperBoundCorrect;
private WildCardExtendsWrapper<String> fooWildCardExtendsString;
private WildCardExtendsWrapper<TypeC> fooWildCardExtendsTypeCCorrect;
private WildCardExtendsWrapper<TypeB> fooWildCardExtendsTypeBCorrect;
private WildCardSuperWrapper<String> fooWildCardSuperString;
private WildCardExtendsMBWrapper<TypeC> fooWildCardExtendsMBTypeCCorrect;
private WildCardSuperWrapper<TypeB> fooWildCardSuperTypeBCorrect;
public Wrapper<Integer> getFooInteger() {
return fooInteger;
}
public void setFooInteger(Wrapper<Integer> fooInteger) {
this.fooInteger = fooInteger;
}
public Wrapper<String> getFooString() {
return fooString;
}
public void setFooString(Wrapper<String> fooString) {
this.fooString = fooString;
}
public Wrapper<String[]> getFooStringArray() {
return fooStringArray;
}
public void setFooStringArray(Wrapper<String[]> fooStringArray) {
this.fooStringArray = fooStringArray;
}
public ArrayWrapper<Long> getFooLongArray() {
return fooLongArray;
}
public void setFooLongArray(ArrayWrapper<Long> fooLongArray) {
this.fooLongArray = fooLongArray;
}
public TwoArgWrapper<Integer, Boolean> getFooTwoArgs() {
return fooTwoArgs;
}
public void setFooTwoArgs(TwoArgWrapper<Integer, Boolean> fooTwoArgs) {
this.fooTwoArgs = fooTwoArgs;
}
public Wrapper<Wrapper<BigDecimal>> getFooNested() {
return fooNested;
}
public void setFooNested(Wrapper<Wrapper<BigDecimal>> fooNested) {
this.fooNested = fooNested;
}
public UpperBoundWrapper<TypeB> getFooUpperBoundCorrect() {
return fooUpperBoundCorrect;
}
public void setFooUpperBoundCorrect(UpperBoundWrapper<TypeB> fooUpperBoundCorrect) {
this.fooUpperBoundCorrect = fooUpperBoundCorrect;
}
public WildCardExtendsWrapper<String> getFooWildCardExtendsString() {
return fooWildCardExtendsString;
}
public void setFooWildCardExtendsString(WildCardExtendsWrapper<String> fooWildCardExtendsString) {
this.fooWildCardExtendsString = fooWildCardExtendsString;
}
public void setFooWildCardExtendsTypeCCorrect(WildCardExtendsWrapper<TypeC> fooWildCardExtendsTypeCCorrect) {
this.fooWildCardExtendsTypeCCorrect = fooWildCardExtendsTypeCCorrect;
}
public WildCardExtendsWrapper<TypeC> getFooWildCardExtendsTypeCCorrect() {
return fooWildCardExtendsTypeCCorrect;
}
public WildCardExtendsWrapper<TypeB> getFooWildCardExtendsTypeBCorrect() {
return fooWildCardExtendsTypeBCorrect;
}
public void setFooWildCardExtendsTypeBCorrect(WildCardExtendsWrapper<TypeB> fooWildCardExtendsTypeBCorrect) {
this.fooWildCardExtendsTypeBCorrect = fooWildCardExtendsTypeBCorrect;
}
public WildCardSuperWrapper<String> getFooWildCardSuperString() {
return fooWildCardSuperString;
}
public void setFooWildCardSuperString(WildCardSuperWrapper<String> fooWildCardSuperString) {
this.fooWildCardSuperString = fooWildCardSuperString;
}
public WildCardExtendsMBWrapper<TypeC> getFooWildCardExtendsMBTypeCCorrect() {
return fooWildCardExtendsMBTypeCCorrect;
}
public void setFooWildCardExtendsMBTypeCCorrect(WildCardExtendsMBWrapper<TypeC> fooWildCardExtendsMBTypeCCorrect) {
this.fooWildCardExtendsMBTypeCCorrect = fooWildCardExtendsMBTypeCCorrect;
}
public WildCardSuperWrapper<TypeB> getFooWildCardSuperTypeBCorrect() {
return fooWildCardSuperTypeBCorrect;
}
public void setFooWildCardSuperTypeBCorrect(WildCardSuperWrapper<TypeB> fooWildCardSuperTypeBCorrect) {
this.fooWildCardSuperTypeBCorrect = fooWildCardSuperTypeBCorrect;
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper( uses = GenericTypeMapper.class )
public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
Target sourceToTarget(Source source);
}

View File

@ -0,0 +1,142 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import java.math.BigDecimal;
public class Target {
private Integer fooInteger;
private String fooString;
private String[] fooStringArray;
private Long[] fooLongArray;
private TwoArgHolder<Integer, Boolean> fooTwoArgs;
private BigDecimal fooNested;
private TypeB fooUpperBoundCorrect;
private String fooWildCardExtendsString;
private TypeC fooWildCardExtendsTypeCCorrect;
private TypeB fooWildCardExtendsTypeBCorrect;
private String fooWildCardSuperString;
private TypeC fooWildCardExtendsMBTypeCCorrect;
private TypeB fooWildCardSuperTypeBCorrect;
public Integer getFooInteger() {
return fooInteger;
}
public void setFooInteger(Integer fooInteger) {
this.fooInteger = fooInteger;
}
public String getFooString() {
return fooString;
}
public void setFooString(String fooString) {
this.fooString = fooString;
}
public String[] getFooStringArray() {
return fooStringArray;
}
public void setFooStringArray(String[] fooStringArray) {
this.fooStringArray = fooStringArray;
}
public Long[] getFooLongArray() {
return fooLongArray;
}
public void setFooLongArray(Long[] fooLongArray) {
this.fooLongArray = fooLongArray;
}
public TwoArgHolder<Integer, Boolean> getFooTwoArgs() {
return fooTwoArgs;
}
public void setFooTwoArgs(TwoArgHolder<Integer, Boolean> fooTwoArgs) {
this.fooTwoArgs = fooTwoArgs;
}
public BigDecimal getFooNested() {
return fooNested;
}
public void setFooNested(BigDecimal fooNested) {
this.fooNested = fooNested;
}
public TypeB getFooUpperBoundCorrect() {
return fooUpperBoundCorrect;
}
public void setFooUpperBoundCorrect(TypeB fooUpperBoundCorrect) {
this.fooUpperBoundCorrect = fooUpperBoundCorrect;
}
public String getFooWildCardExtendsString() {
return fooWildCardExtendsString;
}
public void setFooWildCardExtendsString(String fooWildCardExtendsString) {
this.fooWildCardExtendsString = fooWildCardExtendsString;
}
public TypeC getFooWildCardExtendsTypeCCorrect() {
return fooWildCardExtendsTypeCCorrect;
}
public void setFooWildCardExtendsTypeCCorrect(TypeC fooWildCardExtendsTypeCCorrect) {
this.fooWildCardExtendsTypeCCorrect = fooWildCardExtendsTypeCCorrect;
}
public TypeB getFooWildCardExtendsTypeBCorrect() {
return fooWildCardExtendsTypeBCorrect;
}
public void setFooWildCardExtendsTypeBCorrect(TypeB fooWildCardExtendsTypeBCorrect) {
this.fooWildCardExtendsTypeBCorrect = fooWildCardExtendsTypeBCorrect;
}
public String getFooWildCardSuperString() {
return fooWildCardSuperString;
}
public void setFooWildCardSuperString(String fooWildCardSuperString) {
this.fooWildCardSuperString = fooWildCardSuperString;
}
public TypeC getFooWildCardExtendsMBTypeCCorrect() {
return fooWildCardExtendsMBTypeCCorrect;
}
public void setFooWildCardExtendsMBTypeCCorrect(TypeC fooWildCardExtendsMBTypeCCorrect) {
this.fooWildCardExtendsMBTypeCCorrect = fooWildCardExtendsMBTypeCCorrect;
}
public TypeB getFooWildCardSuperTypeBCorrect() {
return fooWildCardSuperTypeBCorrect;
}
public void setFooWildCardSuperTypeBCorrect(TypeB fooWildCardSuperTypeBCorrect) {
this.fooWildCardSuperTypeBCorrect = fooWildCardSuperTypeBCorrect;
}
}

View File

@ -0,0 +1,49 @@
/**
* Copyright 2012-2013 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.conversion.generics;
/**
* @author sjaak
*/
public class TwoArgHolder<T1, T2> {
private T1 arg1;
private T2 arg2;
public TwoArgHolder(T1 arg1, T2 arg2) {
this.arg1 = arg1;
this.arg2 = arg2;
}
public T1 getArg1() {
return arg1;
}
public void setArg1(T1 arg1) {
this.arg1 = arg1;
}
public T2 getArg2() {
return arg2;
}
public void setArg2(T2 arg2) {
this.arg2 = arg2;
}
}

View File

@ -0,0 +1,39 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class TwoArgWrapper<T1, T2> {
public TwoArgWrapper() {
}
public TwoArgWrapper(TwoArgHolder<T1, T2> wrapped) {
this.wrapped = wrapped;
}
private TwoArgHolder<T1, T2> wrapped;
public TwoArgHolder<T1, T2> getWrapped() {
return wrapped;
}
public void setWrapped(TwoArgHolder<T1, T2> wrapped) {
this.wrapped = wrapped;
}
}

View File

@ -0,0 +1,25 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class TypeA {
public TypeA() {
}
}

View File

@ -0,0 +1,25 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class TypeB extends TypeA {
public TypeB() {
}
}

View File

@ -0,0 +1,27 @@
/**
* Copyright 2012-2013 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.conversion.generics;
import java.io.Serializable;
public class TypeC extends TypeB implements Serializable {
public TypeC() {
}
}

View File

@ -0,0 +1,39 @@
/**
* Copyright 2012-2013 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.conversion.generics;
/**
* @author sjaak
*/
public class UpperBoundWrapper<T> {
private T wrapped;
public UpperBoundWrapper(T wrapped) {
this.wrapped = wrapped;
}
public T getWrapped() {
return wrapped;
}
public void setWrapped(T wrapped) {
this.wrapped = wrapped;
}
}

View File

@ -0,0 +1,40 @@
/**
* Copyright 2012-2013 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.conversion.generics;
/**
* Testing Multiple Bounds
* @author sjaak
*/
public class WildCardExtendsMBWrapper<T> {
private T wrapped;
public WildCardExtendsMBWrapper(T wrapped) {
this.wrapped = wrapped;
}
public T getWrapped() {
return wrapped;
}
public void setWrapped(T wrapped) {
this.wrapped = wrapped;
}
}

View File

@ -0,0 +1,39 @@
/**
* Copyright 2012-2013 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.conversion.generics;
/**
* @author sjaak
*/
public class WildCardExtendsWrapper<T> {
private T wrapped;
public WildCardExtendsWrapper(T wrapped) {
this.wrapped = wrapped;
}
public T getWrapped() {
return wrapped;
}
public void setWrapped(T wrapped) {
this.wrapped = wrapped;
}
}

View File

@ -0,0 +1,39 @@
/**
* Copyright 2012-2013 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.conversion.generics;
/**
* @author sjaak
*/
public class WildCardSuperWrapper<T> {
private T wrapped;
public WildCardSuperWrapper(T wrapped) {
this.wrapped = wrapped;
}
public T getWrapped() {
return wrapped;
}
public void setWrapped(T wrapped) {
this.wrapped = wrapped;
}
}

View File

@ -0,0 +1,39 @@
/**
* Copyright 2012-2013 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.conversion.generics;
public class Wrapper<T> {
public Wrapper() {
}
public Wrapper(T wrapped) {
this.wrapped = wrapped;
}
private T wrapped;
public T getWrapped() {
return wrapped;
}
public void setWrapped(T wrapped) {
this.wrapped = wrapped;
}
}