diff --git a/src/main/java/com/openpojo/reflection/impl/PojoMethodFactory.java b/src/main/java/com/openpojo/reflection/impl/PojoMethodFactory.java index 27a54f8c..e442bd99 100644 --- a/src/main/java/com/openpojo/reflection/impl/PojoMethodFactory.java +++ b/src/main/java/com/openpojo/reflection/impl/PojoMethodFactory.java @@ -127,6 +127,8 @@ private static List generateGetMethodNames(final Field field) { String fieldName = field.getName(); if (fieldName.length() > 2 && fieldName.startsWith("is") && Character.isUpperCase(fieldName.charAt(2))) prefix.add(fieldName); + if (AttributeHelper.getAttributeName(field).length() > 2 && AttributeHelper.getAttributeName(field).startsWith("Is") && Character.isUpperCase(AttributeHelper.getAttributeName(field).charAt(2))) + prefix.add(AttributeHelper.getAttributeName(field).replaceFirst("Is", "is")); } return prefix; } @@ -179,6 +181,8 @@ private static List generateSetMethodNames(final Field field) { String fieldName = field.getName(); if (fieldName.length() > 2 && fieldName.startsWith("is") && Character.isUpperCase(fieldName.charAt(2))) prefix.add("set" + fieldName.substring(2)); + if (AttributeHelper.getAttributeName(field).length() > 2 && AttributeHelper.getAttributeName(field).startsWith("Is") && Character.isUpperCase(AttributeHelper.getAttributeName(field).charAt(2))) + prefix.add("set" + AttributeHelper.getAttributeName(field).replaceFirst("Is", "is")); return prefix; } diff --git a/src/test/java/com/openpojo/issues/issue104/IssueTest.java b/src/test/java/com/openpojo/issues/issue104/IssueTest.java new file mode 100644 index 00000000..f573b124 --- /dev/null +++ b/src/test/java/com/openpojo/issues/issue104/IssueTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010-2017 Osman Shoukry + * + * 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 com.openpojo.issues.issue104; + +import com.openpojo.issues.issue104.sample.ClassWithBooleanAndPrefix_prefixIsX; +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.reflection.utils.AttributeHelper; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * @author oshoukry + */ +public class IssueTest { + @Test + public void whenBooleanStartsWithAPrefixFollowedBy_Is_AndThirdCharacterIsUpperCase_Getter_IsX_Setter_setIsX() { + com.openpojo.reflection.cache.PojoCache.clear();; + AttributeHelper.registerFieldPrefix("prefix"); + + PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithBooleanAndPrefix_prefixIsX.class); + Validator pojoValidator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .build(); + + pojoValidator.validate(pojoClass); + } +} diff --git a/src/test/java/com/openpojo/issues/issue104/sample/ClassWithBooleanAndPrefix_prefixIsX.java b/src/test/java/com/openpojo/issues/issue104/sample/ClassWithBooleanAndPrefix_prefixIsX.java new file mode 100644 index 00000000..43d02f6b --- /dev/null +++ b/src/test/java/com/openpojo/issues/issue104/sample/ClassWithBooleanAndPrefix_prefixIsX.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010-2017 Osman Shoukry + * + * 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 com.openpojo.issues.issue104.sample; + +/** + * @author Francisco N + */ +public class ClassWithBooleanAndPrefix_prefixIsX { + public boolean isX() { + return prefixIsX; + } + + public void setIsX(boolean isX) { + this.prefixIsX= isX; + } + + private boolean prefixIsX; +}