mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3163: Strip wild card when checking for type assignability
This commit is contained in:
parent
721288140a
commit
8cc2bdd092
@ -629,11 +629,14 @@ public class Type extends ModelElement implements Comparable<Type> {
|
|||||||
* @return {@code true} if and only if this type is assignable to the given other type.
|
* @return {@code true} if and only if this type is assignable to the given other type.
|
||||||
*/
|
*/
|
||||||
public boolean isAssignableTo(Type other) {
|
public boolean isAssignableTo(Type other) {
|
||||||
if ( TypeKind.WILDCARD == typeMirror.getKind() ) {
|
TypeMirror otherMirror = other.typeMirror;
|
||||||
return typeUtils.contains( typeMirror, other.typeMirror );
|
if ( otherMirror.getKind() == TypeKind.WILDCARD ) {
|
||||||
|
otherMirror = typeUtils.erasure( other.typeMirror );
|
||||||
}
|
}
|
||||||
|
if ( TypeKind.WILDCARD == typeMirror.getKind() ) {
|
||||||
return typeUtils.isAssignable( typeMirror, other.typeMirror );
|
return typeUtils.contains( typeMirror, otherMirror );
|
||||||
|
}
|
||||||
|
return typeUtils.isAssignable( typeMirror, otherMirror );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3163;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface Issue3163Mapper {
|
||||||
|
|
||||||
|
Target map(Source value);
|
||||||
|
|
||||||
|
Target.Nested map(Source.Nested value);
|
||||||
|
|
||||||
|
default <T> Optional<T> wrapAsOptional(T value) {
|
||||||
|
return Optional.ofNullable( value );
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3163;
|
||||||
|
|
||||||
|
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
|
||||||
|
@WithClasses({
|
||||||
|
Issue3163Mapper.class,
|
||||||
|
Source.class,
|
||||||
|
Target.class
|
||||||
|
})
|
||||||
|
class Issue3163Test {
|
||||||
|
|
||||||
|
@ProcessorTest
|
||||||
|
void shouldCompile() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3163;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
public class Source {
|
||||||
|
|
||||||
|
private final Nested nested;
|
||||||
|
|
||||||
|
public Source(Nested nested) {
|
||||||
|
this.nested = nested;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nested getNested() {
|
||||||
|
return nested;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Nested {
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
public Nested(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3163;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
public class Target {
|
||||||
|
|
||||||
|
private Nested nested;
|
||||||
|
|
||||||
|
public Optional<Nested> getNested() {
|
||||||
|
return Optional.ofNullable( nested );
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||||
|
public final void setNested(Optional<? extends Nested> nested) {
|
||||||
|
this.nested = nested.orElse( null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Nested {
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user