mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#206 adding checks on accessibility of referenced mappers and introducing unit test for that case
This commit is contained in:
parent
d6a6cb25b6
commit
e144519b28
@ -69,7 +69,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
this.messager = context.getMessager();
|
||||
this.typeFactory = context.getTypeFactory();
|
||||
this.typeUtils = context.getTypeUtils();
|
||||
return retrieveMethods( mapperTypeElement, true );
|
||||
return retrieveMethods( mapperTypeElement, mapperTypeElement );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,34 +80,32 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
/**
|
||||
* Retrieves the mapping methods declared by the given mapper type.
|
||||
*
|
||||
* @param element The type of interest
|
||||
* @param mapperRequiresImplementation Whether an implementation of this type must be generated or not. {@code true}
|
||||
* if the type is the currently processed mapper interface, {@code false} if the given type is one
|
||||
* referred to via {@code Mapper#uses()}.
|
||||
* @param usedMapper The type of interest (either the mapper to implement or a used mapper via @uses annotation)
|
||||
* @param mapperToImplement the top level type (mapper) that requires implementation
|
||||
*
|
||||
* @return All mapping methods declared by the given type
|
||||
*/
|
||||
private List<SourceMethod> retrieveMethods(TypeElement element, boolean mapperRequiresImplementation) {
|
||||
private List<SourceMethod> retrieveMethods(TypeElement usedMapper, TypeElement mapperToImplement) {
|
||||
List<SourceMethod> methods = new ArrayList<SourceMethod>();
|
||||
|
||||
for ( ExecutableElement executable : methodsIn( allEnclosingElementsIncludeSuper( element ) ) ) {
|
||||
SourceMethod method = getMethod( element, executable, mapperRequiresImplementation );
|
||||
for ( ExecutableElement executable : methodsIn( allEnclosingElementsIncludeSuper( usedMapper ) ) ) {
|
||||
SourceMethod method = getMethod( usedMapper, executable, mapperToImplement );
|
||||
if ( method != null ) {
|
||||
methods.add( method );
|
||||
}
|
||||
}
|
||||
|
||||
//Add all methods of used mappers in order to reference them in the aggregated model
|
||||
if ( mapperRequiresImplementation ) {
|
||||
MapperConfig mapperSettings = MapperConfig.getInstanceOn( element );
|
||||
if ( usedMapper.equals( mapperToImplement ) ) {
|
||||
MapperConfig mapperSettings = MapperConfig.getInstanceOn( usedMapper );
|
||||
if ( !mapperSettings.isValid() ) {
|
||||
throw new AnnotationProcessingException(
|
||||
"Couldn't retrieve @Mapper annotation", element, mapperSettings.getAnnotationMirror()
|
||||
"Couldn't retrieve @Mapper annotation", usedMapper, mapperSettings.getAnnotationMirror()
|
||||
);
|
||||
}
|
||||
|
||||
for ( TypeMirror usedMapper : mapperSettings.uses() ) {
|
||||
methods.addAll( retrieveMethods( asTypeElement( usedMapper ), false ) );
|
||||
for ( TypeMirror mapper : mapperSettings.uses() ) {
|
||||
methods.addAll( retrieveMethods( asTypeElement( mapper ), mapperToImplement ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,9 +138,9 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
&& asTypeElement( element.getSuperclass() ).getSuperclass().getKind() == TypeKind.DECLARED;
|
||||
}
|
||||
|
||||
private SourceMethod getMethod(TypeElement element,
|
||||
private SourceMethod getMethod(TypeElement usedMapper,
|
||||
ExecutableElement method,
|
||||
boolean mapperRequiresImplementation) {
|
||||
TypeElement mapperToImplement) {
|
||||
List<Parameter> parameters = typeFactory.getParameters( method );
|
||||
Type returnType = typeFactory.getReturnType( method );
|
||||
List<Type> exceptionTypes = typeFactory.getThrownTypes( method );
|
||||
@ -151,7 +149,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
boolean methodRequiresImplementation = method.getModifiers().contains( Modifier.ABSTRACT );
|
||||
boolean containsTargetTypeParameter = SourceMethod.containsTargetTypeParameter( parameters );
|
||||
|
||||
if ( mapperRequiresImplementation && methodRequiresImplementation ) {
|
||||
if ( ( usedMapper.equals( mapperToImplement ) ) && methodRequiresImplementation ) {
|
||||
List<Parameter> sourceParameters = extractSourceParameters( parameters );
|
||||
Parameter targetParameter = extractTargetParameter( parameters );
|
||||
Type resultType = selectResultType( returnType, targetParameter );
|
||||
@ -184,15 +182,21 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
}
|
||||
//otherwise add reference to existing mapper method
|
||||
else if ( isValidReferencedMethod( parameters ) || isValidFactoryMethod( parameters ) ) {
|
||||
return
|
||||
SourceMethod.forReferencedMethod(
|
||||
mapperRequiresImplementation ? null : typeFactory.getType( element ),
|
||||
method,
|
||||
parameters,
|
||||
returnType,
|
||||
exceptionTypes,
|
||||
typeUtils
|
||||
Type usedMapperAsType = typeFactory.getType( usedMapper );
|
||||
Type mapperToImplementAsType = typeFactory.getType( mapperToImplement );
|
||||
if ( isAccessible( mapperToImplementAsType, usedMapperAsType, method ) ) {
|
||||
return SourceMethod.forReferencedMethod(
|
||||
usedMapper.equals( mapperToImplement ) ? null : usedMapperAsType,
|
||||
method,
|
||||
parameters,
|
||||
returnType,
|
||||
exceptionTypes,
|
||||
typeUtils
|
||||
);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@ -229,6 +233,23 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
&& parameters.size() == validSourceParameters + targetParameters + targetTypeParameters;
|
||||
}
|
||||
|
||||
|
||||
private boolean isAccessible( Type mapperToImplement, Type usedMapper, ExecutableElement method ) {
|
||||
|
||||
if ( method.getModifiers().contains( Modifier.PRIVATE ) ) {
|
||||
return false;
|
||||
}
|
||||
else if ( method.getModifiers().contains( Modifier.PROTECTED ) ) {
|
||||
return mapperToImplement.isAssignableTo( usedMapper );
|
||||
}
|
||||
else if ( !method.getModifiers().contains( Modifier.PUBLIC ) ) {
|
||||
// default
|
||||
return mapperToImplement.getPackageName().equals( usedMapper.getPackageName());
|
||||
}
|
||||
// public
|
||||
return true;
|
||||
}
|
||||
|
||||
private Parameter extractTargetParameter(List<Parameter> parameters) {
|
||||
for ( Parameter param : parameters ) {
|
||||
if ( param.isMappingTarget() ) {
|
||||
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Mapper
|
||||
public abstract class AbstractSourceTargetMapperPrivate extends SourceTargetmapperPrivateBase {
|
||||
|
||||
public static final AbstractSourceTargetMapperPrivate INSTANCE =
|
||||
Mappers.getMapper( AbstractSourceTargetMapperPrivate.class );
|
||||
|
||||
@Mapping(source = "referencedSource", target = "referencedTarget")
|
||||
public abstract Target toTarget(Source source);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Mapper
|
||||
public abstract class AbstractSourceTargetMapperProtected extends SourceTargetmapperProtectedBase {
|
||||
|
||||
public static final AbstractSourceTargetMapperProtected INSTANCE =
|
||||
Mappers.getMapper( AbstractSourceTargetMapperProtected.class );
|
||||
|
||||
@Mapping(source = "referencedSource", target = "referencedTarget")
|
||||
public abstract Target toTarget(Source source);
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.test.accessibility.referenced.a.ReferencedMapperDefaultOther;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
|
||||
/**
|
||||
* Test for different accessibility modifiers
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@WithClasses( { Source.class, Target.class, ReferencedSource.class, ReferencedTarget.class } )
|
||||
@RunWith( AnnotationProcessorTestRunner.class )
|
||||
public class ReferencedAccessibilityTest {
|
||||
|
||||
@Test
|
||||
@IssueKey( "206" )
|
||||
@WithClasses( { SourceTargetMapperPrivate.class, ReferencedMapperPrivate.class } )
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic( type = SourceTargetMapperPrivate.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 35,
|
||||
messageRegExp = "Can't map property \"org\\.mapstruct\\.ap\\.test\\.accessibility\\."
|
||||
+ "referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\."
|
||||
+ "ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"" )
|
||||
}
|
||||
)
|
||||
public void shouldNotBeAbleToAccessPrivateMethodInReferenced() throws Exception { }
|
||||
|
||||
@Test
|
||||
@IssueKey( "206" )
|
||||
@WithClasses( { SourceTargetMapperDefaultSame.class, ReferencedMapperDefaultSame.class } )
|
||||
public void shouldBeAbleToAccessDefaultMethodInReferencedInSamePackage() throws Exception { }
|
||||
|
||||
@Test
|
||||
@IssueKey( "206" )
|
||||
@WithClasses( { SourceTargetMapperDefaultOther.class, ReferencedMapperDefaultOther.class } )
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic( type = SourceTargetMapperDefaultOther.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 36,
|
||||
messageRegExp = "Can't map property \"org\\.mapstruct\\.ap\\.test\\.accessibility\\."
|
||||
+ "referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\."
|
||||
+ "ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"" )
|
||||
}
|
||||
)
|
||||
public void shouldNotBeAbleToAccessDefaultMethodInReferencedInOtherPackage() throws Exception { }
|
||||
|
||||
@Test
|
||||
@IssueKey( "206" )
|
||||
@WithClasses( { AbstractSourceTargetMapperProtected.class, SourceTargetmapperProtectedBase.class } )
|
||||
public void shouldBeAbleToAccessProtectedMethodInBase() throws Exception { }
|
||||
|
||||
|
||||
@Test
|
||||
@IssueKey( "206" )
|
||||
@WithClasses( { AbstractSourceTargetMapperPrivate.class, SourceTargetmapperPrivateBase.class } )
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic( type = AbstractSourceTargetMapperPrivate.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 36,
|
||||
messageRegExp = "Can't map property \"org\\.mapstruct\\.ap\\.test\\.accessibility\\."
|
||||
+ "referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\."
|
||||
+ "ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"" )
|
||||
}
|
||||
)
|
||||
public void shouldNotBeAbleToAccessPrivateMethodInBase() throws Exception { }
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class ReferencedMapperDefaultSame {
|
||||
|
||||
ReferencedTarget sourceToTarget( ReferencedSource source ) {
|
||||
ReferencedTarget target = new ReferencedTarget();
|
||||
target.setFoo( source.getFoo() );
|
||||
return target;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class ReferencedMapperPrivate {
|
||||
|
||||
private ReferencedTarget sourceToTarget( ReferencedSource source ) {
|
||||
ReferencedTarget target = new ReferencedTarget();
|
||||
target.setFoo( source.getFoo() );
|
||||
return target;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class ReferencedSource {
|
||||
private String foo;
|
||||
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class ReferencedTarget {
|
||||
private String foo;
|
||||
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Source {
|
||||
|
||||
private ReferencedSource referencedSource;
|
||||
|
||||
public ReferencedSource getReferencedSource() {
|
||||
return referencedSource;
|
||||
}
|
||||
|
||||
public void setReferencedSource( ReferencedSource referencedSource ) {
|
||||
this.referencedSource = referencedSource;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ap.test.accessibility.referenced.a.ReferencedMapperDefaultOther;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Mapper(uses = ReferencedMapperDefaultOther.class)
|
||||
public interface SourceTargetMapperDefaultOther {
|
||||
|
||||
SourceTargetMapperDefaultOther INSTANCE = Mappers.getMapper( SourceTargetMapperDefaultOther.class );
|
||||
|
||||
@Mapping(source = "referencedSource", target = "referencedTarget")
|
||||
Target toTarget(Source source);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Mapper(uses = ReferencedMapperDefaultSame.class)
|
||||
public interface SourceTargetMapperDefaultSame {
|
||||
|
||||
SourceTargetMapperDefaultSame INSTANCE = Mappers.getMapper( SourceTargetMapperDefaultSame.class );
|
||||
|
||||
@Mapping(source = "referencedSource", target = "referencedTarget")
|
||||
Target toTarget(Source source);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Mapper(uses = ReferencedMapperPrivate.class)
|
||||
public interface SourceTargetMapperPrivate {
|
||||
|
||||
SourceTargetMapperPrivate INSTANCE = Mappers.getMapper( SourceTargetMapperPrivate.class );
|
||||
|
||||
@Mapping(source = "referencedSource", target = "referencedTarget")
|
||||
Target toTarget(Source source);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class SourceTargetmapperPrivateBase {
|
||||
|
||||
private ReferencedTarget sourceToTarget( ReferencedSource source ) {
|
||||
ReferencedTarget target = new ReferencedTarget();
|
||||
target.setFoo( source.getFoo() );
|
||||
return target;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class SourceTargetmapperProtectedBase {
|
||||
|
||||
protected ReferencedTarget sourceToTarget( ReferencedSource source ) {
|
||||
ReferencedTarget target = new ReferencedTarget();
|
||||
target.setFoo( source.getFoo() );
|
||||
return target;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Target {
|
||||
|
||||
private ReferencedTarget referencedTarget;
|
||||
|
||||
public ReferencedTarget getReferencedTarget() {
|
||||
return referencedTarget;
|
||||
}
|
||||
|
||||
public void setReferencedTarget( ReferencedTarget referencedTarget ) {
|
||||
this.referencedTarget = referencedTarget;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct.ap.test.accessibility.referenced.a;
|
||||
|
||||
import org.mapstruct.ap.test.accessibility.referenced.ReferencedSource;
|
||||
import org.mapstruct.ap.test.accessibility.referenced.ReferencedTarget;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class ReferencedMapperDefaultOther {
|
||||
|
||||
ReferencedTarget sourceToTarget( ReferencedSource source ) {
|
||||
ReferencedTarget target = new ReferencedTarget();
|
||||
target.setFoo( source.getFoo() );
|
||||
return target;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user