-
-
Notifications
You must be signed in to change notification settings - Fork 990
#3303 Mapping from Map to Map and specify source and target keys of type String #3367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
thunderhook
wants to merge
3
commits into
mapstruct:main
Choose a base branch
from
thunderhook:3303
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
processor/src/main/java/org/mapstruct/ap/internal/model/MapKeyMappingConstructor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.internal.model; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import org.mapstruct.ap.internal.model.common.ModelElement; | ||
import org.mapstruct.ap.internal.model.common.Type; | ||
|
||
/** | ||
* Represents a constructor that is used for mapping keys of a {@link MapMappingMethod}. | ||
* | ||
* @author Oliver Erhart | ||
*/ | ||
public class MapKeyMappingConstructor extends ModelElement implements Constructor { | ||
|
||
private final String name; | ||
private final String delegateName; | ||
private final boolean invokeSuperConstructor; | ||
|
||
public MapKeyMappingConstructor(String name, String delegateName, boolean invokeSuperConstructor) { | ||
this.name = name; | ||
this.delegateName = delegateName; | ||
this.invokeSuperConstructor = invokeSuperConstructor; | ||
} | ||
|
||
@Override | ||
public Set<Type> getImportTypes() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDelegateName() { | ||
return delegateName; | ||
} | ||
|
||
public boolean isInvokeSuperConstructor() { | ||
return invokeSuperConstructor; | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...essor/src/main/java/org/mapstruct/ap/internal/model/MapKeyMappingConstructorFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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.internal.model; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import org.mapstruct.ap.internal.model.common.ConstructorFragment; | ||
import org.mapstruct.ap.internal.model.common.ModelElement; | ||
import org.mapstruct.ap.internal.model.common.Type; | ||
|
||
/** | ||
* Constructor fragment for key mappings for a {@link MapMappingMethod}. | ||
* | ||
* @author Oliver Erhart | ||
*/ | ||
public class MapKeyMappingConstructorFragment extends ModelElement implements ConstructorFragment { | ||
|
||
private final MapKeyMappingField field; | ||
private final MappingMethod definingMethod; | ||
private final List<KeyMappingEntry> keyMappings; | ||
|
||
public MapKeyMappingConstructorFragment(MapKeyMappingField field, MappingMethod definingMethod, | ||
List<KeyMappingEntry> keyMappings) { | ||
this.field = field; | ||
this.definingMethod = definingMethod; | ||
this.keyMappings = keyMappings; | ||
} | ||
|
||
@Override | ||
public Set<Type> getImportTypes() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
public MapKeyMappingField getField() { | ||
return field; | ||
} | ||
|
||
public MappingMethod getDefiningMethod() { | ||
return definingMethod; | ||
} | ||
|
||
public List<KeyMappingEntry> getKeyMappings() { | ||
return keyMappings; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ( ( field == null ) ? 0 : field.hashCode() ); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if ( this == obj ) { | ||
return true; | ||
} | ||
if ( obj == null ) { | ||
return false; | ||
} | ||
if ( getClass() != obj.getClass() ) { | ||
return false; | ||
} | ||
MapKeyMappingConstructorFragment other = (MapKeyMappingConstructorFragment) obj; | ||
|
||
if ( !Objects.equals( field, other.field ) ) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static void addAllMapKeyMappingFragmentsIn(List<MapMappingMethod> mapMappingMethods, | ||
Set<ConstructorFragment> targets) { | ||
for ( MapMappingMethod mapMappingMethod : mapMappingMethods ) { | ||
MapKeyMappingConstructorFragment fragment = mapMappingMethod.getMapMappingConstructorFragment(); | ||
if ( fragment != null ) { | ||
targets.add( mapMappingMethod.getMapMappingConstructorFragment() ); | ||
} | ||
} | ||
} | ||
|
||
public static class KeyMappingEntry { | ||
|
||
String source; | ||
String target; | ||
|
||
public KeyMappingEntry(String source, String target) { | ||
this.source = source; | ||
this.target = target; | ||
} | ||
|
||
public String getSource() { | ||
return source; | ||
} | ||
|
||
public String getTarget() { | ||
return target; | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
processor/src/main/java/org/mapstruct/ap/internal/model/MapKeyMappingField.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.internal.model; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* Field that is used for mapping keys of a {@link MapMappingMethod}. | ||
* | ||
* @author Oliver Erhart | ||
*/ | ||
public class MapKeyMappingField extends Field { | ||
|
||
public MapKeyMappingField(String variableName) { | ||
super( null, variableName, true ); | ||
} | ||
|
||
public static void addAllMapKeyMappingFieldsIn(List<MapMappingMethod> mapMappingMethods, Set<Field> targets) { | ||
for ( MapMappingMethod mapMappingMethod : mapMappingMethods ) { | ||
MapKeyMappingConstructorFragment fragment = mapMappingMethod.getMapMappingConstructorFragment(); | ||
if (fragment != null) { | ||
Field field = fragment.getField(); | ||
if ( field != null ) { | ||
targets.add( field ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this used?