Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,24 @@ public boolean isAssignableTo(Type other) {
return typeUtils.isAssignable( typeMirrorToMatch, other.typeMirror );
}

/**
* Whether this type is raw assignable to the given other type. We can't make a verdict on typevars,
* they need to be resolved first.
*
* @param other The other type.
*
* @return {@code true} if and only if this type is assignable to the given other type.
*/
public boolean isRawAssignableTo(Type other) {
if ( isTypeVar() || other.isTypeVar() ) {
return true;
}
if ( equals( other ) ) {
return true;
}
return typeUtils.isAssignable( typeUtils.erasure( typeMirror ), typeUtils.erasure( other.typeMirror ) );
}

/**
* getPropertyReadAccessors
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,18 @@ public interface Method {
default boolean isMappingTargetAssignableToReturnType() {
return isUpdateMethod() && getResultType().isAssignableTo( getReturnType() );
}

/**
* @return the first source type, intended for mapping methods from single source to target
*/
default Type getMappingSourceType() {
return getSourceParameters().get( 0 ).getType();
}

/**
* @return the short name for error messages
*/
default String shortName() {
return getResultType().getName() + ":" + getName() + "(" + getMappingSourceType().getName() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public boolean inverses(SourceMethod method) {
return method.getDeclaringMapper() == null
&& method.isAbstract()
&& getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1
&& first( getSourceParameters() ).getType().isAssignableTo( method.getResultType() )
&& getMappingSourceType().isAssignableTo( method.getResultType() )
&& getResultType().isAssignableTo( first( method.getSourceParameters() ).getType() );
}

Expand Down Expand Up @@ -326,7 +326,7 @@ public Parameter getTargetTypeParameter() {
public boolean isIterableMapping() {
if ( isIterableMapping == null ) {
isIterableMapping = getSourceParameters().size() == 1
&& first( getSourceParameters() ).getType().isIterableType()
&& getMappingSourceType().isIterableType()
&& getResultType().isIterableType();
}
return isIterableMapping;
Expand All @@ -335,17 +335,17 @@ && first( getSourceParameters() ).getType().isIterableType()
public boolean isStreamMapping() {
if ( isStreamMapping == null ) {
isStreamMapping = getSourceParameters().size() == 1
&& ( first( getSourceParameters() ).getType().isIterableType() && getResultType().isStreamType()
|| first( getSourceParameters() ).getType().isStreamType() && getResultType().isIterableType()
|| first( getSourceParameters() ).getType().isStreamType() && getResultType().isStreamType() );
&& ( getMappingSourceType().isIterableType() && getResultType().isStreamType()
|| getMappingSourceType().isStreamType() && getResultType().isIterableType()
|| getMappingSourceType().isStreamType() && getResultType().isStreamType() );
}
return isStreamMapping;
}

public boolean isMapMapping() {
if ( isMapMapping == null ) {
isMapMapping = getSourceParameters().size() == 1
&& first( getSourceParameters() ).getType().isMapType()
&& getMappingSourceType().isMapType()
&& getResultType().isMapType();
}
return isMapMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,13 @@ public boolean matches(List<Type> sourceTypes, Type targetType) {

Type sourceType = first( sourceTypes );

if ( getReturnType().isAssignableTo( targetType.erasure() )
&& sourceType.erasure().isAssignableTo( getParameter().getType() ) ) {
return doTypeVarsMatch( sourceType, targetType );
}
if ( getReturnType().getFullyQualifiedName().equals( "java.lang.Object" )
&& sourceType.erasure().isAssignableTo( getParameter().getType() ) ) {
// return type could be a type parameter T
return doTypeVarsMatch( sourceType, targetType );
}
if ( getReturnType().isAssignableTo( targetType.erasure() )
&& getParameter().getType().getFullyQualifiedName().equals( "java.lang.Object" ) ) {
// parameter type could be a type parameter T
return doTypeVarsMatch( sourceType, targetType );
Type returnType = getReturnType().resolveTypeVarToType( sourceType, getParameter().getType() );
if ( returnType == null ) {
return false;
}
return false;

return returnType.isAssignableTo( targetType )
&& sourceType.erasure().isAssignableTo( getParameter().getType() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
*/
package org.mapstruct.ap.internal.model.source.builtin;

import static org.mapstruct.ap.internal.util.Collections.asSet;

import java.util.Set;

import javax.xml.bind.JAXBElement;

import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory;

import static org.mapstruct.ap.internal.util.Collections.asSet;

/**
* @author Sjaak Derksen
*/
Expand All @@ -24,8 +25,9 @@ public class JaxbElemToValue extends BuiltInMethod {
private final Set<Type> importTypes;

public JaxbElemToValue(TypeFactory typeFactory) {
this.parameter = new Parameter( "element", typeFactory.getType( JAXBElement.class ) );
this.returnType = typeFactory.getType( Object.class );
Type type = typeFactory.getType( JAXBElement.class );
this.parameter = new Parameter( "element", type );
this.returnType = type.getTypeParameters().get( 0 );
this.importTypes = asSet( parameter.getType() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.mapstruct.ap.internal.model.source.selector;

import java.util.List;
import java.util.Objects;

import org.mapstruct.ap.internal.model.common.ParameterBinding;
import org.mapstruct.ap.internal.model.source.Method;
Expand Down Expand Up @@ -39,4 +40,21 @@ public void setParameterBindings(List<ParameterBinding> parameterBindings) {
public String toString() {
return method.toString();
}

@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
SelectedMethod<?> that = (SelectedMethod<?>) o;
return method.equals( that.method );
}

@Override
public int hashCode() {
return Objects.hash( method );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public <T extends Method> List<SelectedMethod<T>> getMatchingMethods(Method mapp
}

String name = xmlElementDecl.name().get();
TypeMirror scope = xmlElementDecl.scope().get();
TypeMirror scope = xmlElementDecl.scope().getValue();
Comment thread
filiphr marked this conversation as resolved.

boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() );
boolean scopeIsSetAndMatches =
Expand Down
Loading