mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#79 Formatting
This commit is contained in:
parent
623acb6f10
commit
e325862448
@ -547,9 +547,9 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodMatcher m = new MethodMatcher(typeUtils, method, returnType, parameterType);
|
MethodMatcher m = new MethodMatcher( typeUtils, method, returnType, parameterType );
|
||||||
if (m.matches()) {
|
if ( m.matches() ) {
|
||||||
return new MappingMethodReference(method);
|
return new MappingMethodReference( method );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -21,7 +21,6 @@ package org.mapstruct.ap.util;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.lang.model.element.TypeParameterElement;
|
import javax.lang.model.element.TypeParameterElement;
|
||||||
import javax.lang.model.element.VariableElement;
|
import javax.lang.model.element.VariableElement;
|
||||||
import javax.lang.model.type.ArrayType;
|
import javax.lang.model.type.ArrayType;
|
||||||
@ -111,8 +110,8 @@ public class MethodMatcher {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// check if all entries are in the bounds
|
// check if all entries are in the bounds
|
||||||
for (Map.Entry<TypeVariable, TypeMirror> entry : genericTypesMap.entrySet()) {
|
for ( Map.Entry<TypeVariable, TypeMirror> entry : genericTypesMap.entrySet() ) {
|
||||||
if (!isWithinBounds( entry.getValue(), getTypeParamFromCandidate( entry.getKey() ) ) ) {
|
if ( !isWithinBounds( entry.getValue(), getTypeParamFromCandidate( entry.getKey() ) ) ) {
|
||||||
// checks if the found Type is in bounds of the TypeParameters bounds.
|
// checks if the found Type is in bounds of the TypeParameters bounds.
|
||||||
typesMatch = false;
|
typesMatch = false;
|
||||||
}
|
}
|
||||||
@ -135,7 +134,7 @@ public class MethodMatcher {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean visitArray(ArrayType t, TypeMirror p) {
|
public Boolean visitArray(ArrayType t, TypeMirror p) {
|
||||||
|
|
||||||
if ( p.getKind().equals( TypeKind.ARRAY) ) {
|
if ( p.getKind().equals( TypeKind.ARRAY ) ) {
|
||||||
return t.getComponentType().accept( this, ( (ArrayType) p ).getComponentType() );
|
return t.getComponentType().accept( this, ( (ArrayType) p ).getComponentType() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -152,8 +151,7 @@ public class MethodMatcher {
|
|||||||
if ( t.asElement().getSimpleName().equals( t1.asElement().getSimpleName() )
|
if ( t.asElement().getSimpleName().equals( t1.asElement().getSimpleName() )
|
||||||
&& t.getTypeArguments().size() == t1.getTypeArguments().size() ) {
|
&& t.getTypeArguments().size() == t1.getTypeArguments().size() ) {
|
||||||
for ( int i = 0; i < t.getTypeArguments().size(); i++ ) {
|
for ( int i = 0; i < t.getTypeArguments().size(); i++ ) {
|
||||||
if (!t.getTypeArguments().get( i ).accept( this, t1.getTypeArguments().get( i ) ))
|
if ( !t.getTypeArguments().get( i ).accept( this, t1.getTypeArguments().get( i ) ) ) {
|
||||||
{
|
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +162,7 @@ public class MethodMatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +236,7 @@ public class MethodMatcher {
|
|||||||
// a result: <type, superType] (so type not included) so we need to check sameType also.
|
// a result: <type, superType] (so type not included) so we need to check sameType also.
|
||||||
TypeMirror superBoundAsDeclared = typeParameter.getBounds().get( 0 );
|
TypeMirror superBoundAsDeclared = typeParameter.getBounds().get( 0 );
|
||||||
return ( typeUtils.isSubtype( superBoundAsDeclared, p ) ||
|
return ( typeUtils.isSubtype( superBoundAsDeclared, p ) ||
|
||||||
typeUtils.isSameType( p, superBoundAsDeclared ) );
|
typeUtils.isSameType( p, superBoundAsDeclared ) );
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// does this situation occur?
|
// does this situation occur?
|
||||||
@ -254,6 +252,7 @@ public class MethodMatcher {
|
|||||||
* Looks through the list of type parameters of the candidate method for a match
|
* Looks through the list of type parameters of the candidate method for a match
|
||||||
*
|
*
|
||||||
* @param t type parameter to match
|
* @param t type parameter to match
|
||||||
|
*
|
||||||
* @return matching type parameter
|
* @return matching type parameter
|
||||||
*/
|
*/
|
||||||
private TypeParameterElement getTypeParamFromCandidate(TypeMirror t) {
|
private TypeParameterElement getTypeParamFromCandidate(TypeMirror t) {
|
||||||
@ -270,6 +269,7 @@ public class MethodMatcher {
|
|||||||
*
|
*
|
||||||
* @param t
|
* @param t
|
||||||
* @param tpe
|
* @param tpe
|
||||||
|
*
|
||||||
* @return true if within bounds
|
* @return true if within bounds
|
||||||
*/
|
*/
|
||||||
private boolean isWithinBounds(TypeMirror t, TypeParameterElement tpe) {
|
private boolean isWithinBounds(TypeMirror t, TypeParameterElement tpe) {
|
||||||
@ -277,7 +277,7 @@ public class MethodMatcher {
|
|||||||
if ( t != null && bounds != null ) {
|
if ( t != null && bounds != null ) {
|
||||||
for ( TypeMirror bound : bounds ) {
|
for ( TypeMirror bound : bounds ) {
|
||||||
if ( !( bound.getKind().equals( TypeKind.DECLARED ) &&
|
if ( !( bound.getKind().equals( TypeKind.DECLARED ) &&
|
||||||
typeUtils.isSubtype( t, bound ) ) ) {
|
typeUtils.isSubtype( t, bound ) ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,16 @@ import org.testng.annotations.Test;
|
|||||||
*
|
*
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
@WithClasses( { GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
|
@WithClasses({
|
||||||
|
GenericTypeMapper.class, Wrapper.class, ArrayWrapper.class, TwoArgHolder.class, TwoArgWrapper.class,
|
||||||
UpperBoundWrapper.class, WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
|
UpperBoundWrapper.class, WildCardExtendsWrapper.class, WildCardSuperWrapper.class, WildCardExtendsMBWrapper.class,
|
||||||
TypeA.class, TypeB.class, TypeC.class } )
|
TypeA.class, TypeB.class, TypeC.class
|
||||||
@IssueKey( value = "79" )
|
})
|
||||||
|
@IssueKey(value = "79")
|
||||||
public class ConversionTest extends MapperTestBase {
|
public class ConversionTest extends MapperTestBase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses( { Source.class, Target.class, SourceTargetMapper.class } )
|
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
|
||||||
public void shouldApplyGenericTypeMapper() {
|
public void shouldApplyGenericTypeMapper() {
|
||||||
|
|
||||||
// setup used types
|
// setup used types
|
||||||
@ -88,67 +90,72 @@ public class ConversionTest extends MapperTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ ErroneousSource1.class, ErroneousTarget1.class, ErroneousSourceTargetMapper1.class } )
|
@WithClasses({ ErroneousSource1.class, ErroneousTarget1.class, ErroneousSourceTargetMapper1.class })
|
||||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
@Diagnostic(type = ErroneousSourceTargetMapper1.class,
|
@Diagnostic(type = ErroneousSourceTargetMapper1.class,
|
||||||
kind = javax.tools.Diagnostic.Kind.ERROR, line = 29,
|
kind = javax.tools.Diagnostic.Kind.ERROR, line = 29,
|
||||||
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.UpperBoundWrapper"
|
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\" to "
|
||||||
+ "\"org.mapstruct.ap.test.conversion.generics.TypeA fooUpperBoundFailure\"") } )
|
+ "\"org.mapstruct.ap.test.conversion.generics.TypeA fooUpperBoundFailure\"")
|
||||||
|
})
|
||||||
public void shouldFailOnUpperBound() {
|
public void shouldFailOnUpperBound() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ ErroneousSource2.class, ErroneousTarget2.class, ErroneousSourceTargetMapper2.class } )
|
@WithClasses({ ErroneousSource2.class, ErroneousTarget2.class, ErroneousSourceTargetMapper2.class })
|
||||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
@Diagnostic(type = ErroneousSourceTargetMapper2.class,
|
@Diagnostic(type = ErroneousSourceTargetMapper2.class,
|
||||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||||
line = 29,
|
line = 29,
|
||||||
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.WildCardExtendsWrapper"
|
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\" to"
|
||||||
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardExtendsTypeAFailure\"" ) } )
|
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardExtendsTypeAFailure\"")
|
||||||
|
})
|
||||||
public void shouldFailOnWildCardBound() {
|
public void shouldFailOnWildCardBound() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ ErroneousSource3.class, ErroneousTarget3.class, ErroneousSourceTargetMapper3.class } )
|
@WithClasses({ ErroneousSource3.class, ErroneousTarget3.class, ErroneousSourceTargetMapper3.class })
|
||||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
@Diagnostic(type = ErroneousSourceTargetMapper3.class,
|
@Diagnostic(type = ErroneousSourceTargetMapper3.class,
|
||||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||||
line = 29,
|
line = 29,
|
||||||
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics."
|
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics."
|
||||||
+ "WildCardExtendsMBWrapper<org.mapstruct.ap.test.conversion.generics.TypeB> "
|
+ "WildCardExtendsMBWrapper<org.mapstruct.ap.test.conversion.generics.TypeB> "
|
||||||
+ "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.conversion.generics.TypeB "
|
+ "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.conversion.generics.TypeB "
|
||||||
+ "fooWildCardExtendsMBTypeBFailure\"" ) } )
|
+ "fooWildCardExtendsMBTypeBFailure\"")
|
||||||
|
})
|
||||||
public void shouldFailOnWildCardMultipleBounds() {
|
public void shouldFailOnWildCardMultipleBounds() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ ErroneousSource4.class, ErroneousTarget4.class, ErroneousSourceTargetMapper4.class } )
|
@WithClasses({ ErroneousSource4.class, ErroneousTarget4.class, ErroneousSourceTargetMapper4.class })
|
||||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
@Diagnostic(type = ErroneousSourceTargetMapper4.class,
|
@Diagnostic(type = ErroneousSourceTargetMapper4.class,
|
||||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||||
line = 29,
|
line = 29,
|
||||||
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.WildCardSuperWrapper"
|
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\" to"
|
||||||
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardSuperTypeAFailure\"" ) } )
|
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardSuperTypeAFailure\"")
|
||||||
|
})
|
||||||
public void shouldFailOnSuperBounds1() {
|
public void shouldFailOnSuperBounds1() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ ErroneousSource5.class, ErroneousTarget5.class, ErroneousSourceTargetMapper5.class } )
|
@WithClasses({ ErroneousSource5.class, ErroneousTarget5.class, ErroneousSourceTargetMapper5.class })
|
||||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
@Diagnostic(type = ErroneousSourceTargetMapper5.class,
|
@Diagnostic(type = ErroneousSourceTargetMapper5.class,
|
||||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||||
line = 29,
|
line = 29,
|
||||||
messageRegExp = "Can't map property \"org.mapstruct.ap.test.conversion.generics.WildCardSuperWrapper"
|
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\" to"
|
||||||
+ " \"org.mapstruct.ap.test.conversion.generics.TypeC fooWildCardSuperTypeCFailure\"" ) } )
|
+ " \"org.mapstruct.ap.test.conversion.generics.TypeC fooWildCardSuperTypeCFailure\"")
|
||||||
|
})
|
||||||
public void shouldFailOnSuperBounds2() {
|
public void shouldFailOnSuperBounds2() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user