diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index 0e0cc4f3e..016376ddf 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -77,6 +77,12 @@ ${mapstruct.version} provided + + ${project.groupId} + mapstruct-spi + ${mapstruct.version} + provided + diff --git a/parent/pom.xml b/parent/pom.xml index d2a74269d..6104b2086 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -206,6 +206,11 @@ mapstruct-processor ${project.version} + + ${project.groupId} + mapstruct-spi + ${project.version} + org.apache.maven.shared maven-verifier diff --git a/pom.xml b/pom.xml index 3ea91b66d..05120d1cb 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,7 @@ core core-jdk8 processor + spi integrationtest diff --git a/processor/pom.xml b/processor/pom.xml index 9cbad0986..309c0305f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -43,6 +43,10 @@ org.freemarker freemarker + + ${project.groupId} + mapstruct-spi + + + 4.0.0 + + + org.mapstruct + mapstruct-parent + 1.0.0-SNAPSHOT + ../parent/pom.xml + + + mapstruct-spi + jar + MapStruct Service Provider Interfaces + + + + + junit + junit + test + + + org.easytesting + fest-assert + test + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + check-style + verify + + checkstyle + + + + + + + + diff --git a/spi/src/main/java/org/mapstruct/spi/AccessorNamingStrategy.java b/spi/src/main/java/org/mapstruct/spi/AccessorNamingStrategy.java new file mode 100644 index 000000000..3320d7bdf --- /dev/null +++ b/spi/src/main/java/org/mapstruct/spi/AccessorNamingStrategy.java @@ -0,0 +1,102 @@ +/** + * Copyright 2012-2015 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.spi; + +/** + * A service provider interface for the mapping between method names and properties. + * + * @author Christian Schuster + */ +public interface AccessorNamingStrategy { + + /** + * Determine if a method name defines a getter with a non-boolean return type. + * + * @param methodName The method name. + * @return true if the method name can be a non-boolean getter, false otherwise. + */ + boolean isNonBooleanGetterName(String methodName); + + /** + * Determine if a method name defines a getter with a boolean return type. + * + * @param methodName The method name. + * @return true if the method name can be a boolean getter, false otherwise. + */ + boolean isBooleanGetterName(String methodName); + + /** + * Determine if a method name defines a setter. + * + * @param methodName The method name. + * @return true if the method name can be a setter, false otherwise. + */ + boolean isSetterName(String methodName); + + /** + * Determine if a method name defines an adder. + * + * @param methodName The method name. + * @return true if the method name can be an adder, false otherwise. + */ + boolean isAdderName(String methodName); + + /** + * Extract the property name from a method name for which {@link #isNonBooleanGetterName(String)} returned + * true. + * + * @param methodName The method name, guaranteed to be a non-boolean getter name. + * @return The property name corresponding to the method name. + */ + String getPropertyNameForNonBooleanGetterName(String methodName); + + /** + * Extract the property name from a method name for which {@link #isBooleanGetterName(String)} returned + * true. + * + * @param methodName The method name, guaranteed to be a boolean getter name. + * @return The property name corresponding to the method name. + */ + String getPropertyNameForBooleanGetterName(String methodName); + + /** + * Extract the property name from a method name for which {@link #isSetterName(String)} returned true. + * + * @param methodName The method name, guaranteed to be a setter name. + * @return The property name corresponding to the method name. + */ + String getPropertyNameForSetterName(String methodName); + + /** + * Extract the element name (singular form of the collection's property name) from a method name for which + * {@link #isAdderName(String)} returned true. + * + * @param methodName The method name, guaranteed to be an adder name. + * @return The element name corresponding to the method name. + */ + String getElementNameForAdderName(String methodName); + + /** + * Extract the non-boolean getter method name from the setter method name of the same property. + * + * @param methodName The method name, guaranteed to be a setter name. + * @return The corresponding non-boolean getter method name. + */ + String getNonBooleanGetterNameForSetterName(String methodName); +}