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;
|
||||
}
|
||||
|
||||
MethodMatcher m = new MethodMatcher(typeUtils, method, returnType, parameterType);
|
||||
if (m.matches()) {
|
||||
return new MappingMethodReference(method);
|
||||
MethodMatcher m = new MethodMatcher( typeUtils, method, returnType, parameterType );
|
||||
if ( m.matches() ) {
|
||||
return new MappingMethodReference( method );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -21,7 +21,6 @@ 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;
|
||||
@ -111,8 +110,8 @@ public class MethodMatcher {
|
||||
}
|
||||
else {
|
||||
// check if all entries are in the bounds
|
||||
for (Map.Entry<TypeVariable, TypeMirror> entry : genericTypesMap.entrySet()) {
|
||||
if (!isWithinBounds( entry.getValue(), getTypeParamFromCandidate( entry.getKey() ) ) ) {
|
||||
for ( Map.Entry<TypeVariable, TypeMirror> entry : genericTypesMap.entrySet() ) {
|
||||
if ( !isWithinBounds( entry.getValue(), getTypeParamFromCandidate( entry.getKey() ) ) ) {
|
||||
// checks if the found Type is in bounds of the TypeParameters bounds.
|
||||
typesMatch = false;
|
||||
}
|
||||
@ -135,7 +134,7 @@ public class MethodMatcher {
|
||||
@Override
|
||||
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() );
|
||||
}
|
||||
else {
|
||||
@ -152,8 +151,7 @@ public class MethodMatcher {
|
||||
if ( t.asElement().getSimpleName().equals( t1.asElement().getSimpleName() )
|
||||
&& t.getTypeArguments().size() == t1.getTypeArguments().size() ) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -164,7 +162,7 @@ public class MethodMatcher {
|
||||
}
|
||||
}
|
||||
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.
|
||||
TypeMirror superBoundAsDeclared = typeParameter.getBounds().get( 0 );
|
||||
return ( typeUtils.isSubtype( superBoundAsDeclared, p ) ||
|
||||
typeUtils.isSameType( p, superBoundAsDeclared ) );
|
||||
typeUtils.isSameType( p, superBoundAsDeclared ) );
|
||||
|
||||
default:
|
||||
// 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
|
||||
*
|
||||
* @param t type parameter to match
|
||||
*
|
||||
* @return matching type parameter
|
||||
*/
|
||||
private TypeParameterElement getTypeParamFromCandidate(TypeMirror t) {
|
||||
@ -270,6 +269,7 @@ public class MethodMatcher {
|
||||
*
|
||||
* @param t
|
||||
* @param tpe
|
||||
*
|
||||
* @return true if within bounds
|
||||
*/
|
||||
private boolean isWithinBounds(TypeMirror t, TypeParameterElement tpe) {
|
||||
@ -277,7 +277,7 @@ public class MethodMatcher {
|
||||
if ( t != null && bounds != null ) {
|
||||
for ( TypeMirror bound : bounds ) {
|
||||
if ( !( bound.getKind().equals( TypeKind.DECLARED ) &&
|
||||
typeUtils.isSubtype( t, bound ) ) ) {
|
||||
typeUtils.isSubtype( t, bound ) ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -35,14 +35,16 @@ import org.testng.annotations.Test;
|
||||
*
|
||||
* @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,
|
||||
TypeA.class, TypeB.class, TypeC.class } )
|
||||
@IssueKey( value = "79" )
|
||||
TypeA.class, TypeB.class, TypeC.class
|
||||
})
|
||||
@IssueKey(value = "79")
|
||||
public class ConversionTest extends MapperTestBase {
|
||||
|
||||
@Test
|
||||
@WithClasses( { Source.class, Target.class, SourceTargetMapper.class } )
|
||||
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
|
||||
public void shouldApplyGenericTypeMapper() {
|
||||
|
||||
// setup used types
|
||||
@ -88,67 +90,72 @@ public class ConversionTest extends MapperTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ ErroneousSource1.class, ErroneousTarget1.class, ErroneousSourceTargetMapper1.class } )
|
||||
@WithClasses({ ErroneousSource1.class, ErroneousTarget1.class, ErroneousSourceTargetMapper1.class })
|
||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousSourceTargetMapper1.class,
|
||||
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\"") } )
|
||||
+ "<org.mapstruct.ap.test.conversion.generics.TypeA> fooUpperBoundFailure\" to "
|
||||
+ "\"org.mapstruct.ap.test.conversion.generics.TypeA fooUpperBoundFailure\"")
|
||||
})
|
||||
public void shouldFailOnUpperBound() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ ErroneousSource2.class, ErroneousTarget2.class, ErroneousSourceTargetMapper2.class } )
|
||||
@WithClasses({ ErroneousSource2.class, ErroneousTarget2.class, ErroneousSourceTargetMapper2.class })
|
||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousSourceTargetMapper2.class,
|
||||
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\"" ) } )
|
||||
+ "<org.mapstruct.ap.test.conversion.generics.TypeA> fooWildCardExtendsTypeAFailure\" to"
|
||||
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardExtendsTypeAFailure\"")
|
||||
})
|
||||
public void shouldFailOnWildCardBound() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ ErroneousSource3.class, ErroneousTarget3.class, ErroneousSourceTargetMapper3.class } )
|
||||
@WithClasses({ ErroneousSource3.class, ErroneousTarget3.class, ErroneousSourceTargetMapper3.class })
|
||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousSourceTargetMapper3.class,
|
||||
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\"" ) } )
|
||||
+ "WildCardExtendsMBWrapper<org.mapstruct.ap.test.conversion.generics.TypeB> "
|
||||
+ "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.conversion.generics.TypeB "
|
||||
+ "fooWildCardExtendsMBTypeBFailure\"")
|
||||
})
|
||||
public void shouldFailOnWildCardMultipleBounds() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ ErroneousSource4.class, ErroneousTarget4.class, ErroneousSourceTargetMapper4.class } )
|
||||
@WithClasses({ ErroneousSource4.class, ErroneousTarget4.class, ErroneousSourceTargetMapper4.class })
|
||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousSourceTargetMapper4.class,
|
||||
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\"" ) } )
|
||||
+ "<org.mapstruct.ap.test.conversion.generics.TypeA> fooWildCardSuperTypeAFailure\" to"
|
||||
+ " \"org.mapstruct.ap.test.conversion.generics.TypeA fooWildCardSuperTypeAFailure\"")
|
||||
})
|
||||
public void shouldFailOnSuperBounds1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ ErroneousSource5.class, ErroneousTarget5.class, ErroneousSourceTargetMapper5.class } )
|
||||
@WithClasses({ ErroneousSource5.class, ErroneousTarget5.class, ErroneousSourceTargetMapper5.class })
|
||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = ErroneousSourceTargetMapper5.class,
|
||||
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\"" ) } )
|
||||
+ "<org.mapstruct.ap.test.conversion.generics.TypeC> fooWildCardSuperTypeCFailure\" to"
|
||||
+ " \"org.mapstruct.ap.test.conversion.generics.TypeC fooWildCardSuperTypeCFailure\"")
|
||||
})
|
||||
public void shouldFailOnSuperBounds2() {
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user