-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Define new enum ClassAccessibility #4071
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
Merged
+306
−5
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
38df79f
Define new enum ClassAccessibility for controlling generated Mappers'…
Chessray c0784ac
Define new enum ClassAccessibility for controlling generated Mappers'…
Chessray cad76eb
Merge remote-tracking branch 'origin/main'
Chessray 5f9a034
Fix typos, improve wording, and add missing tests.
Chessray 5ae77ce
Checkstyle
Chessray 0d4ec31
Merge branch 'mapstruct:main' into main
Chessray 4514a92
Rename accessibility options as discussed.
Chessray 9af8669
Formatting
Chessray 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright MapStruct Authors. | ||
| * | ||
| * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package org.mapstruct; | ||
|
|
||
| /** | ||
| * Determines whether a generated Mapper implementation class will be declared {@code public} or not. | ||
| * | ||
| * @author Raimund Klein | ||
| * | ||
| * @since 1.7.0 | ||
| */ | ||
| public enum ClassAccessibility { | ||
| /** | ||
| * The generated Mapper will have the same modifier ({@code public} or none) as the annotated class or interface. | ||
| */ | ||
| DEFAULT, | ||
| /** | ||
| * The generated Mapper will be declared {@code public}. | ||
| */ | ||
| PUBLIC, | ||
| /** | ||
| * The generated Mapper will have no visibility modifier ("package-private"). | ||
| */ | ||
| PACKAGE_PRIVATE | ||
| } |
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
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
15 changes: 15 additions & 0 deletions
15
processor/src/main/java/org/mapstruct/ap/internal/gem/ClassAccessibilityGem.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,15 @@ | ||
| /* | ||
| * 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.gem; | ||
|
|
||
| /** | ||
| * Gem for the enum {@link org.mapstruct.ClassAccessibility} | ||
| * | ||
| * @author Raimund Klein | ||
| */ | ||
| public enum ClassAccessibilityGem { | ||
| DEFAULT, PUBLIC, PACKAGE_PRIVATE | ||
| } | ||
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
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
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
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
49 changes: 49 additions & 0 deletions
49
processor/src/test/java/org/mapstruct/ap/test/classaccessibility/ClassAccessibilityTest.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,49 @@ | ||
| /* | ||
| * 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.classaccessibility; | ||
|
|
||
| import org.mapstruct.ap.testutil.ProcessorTest; | ||
| import org.mapstruct.ap.testutil.WithClasses; | ||
|
|
||
| import static java.lang.reflect.Modifier.isPrivate; | ||
| import static java.lang.reflect.Modifier.isProtected; | ||
| import static java.lang.reflect.Modifier.isPublic; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @WithClasses({ | ||
| Source.class, | ||
| Target.class, | ||
| PublicAbstractionMapper.class, | ||
| PackageAbstractionMapper.class, | ||
| ForcedPublicMapper.class, | ||
| ForcedPackagePrivateMapper.class | ||
| }) | ||
| public class ClassAccessibilityTest { | ||
|
|
||
| @ProcessorTest | ||
| public void shouldCreateModifierAccordingToAnnotation() throws Exception { | ||
| Class<?> publicLike = loadForMapper( PublicAbstractionMapper.class ); | ||
| assertThat( isPublic( publicLike.getModifiers() ) ).isTrue(); | ||
|
|
||
| Class<?> packageLike = loadForMapper( PackageAbstractionMapper.class ); | ||
| assertThat( isDefault( packageLike.getModifiers() ) ).isTrue(); | ||
|
|
||
| Class<?> forcedPublic = loadForMapper( ForcedPublicMapper.class ); | ||
| assertThat( isPublic( forcedPublic.getModifiers() ) ).isTrue(); | ||
|
|
||
| Class<?> forcedDefault = loadForMapper( ForcedPackagePrivateMapper.class ); | ||
| assertThat( isDefault( forcedDefault.getModifiers() ) ).isTrue(); | ||
| } | ||
|
|
||
| private static Class<?> loadForMapper(Class<?> mapper) throws ClassNotFoundException { | ||
| return Thread.currentThread().getContextClassLoader().loadClass( mapper.getName() + "Impl" ); | ||
| } | ||
|
|
||
| private static boolean isDefault(int modifiers) { | ||
| return !isPublic( modifiers ) && !isProtected( modifiers ) && !isPrivate( modifiers ); | ||
| } | ||
| } | ||
|
|
15 changes: 15 additions & 0 deletions
15
...or/src/test/java/org/mapstruct/ap/test/classaccessibility/ForcedPackagePrivateMapper.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,15 @@ | ||
| /* | ||
| * 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.classaccessibility; | ||
|
|
||
| import org.mapstruct.ClassAccessibility; | ||
| import org.mapstruct.Mapper; | ||
|
|
||
| @Mapper(accessibility = ClassAccessibility.PACKAGE_PRIVATE) | ||
| public interface ForcedPackagePrivateMapper { | ||
| Target map(Source value); | ||
| } | ||
|
|
15 changes: 15 additions & 0 deletions
15
processor/src/test/java/org/mapstruct/ap/test/classaccessibility/ForcedPublicMapper.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,15 @@ | ||
| /* | ||
| * 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.classaccessibility; | ||
|
|
||
| import org.mapstruct.ClassAccessibility; | ||
| import org.mapstruct.Mapper; | ||
|
|
||
| @Mapper(accessibility = ClassAccessibility.PUBLIC) | ||
| interface ForcedPublicMapper { | ||
| Target map(Source value); | ||
| } | ||
|
|
14 changes: 14 additions & 0 deletions
14
...ssor/src/test/java/org/mapstruct/ap/test/classaccessibility/PackageAbstractionMapper.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,14 @@ | ||
| /* | ||
| * 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.classaccessibility; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
|
|
||
| @Mapper | ||
| interface PackageAbstractionMapper { | ||
| Target map(Source value); | ||
| } | ||
|
|
14 changes: 14 additions & 0 deletions
14
...essor/src/test/java/org/mapstruct/ap/test/classaccessibility/PublicAbstractionMapper.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,14 @@ | ||
| /* | ||
| * 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.classaccessibility; | ||
|
|
||
| import org.mapstruct.Mapper; | ||
|
|
||
| @Mapper | ||
| public interface PublicAbstractionMapper { | ||
| Target map(Source value); | ||
| } | ||
|
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.