Skip to content

Commit 21936e1

Browse files
authored
Support var-args parameter on setters too (#187)
1 parent 441f5ce commit 21936e1

File tree

11 files changed

+46
-28
lines changed

11 files changed

+46
-28
lines changed

frank-doc-doclet/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description>Doclet for the Frank!Doc</description>
1616

1717
<properties>
18-
<log4j2.version>2.22.1</log4j2.version>
18+
<log4j2.version>2.23.1</log4j2.version>
1919
<argLine /> <!-- add empty default argLine so Surefire won't fail when JaCoCo isn't present -->
2020
</properties>
2121

@@ -98,7 +98,7 @@
9898

9999
<plugin>
100100
<artifactId>maven-shade-plugin</artifactId>
101-
<version>3.5.2</version>
101+
<version>3.5.3</version>
102102
<executions>
103103
<execution>
104104
<phase>package</phase>
@@ -181,7 +181,7 @@
181181
<dependency>
182182
<groupId>org.projectlombok</groupId>
183183
<artifactId>lombok</artifactId>
184-
<version>1.18.30</version>
184+
<version>1.18.32</version>
185185
<scope>provided</scope>
186186
</dependency>
187187
<dependency>

frank-doc-doclet/src/main/java/org/frankframework/frankdoc/Utils.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,18 @@ public static boolean isAttributeGetterOrSetter(FrankMethod method) {
105105
boolean isSetter = method.getReturnType().isPrimitive()
106106
&& method.getReturnType().getName().equals("void")
107107
&& (method.getParameterTypes().length == 1)
108-
&& (!method.isVarargs())
109108
&& (method.getParameterTypes()[0].isPrimitive()
110109
|| JAVA_BOXED.contains(method.getParameterTypes()[0].getName())
111110
|| method.getParameterTypes()[0].isEnum());
112-
boolean isGetter = (
111+
if (isSetter) {
112+
return true;
113+
}
114+
// Check getter too.
115+
return ((method.getParameterTypes().length == 0) &&
113116
(method.getReturnType().isPrimitive()
114-
&& !method.getReturnType().getName().equals("void"))
115-
|| JAVA_BOXED.contains(method.getReturnType().getName())
116-
|| method.getReturnType().isEnum()
117-
) && (method.getParameterTypes().length == 0);
118-
return isSetter || isGetter;
117+
&& !method.getReturnType().getName().equals("void"))
118+
|| JAVA_BOXED.contains(method.getReturnType().getName())
119+
|| method.getReturnType().isEnum());
119120
}
120121

121122
public static boolean isConfigChildSetter(FrankMethod method) {
@@ -129,7 +130,7 @@ private static boolean configChildSetter(String methodName, FrankType parameterT
129130
boolean objectConfigChild = (!parameterType.isPrimitive())
130131
&& (!JAVA_BOXED.contains(parameterType.getName()));
131132
// A ConfigChildSetterDescriptor for a TextConfigChild should not start with "set".
132-
// If that would be allowed then we would have confusing with attribute setters.
133+
// If that was allowed, then we would have confusing with attribute setters.
133134
boolean textConfigChild = (!methodName.startsWith("set")) && parameterType.getName().equals(JAVA_STRING);
134135
return objectConfigChild || textConfigChild;
135136
}

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/DocWriterNewAndJsonGenerationExamplesTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ public void testXsd(XsdVersion xsdVersion, AttributeTypeStrategy attributeTypeSt
111111
DocWriterNew docWriter = new DocWriterNew(model, attributeTypeStrategy, "1.2.3-SNAPSHOT");
112112
docWriter.init(startClassName, xsdVersion);
113113
String actualXsd = docWriter.getSchema();
114-
System.out.println(actualXsd);
115114
String expectedXsd = TestUtil.getTestFile("/doc/examplesExpected/" + expectedXsdFileName);
116-
System.out.println("Jacobjob: " + "/doc/examplesExpected/" + expectedXsdFileName);
117115
TestUtil.assertEqualsIgnoreCRLF(expectedXsd, actualXsd);
118116
}
119117

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/model/FrankDocModelTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ public void testSequenceOfAttributesMatchesSequenceOfSetterMethods() throws Exce
344344
attributeOwner = instance.findOrCreateFrankElement(className);
345345
List<String> actualAttributeNames = instance.createAttributes(classRepository.findClass(className), attributeOwner, classRepository).stream()
346346
.map(FrankAttribute::getName)
347-
.collect(Collectors.toList());
348-
String[] expectedAttributeNames = new String[] {"attributeSetterGetter", "attributeSetterIs", "attributeOnlySetter", "attributeOnlySetterInt",
347+
.toList();
348+
String[] expectedAttributeNames = new String[] {"attributeSetterGetter", "attributeSetterIs", "attributeOnlySetter", "attributeVararg", "attributeOnlySetterInt",
349349
"attributeOnlySetterIntBoxed", "attributeOnlySetterBoolBoxed", "attributeOnlySetterLongBoxed", "attributeOnlySetterByteBoxed",
350350
"attributeOnlySetterShortBoxed", "ibisDockedOnlyDescription", "ibisDockedOrderDescription", "ibisDockedDescriptionDefault",
351351
"ibisDockedOrderDescriptionDefault", "ibisDockedDeprecated", "attributeWithJavaDoc",

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/testtarget/doclet/Child.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ String packagePrivateMethod() {
2121
private void privateMethod() {
2222
}
2323

24-
public void setVarargMethod(String ...value) {
24+
public void setVarargStringMethod(String... value) {
25+
}
26+
27+
public void setVarargEnumMethod(MyEnum... value) {
2528
}
2629

2730
public enum MyInnerEnum {

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/testtarget/examples/sameEnum/only/once/Master.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ public void setFirstAttribute(MyEnum value) {
99
*/
1010
public void setSecondAttribute(MyEnum value) {
1111
}
12+
13+
public void setThirdAttribute(MyEnum... varArgsValue) {
14+
}
1215
}

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/testtarget/reflect/FrankAttributeTarget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public boolean isAttributeSetterIs() {
2424
public void setAttributeOnlySetter(String value) {
2525
}
2626

27-
public void setNonAttributeVararg(String ...value) {
27+
public void setAttributeVararg(String... value) {
2828
}
2929

3030
public void setAttributeOnlySetterInt(int value) {

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/wrapper/FrankClass2Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public void getDeclaredMethodsDoesNotIncludeInheritedMethods() throws FrankDocEx
126126
final Set<String> actualMethodNames = new TreeSet<>();
127127
Arrays.asList(declaredMethods).forEach(m -> actualMethodNames.add(m.getName()));
128128
List<String> sortedActualMethodNames = new ArrayList<>(actualMethodNames);
129-
sortedActualMethodNames = sortedActualMethodNames.stream().filter(name -> !name.contains("jacoco")).collect(Collectors.toList());
130-
assertArrayEquals(new String[]{"getMyInnerEnum", "getProtectedStuff", "methodWithoutAnnotations", "myAnnotatedMethod", "setInherited", "setVarargMethod"}, sortedActualMethodNames.toArray());
129+
sortedActualMethodNames = sortedActualMethodNames.stream().filter(name -> !name.contains("jacoco")).toList();
130+
assertArrayEquals(new String[]{"getMyInnerEnum", "getProtectedStuff", "methodWithoutAnnotations", "myAnnotatedMethod", "setInherited", "setVarargEnumMethod", "setVarargStringMethod"}, sortedActualMethodNames.toArray());
131131
}
132132

133133
/**
@@ -147,7 +147,7 @@ public void testGetDeclaredAndInheritedMethods() throws FrankDocException {
147147
.map(FrankMethod::getName)
148148
.filter(name -> !name.contains("jacoco"))
149149
.forEach(methodNames::add);
150-
assertArrayEquals(new String[]{"equals", "getClass", "getInherited", "getMyInnerEnum", "hashCode", "methodWithoutAnnotations", "myAnnotatedMethod", "myMethod", "notify", "notifyAll", "setInherited", "setVarargMethod", "toString", "wait", "withClassValuedAnnotation"}, new ArrayList<>(methodNames).toArray());
150+
assertArrayEquals(new String[]{"equals", "getClass", "getInherited", "getMyInnerEnum", "hashCode", "methodWithoutAnnotations", "myAnnotatedMethod", "myMethod", "notify", "notifyAll", "setInherited", "setVarargEnumMethod", "setVarargStringMethod", "toString", "wait", "withClassValuedAnnotation"}, new ArrayList<>(methodNames).toArray());
151151
// Test we have no duplicates
152152
Map<String, List<FrankMethod>> methodsByName = Arrays.stream(methods)
153153
.filter(m -> methodNames.contains(m.getName()))

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/wrapper/FrankClassTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.util.Arrays;
77
import java.util.List;
8-
import java.util.stream.Collectors;
98

109
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1110
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -39,9 +38,9 @@ public void testGetJavaDoc() {
3938
public void testMethodSequenceIsPreserved() {
4039
List<String> actualMethodNames = Arrays.asList(instance.getDeclaredMethods()).stream()
4140
.map(FrankMethod::getName)
42-
.collect(Collectors.toList());
43-
assertEquals(6, actualMethodNames.size());
44-
String[] expectedMethodNames = new String[] {"setInherited", "setVarargMethod", "getMyInnerEnum", "myAnnotatedMethod", "methodWithoutAnnotations", "getProtectedStuff"};
41+
.toList();
42+
assertEquals(7, actualMethodNames.size());
43+
String[] expectedMethodNames = new String[] {"setInherited", "setVarargStringMethod", "setVarargEnumMethod", "getMyInnerEnum", "myAnnotatedMethod", "methodWithoutAnnotations", "getProtectedStuff"};
4544
assertArrayEquals(expectedMethodNames, actualMethodNames.toArray(new String[] {}));
4645
}
4746

frank-doc-doclet/src/test/java/org/frankframework/frankdoc/wrapper/FrankMethodTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.HashSet;
77
import java.util.List;
88
import java.util.Set;
9-
import java.util.stream.Collectors;
109

1110
import static org.junit.jupiter.api.Assertions.assertEquals;
1211
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -95,15 +94,15 @@ private FrankMethod getMethodFromDeclaredAndInheritedMethods(FrankClass clazz, S
9594
FrankMethod[] methods = clazz.getDeclaredAndInheritedMethods();
9695
List<FrankMethod> getters = Arrays.asList(methods).stream()
9796
.filter(m -> m.getName().equals(methodName))
98-
.collect(Collectors.toList());
97+
.toList();
9998
assertEquals(1, getters.size());
10099
return getters.get(0);
101100
}
102101

103102
@Test
104-
public void whenMethodHasVarargsThenIsVarargs() throws FrankDocException {
103+
public void whenMethodHasStringVarargsThenIsVarargs() throws FrankDocException {
105104
FrankClass clazz = classRepository.findClass(PACKAGE + "Child");
106-
FrankMethod method = TestUtil.getDeclaredMethodOf(clazz, "setVarargMethod");
105+
FrankMethod method = TestUtil.getDeclaredMethodOf(clazz, "setVarargStringMethod");
107106
assertTrue(method.isVarargs());
108107
assertEquals(1, method.getParameterCount());
109108
FrankType parameter = method.getParameterTypes()[0];
@@ -114,6 +113,16 @@ public void whenMethodHasVarargsThenIsVarargs() throws FrankDocException {
114113
assertTrue(stringOrStringArray.contains(parameter.getName()));
115114
}
116115

116+
@Test
117+
public void whenMethodHasEnumVarargsThenIsVarargs() throws FrankDocException {
118+
FrankClass clazz = classRepository.findClass(PACKAGE + "Child");
119+
FrankMethod method = TestUtil.getDeclaredMethodOf(clazz, "setVarargEnumMethod");
120+
assertTrue(method.isVarargs());
121+
assertEquals(1, method.getParameterCount());
122+
FrankType parameter = method.getParameterTypes()[0];
123+
assertEquals("org.frankframework.frankdoc.testtarget.doclet.MyEnum", parameter.getName());
124+
}
125+
117126
@Test
118127
public void whenMethodDoesNotHaveVarargsThenNotVarargs() throws FrankDocException {
119128
FrankClass clazz = classRepository.findClass(PACKAGE + "Child");

0 commit comments

Comments
 (0)