Skip to content

Commit a0752ca

Browse files
committed
Add ParamName annotation instead of using -parameters javac arg
1 parent 119409e commit a0752ca

File tree

40 files changed

+377
-257
lines changed

40 files changed

+377
-257
lines changed

cdtp-definition-builder/src/main/java/com/github/kklisura/cdtp/definition/builder/support/java/builder/impl/JavaInterfaceBuilderImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ public void addMethod(String name, String description, List<MethodParam> methodP
116116
methodParam.getName());
117117

118118
if (CollectionUtils.isNotEmpty(methodParam.getAnnotations())) {
119-
for (String annotation : methodParam.getAnnotations()) {
120-
parameter.addMarkerAnnotation(annotation);
119+
for (MethodParam.Annotation annotation : methodParam.getAnnotations()) {
120+
if (StringUtils.isNotEmpty(annotation.getValue())) {
121+
parameter.addSingleMemberAnnotation(annotation.getName(),
122+
new StringLiteralExpr(annotation.getValue()));
123+
} else {
124+
parameter.addMarkerAnnotation(annotation.getName());
125+
}
121126

122-
if (!DEPRECATED_ANNOTATION.equals(annotation)) {
123-
addImport(annotationsPackage, annotation);
127+
if (!DEPRECATED_ANNOTATION.equals(annotation.getName())) {
128+
addImport(annotationsPackage, annotation.getName());
124129
}
125130
}
126131
}

cdtp-definition-builder/src/main/java/com/github/kklisura/cdtp/definition/builder/support/java/builder/support/MethodParam.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,51 @@ public class MethodParam {
1717

1818
private String name;
1919

20-
private List<String> annotations;
20+
private List<Annotation> annotations;
21+
22+
/**
23+
* Method param annotation. Supports both Marker and simple string argument annotation.
24+
*/
25+
public static class Annotation {
26+
private String name;
27+
private String value;
28+
29+
/**
30+
* Instantiates a new Method param annotation.
31+
*
32+
* @param name Annotation name.
33+
* @param value Annotation value for simple string argument annotation.
34+
*/
35+
public Annotation(String name, String value) {
36+
this.name = name;
37+
this.value = value;
38+
}
39+
40+
/**
41+
* Instantiates a new Method param annotation.
42+
*
43+
* @param name Annotation name.
44+
*/
45+
public Annotation(String name) {
46+
this.name = name;
47+
}
48+
49+
/**
50+
* Gets name.
51+
*
52+
* @return Annotation name.
53+
*/
54+
public String getName() {
55+
return name;
56+
}
57+
58+
/**
59+
* Gets annotation value.
60+
*
61+
* @return Annotation value.
62+
*/
63+
public String getValue() {
64+
return value;
65+
}
66+
}
2167
}

cdtp-definition-builder/src/main/java/com/github/kklisura/cdtp/definition/builder/support/protocol/builder/CommandBuilder.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,20 @@ private List<MethodParam> buildMethodParams(Command command, Domain domain, Java
183183
methodParam.setAnnotations(new ArrayList<>());
184184

185185
if (Boolean.TRUE.equals(property.getDeprecated())) {
186-
methodParam.getAnnotations().add(DEPRECATED_ANNOTATION);
186+
methodParam.getAnnotations().add(new MethodParam.Annotation(DEPRECATED_ANNOTATION));
187187
}
188188

189189
if (Boolean.TRUE.equals(property.getExperimental())) {
190-
methodParam.getAnnotations().add(EXPERIMENTAL_ANNOTATION);
190+
methodParam.getAnnotations().add(new MethodParam.Annotation(EXPERIMENTAL_ANNOTATION));
191191
}
192192

193193
if (Boolean.TRUE.equals(property.getOptional())) {
194-
methodParam.getAnnotations().add(OPTIONAL_ANNOTATION);
194+
methodParam.getAnnotations().add(new MethodParam.Annotation(OPTIONAL_ANNOTATION));
195195
}
196196

197+
methodParam.getAnnotations().add(new MethodParam.Annotation(PARAM_NAME_ANNOTATION,
198+
methodParam.getName()));
199+
197200
methodParams.add(methodParam);
198201
}
199202
}

cdtp-definition-builder/src/main/java/com/github/kklisura/cdtp/definition/builder/support/protocol/builder/TypesBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class TypesBuilder {
6767
public static final String EXPERIMENTAL_ANNOTATION = "Experimental";
6868
public static final String RETURNS_ANNOTATION = "Returns";
6969
public static final String OPTIONAL_ANNOTATION = "Optional";
70+
public static final String PARAM_NAME_ANNOTATION = "ParamName";
7071

7172
private static final Map<Class, String> TYPE_TO_JAVA_TYPE_MAP = new HashMap<>();
7273
private static final Map<Class, String> PROPERTY_TO_JAVA_TYPE_MAP = new HashMap<>();

cdtp-definition-builder/src/test/java/com/github/kklisura/cdtp/definition/builder/support/java/builder/impl/JavaInterfaceBuilderImplTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ public void testBasicInterfaceWithSimpleMethod2() throws IOException {
198198
final MethodParam param2 = new MethodParam();
199199
param2.setType("String");
200200
param2.setName("param2");
201-
param2.setAnnotations(Arrays.asList("Annotation", "Annotation1", "Deprecated"));
201+
param2.setAnnotations(Arrays.asList(createAnnotation("Annotation"), createAnnotation("Annotation1"),
202+
createAnnotation("Deprecated"), createAnnotation("ParamValue", "paramValueName")));
202203

203204
interfaceBuilder.addMethod("someMethod1", "", Arrays.asList(param1, param2), "String");
204205
interfaceBuilder.addMethodAnnotation("someMethod1", "Annotation");
@@ -212,16 +213,24 @@ public void testBasicInterfaceWithSimpleMethod2() throws IOException {
212213
"\n" +
213214
"import com.github.kklisura.annotations.Annotation;\n" +
214215
"import com.github.kklisura.annotations.Annotation1;\n" +
216+
"import com.github.kklisura.annotations.ParamValue;\n" +
215217
"import com.github.kklisura.annotations.Annotation2;\n" +
216218
"\n" +
217219
"public interface InterfaceTest {\n" +
218220
"\n" +
219221
" @Annotation\n" +
220222
" @Annotation2(\"param\")\n" +
221-
" String someMethod1(Integer param1, @Annotation @Annotation1 @Deprecated String param2);\n" +
223+
" String someMethod1(Integer param1, @Annotation @Annotation1 @Deprecated @ParamValue(\"paramValueName\") String param2);\n" +
222224
"}\n", compilationUnitCapture.getValue().toString());
223225

224226
verifyAll();
225227
}
226228

229+
private MethodParam.Annotation createAnnotation(String name) {
230+
return new MethodParam.Annotation(name);
231+
}
232+
233+
private MethodParam.Annotation createAnnotation(String name, String value) {
234+
return new MethodParam.Annotation(name, value);
235+
}
227236
}

cdtp-definition-builder/src/test/java/com/github/kklisura/cdtp/definition/builder/support/protocol/builder/CommandBuilderTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,15 @@ public void testBuildCommandWithMethodWithSimpleParams() {
193193
assertEquals(2, params.size());
194194
Assert.assertEquals(stringParam.getName(), params.get(0).getName());
195195
assertEquals("String", params.get(0).getType());
196-
assertEquals("Deprecated", params.get(0).getAnnotations().get(0));
196+
assertEquals("Deprecated", params.get(0).getAnnotations().get(0).getName());
197+
assertEquals("ParamName", params.get(0).getAnnotations().get(1).getName());
198+
assertEquals(stringParam.getName(), params.get(0).getAnnotations().get(1).getValue());
197199

198200
assertEquals(numberParam.getName(), params.get(1).getName());
199201
assertEquals("Double", params.get(1).getType());
200-
assertEquals("Experimental", params.get(1).getAnnotations().get(0));
202+
assertEquals("Experimental", params.get(1).getAnnotations().get(0).getName());
203+
assertEquals("ParamName", params.get(1).getAnnotations().get(1).getName());
204+
assertEquals(numberParam.getName(), params.get(1).getAnnotations().get(1).getValue());
201205
}
202206

203207
@Test
@@ -275,12 +279,16 @@ public void testBuildCommandWithMethodWithComplexParams() {
275279
assertEquals(2, params.size());
276280
assertEquals(refParam.getName(), params.get(0).getName());
277281
assertEquals("TestRef", params.get(0).getType());
278-
assertEquals("Deprecated", params.get(0).getAnnotations().get(0));
282+
assertEquals("Deprecated", params.get(0).getAnnotations().get(0).getName());
283+
assertEquals("ParamName", params.get(0).getAnnotations().get(1).getName());
284+
assertEquals(refParam.getName(), params.get(0).getAnnotations().get(1).getValue());
279285

280286
Assert.assertEquals(arrayProperty.getName(), params.get(1).getName());
281287
assertEquals("List<EnumParam1>", params.get(1).getType());
282-
assertEquals("Experimental", params.get(1).getAnnotations().get(0));
283-
assertEquals("Optional", params.get(1).getAnnotations().get(1));
288+
assertEquals("Experimental", params.get(1).getAnnotations().get(0).getName());
289+
assertEquals("Optional", params.get(1).getAnnotations().get(1).getName());
290+
assertEquals("ParamName", params.get(1).getAnnotations().get(2).getName());
291+
assertEquals(arrayProperty.getName(), params.get(1).getAnnotations().get(2).getValue());
284292
}
285293

286294
@Test
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.kklisura.cdtp.protocol.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Param value.
10+
*/
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Target(value={ElementType.PARAMETER})
13+
public @interface ParamName {
14+
String value();
15+
}

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/protocol/commands/Accessibility.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.kklisura.cdtp.protocol.annotations.Experimental;
44
import com.github.kklisura.cdtp.protocol.annotations.Optional;
5+
import com.github.kklisura.cdtp.protocol.annotations.ParamName;
56
import com.github.kklisura.cdtp.protocol.annotations.Returns;
67
import com.github.kklisura.cdtp.protocol.types.accessibility.AXNode;
78
import java.util.List;
@@ -14,5 +15,5 @@ public interface Accessibility {
1415
*/
1516
@Experimental
1617
@Returns("nodes")
17-
List<AXNode> getPartialAXTree(Integer nodeId, @Optional Boolean fetchRelatives);
18+
List<AXNode> getPartialAXTree(@ParamName("nodeId") Integer nodeId, @Optional @ParamName("fetchRelatives") Boolean fetchRelatives);
1819
}

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/protocol/commands/Animation.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.kklisura.cdtp.protocol.commands;
22

33
import com.github.kklisura.cdtp.protocol.annotations.Experimental;
4+
import com.github.kklisura.cdtp.protocol.annotations.ParamName;
45
import com.github.kklisura.cdtp.protocol.annotations.Returns;
56
import com.github.kklisura.cdtp.protocol.types.runtime.RemoteObject;
67
import java.util.List;
@@ -27,37 +28,37 @@ public interface Animation {
2728
/**
2829
* Sets the playback rate of the document timeline.
2930
*/
30-
void setPlaybackRate(Double playbackRate);
31+
void setPlaybackRate(@ParamName("playbackRate") Double playbackRate);
3132

3233
/**
3334
* Returns the current time of the an animation.
3435
*/
3536
@Returns("currentTime")
36-
Double getCurrentTime(String id);
37+
Double getCurrentTime(@ParamName("id") String id);
3738

3839
/**
3940
* Sets the paused state of a set of animations.
4041
*/
41-
void setPaused(List<String> animations, Boolean paused);
42+
void setPaused(@ParamName("animations") List<String> animations, @ParamName("paused") Boolean paused);
4243

4344
/**
4445
* Sets the timing of an animation node.
4546
*/
46-
void setTiming(String animationId, Double duration, Double delay);
47+
void setTiming(@ParamName("animationId") String animationId, @ParamName("duration") Double duration, @ParamName("delay") Double delay);
4748

4849
/**
4950
* Seek a set of animations to a particular time within each animation.
5051
*/
51-
void seekAnimations(List<String> animations, Double currentTime);
52+
void seekAnimations(@ParamName("animations") List<String> animations, @ParamName("currentTime") Double currentTime);
5253

5354
/**
5455
* Releases a set of animations to no longer be manipulated.
5556
*/
56-
void releaseAnimations(List<String> animations);
57+
void releaseAnimations(@ParamName("animations") List<String> animations);
5758

5859
/**
5960
* Gets the remote object of the Animation.
6061
*/
6162
@Returns("remoteObject")
62-
RemoteObject resolveAnimation(String animationId);
63+
RemoteObject resolveAnimation(@ParamName("animationId") String animationId);
6364
}

cdtp-java-client/src/main/java/com/github/kklisura/cdtp/protocol/commands/ApplicationCache.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.kklisura.cdtp.protocol.commands;
22

33
import com.github.kklisura.cdtp.protocol.annotations.Experimental;
4+
import com.github.kklisura.cdtp.protocol.annotations.ParamName;
45
import com.github.kklisura.cdtp.protocol.annotations.Returns;
56
import com.github.kklisura.cdtp.protocol.types.applicationcache.FrameWithManifest;
67
import java.util.List;
@@ -23,11 +24,11 @@ public interface ApplicationCache {
2324
* Returns manifest URL for document in the given frame.
2425
*/
2526
@Returns("manifestURL")
26-
String getManifestForFrame(String frameId);
27+
String getManifestForFrame(@ParamName("frameId") String frameId);
2728

2829
/**
2930
* Returns relevant application cache data for the document in given frame.
3031
*/
3132
@Returns("applicationCache")
32-
com.github.kklisura.cdtp.protocol.types.applicationcache.ApplicationCache getApplicationCacheForFrame(String frameId);
33+
com.github.kklisura.cdtp.protocol.types.applicationcache.ApplicationCache getApplicationCacheForFrame(@ParamName("frameId") String frameId);
3334
}

0 commit comments

Comments
 (0)