FFFF Reuse cached erased TypeMirrors for Collection/Map/Stream checks by NabilJarrai · Pull Request #1 · spring-mapstruct/mapstruct · GitHub
[go: up one dir, main page]

Skip to content
Open
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 @@ -44,7 +44,6 @@
import org.mapstruct.ap.internal.util.ElementUtils;
import org.mapstruct.ap.internal.util.Executables;
import org.mapstruct.ap.internal.util.Filters;
import org.mapstruct.ap.internal.util.JavaStreamConstants;
import org.mapstruct.ap.internal.util.NativeTypes;
import org.mapstruct.ap.internal.util.Nouns;
import org.mapstruct.ap.internal.util.TypeUtils;
Expand Down Expand Up @@ -1084,23 +1083,16 @@ private boolean isCollectionOrMapOrStream(Accessor getterMethod) {
}

private boolean isCollection(TypeMirror candidate) {
return isSubType( candidate, Collection.class );
return typeUtils.isSubtypeErased( candidate, typeFactory.getCollectionType() );
}

private boolean isStream(TypeMirror candidate) {
TypeElement streamTypeElement = elementUtils.getTypeElement( JavaStreamConstants.STREAM_FQN );
TypeMirror streamType = streamTypeElement == null ? null : typeUtils.erasure( streamTypeElement.asType() );
TypeMirror streamType = typeFactory.getStreamType();
return streamType != null && typeUtils.isSubtypeErased( candidate, streamType );
}

private boolean isMap(TypeMirror candidate) {
return isSubType( candidate, Map.class );
}

private boolean isSubType(TypeMirror candidate, Class<?> clazz) {
String className = clazz.getCanonicalName();
TypeMirror classType = typeUtils.erasure( elementUtils.getTypeElement( className ).asType() );
return typeUtils.isSubtypeErased( candidate, classType );
return typeUtils.isSubtypeErased( candidate, typeFactory.getMapType() );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,18 @@ public BuilderType builderTypeFor( Type type, BuilderGem builder ) {
return null;
}

TypeMirror getCollectionType() {
return collectionType;
}

TypeMirror getMapType() {
return mapType;
}

TypeMirror getStreamType() {
return streamType;
}

public Type effectiveResultTypeFor( Type type, BuilderGem builder ) {
if ( type != null ) {
BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builder, false );
Expand Down
Loading
0