diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index c587af52b..1420a1c57 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -47,6 +47,9 @@ public class DefaultAccessorNamingStrategy implements AccessorNamingStrategy { else if ( isAdderMethod( method ) ) { return MethodType.ADDER; } + else if ( isPresenceCheckMethod( method ) ) { + return MethodType.PRESENCE_CHECKER; + } else { return MethodType.OTHER; } @@ -123,4 +126,12 @@ public class DefaultAccessorNamingStrategy implements AccessorNamingStrategy { return typeElement != null ? typeElement.getQualifiedName().toString() : null; } + private boolean isPresenceCheckMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + + return methodName.startsWith( "has" ) && methodName.length() > 3 && + ( method.getReturnType().getKind() == TypeKind.BOOLEAN || + "java.lang.Boolean".equals( getQualifiedName( method.getReturnType() ) ) ); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/PresenceCheckAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/PresenceCheckAccessorNamingStrategy.java deleted file mode 100644 index c533292f9..000000000 --- a/processor/src/main/java/org/mapstruct/ap/spi/PresenceCheckAccessorNamingStrategy.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2012-2016 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.spi; - - -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.TypeKind; - -/** - * The default JavaBeans-compliant implementation of the {@link AccessorNamingStrategy} service provider interface. - * - * @author Sjaak Derksen - */ -public class PresenceCheckAccessorNamingStrategy - extends DefaultAccessorNamingStrategy - implements AccessorNamingStrategy { - - @Override - public MethodType getMethodType(ExecutableElement method) { - if ( isPresenceCheckMethod( method ) ) { - return MethodType.PRESENCE_CHECKER; - } - else { - return super.getMethodType( method ); - } - } - - - private boolean isPresenceCheckMethod(ExecutableElement method) { - String methodName = method.getSimpleName().toString(); - - return methodName.startsWith( "has" ) && methodName.length() > 3 && - ( method.getReturnType().getKind() == TypeKind.BOOLEAN || - "java.lang.Boolean".equals( getQualifiedName( method.getReturnType() ) ) ); - } - -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java index 2b4a25e1d..3c9338215 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java @@ -23,10 +23,8 @@ import static org.fest.assertions.Assertions.assertThat; import org.junit.Test; import org.junit.runner.RunWith; -import org.mapstruct.ap.spi.PresenceCheckAccessorNamingStrategy; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import org.mapstruct.ap.testutil.WithServiceImplementation; /** * Test for correct handling of source presence checks. @@ -42,7 +40,6 @@ import org.mapstruct.ap.testutil.WithServiceImplementation; GoalKeeper.class, SoccerTeamTarget.class }) -@WithServiceImplementation( PresenceCheckAccessorNamingStrategy.class ) @RunWith(AnnotationProcessorTestRunner.class) public class PresenceCheckTest {