1
2
3
4
5 package com.qulice.checkstyle.parameters;
6
7 import com.puppycrawl.tools.checkstyle.api.DetailAST;
8 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
9 import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTag;
10 import java.util.Iterator;
11 import java.util.List;
12 import java.util.function.Consumer;
13
14
15
16
17
18 public class Arguments {
19
20
21
22
23 private final Parameters parameters;
24
25
26
27
28
29 public Arguments(final DetailAST node) {
30 this(
31 new Parameters(
32 node, TokenTypes.PARAMETERS, TokenTypes.PARAMETER_DEF
33 )
34 );
35 }
36
37
38
39
40
41 public Arguments(final Parameters parameters) {
42 this.parameters = parameters;
43 }
44
45
46
47
48
49 public final int count() {
50 return this.parameters.count();
51 }
52
53
54
55
56
57
58
59
60 public final void checkOrder(
61 final List<JavadocTag> tags, final Consumer<JavadocTag> consumer
62 ) {
63 final List<DetailAST> params = this.parameters.parameters();
64 if (tags.size() < params.size()) {
65 throw new IllegalStateException(
66 "Number of Javadoc parameters does not match the number of arguments"
67 );
68 }
69 final Iterator<JavadocTag> iterator = tags.listIterator();
70 for (final DetailAST param : params) {
71 final String type =
72 param.findFirstToken(TokenTypes.IDENT).getText();
73 final JavadocTag tag = iterator.next();
74 final String arg = tag.getFirstArg();
75 if (!arg.equals(type)) {
76 consumer.accept(tag);
77 }
78 }
79 }
80 }