#206 adding case for protected method in same package

This commit is contained in:
sjaakd 2014-05-06 23:36:27 +02:00 committed by Gunnar Morling
parent e144519b28
commit a77a693d9d
4 changed files with 76 additions and 2 deletions

View File

@ -240,11 +240,12 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
return false;
}
else if ( method.getModifiers().contains( Modifier.PROTECTED ) ) {
return mapperToImplement.isAssignableTo( usedMapper );
return mapperToImplement.isAssignableTo( usedMapper ) ||
mapperToImplement.getPackageName().equals( usedMapper.getPackageName() );
}
else if ( !method.getModifiers().contains( Modifier.PUBLIC ) ) {
// default
return mapperToImplement.getPackageName().equals( usedMapper.getPackageName());
return mapperToImplement.getPackageName().equals( usedMapper.getPackageName() );
}
// public
return true;

View File

@ -58,6 +58,11 @@ public class ReferencedAccessibilityTest {
@WithClasses( { SourceTargetMapperDefaultSame.class, ReferencedMapperDefaultSame.class } )
public void shouldBeAbleToAccessDefaultMethodInReferencedInSamePackage() throws Exception { }
@Test
@IssueKey( "206" )
@WithClasses( { SourceTargetMapperProtected.class, ReferencedMapperProtected.class } )
public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() throws Exception { }
@Test
@IssueKey( "206" )
@WithClasses( { SourceTargetMapperDefaultOther.class, ReferencedMapperDefaultOther.class } )

View File

@ -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 ReferencedMapperProtected {
protected ReferencedTarget sourceToTarget( ReferencedSource source ) {
ReferencedTarget target = new ReferencedTarget();
target.setFoo( source.getFoo() );
return target;
}
}

View File

@ -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 = ReferencedMapperProtected.class)
public interface SourceTargetMapperProtected {
SourceTargetMapperProtected INSTANCE = Mappers.getMapper( SourceTargetMapperProtected.class );
@Mapping(source = "referencedSource", target = "referencedTarget")
Target toTarget(Source source);
}