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
19 public class Arguments {
20
21
22
23
24 private final Parameters parameters;
25
26
27
28
29
30 public Arguments(final DetailAST node) {
31 this(
32 new Parameters(
33 node, TokenTypes.PARAMETERS, TokenTypes.PARAMETER_DEF
34 )
35 );
36 }
37
38
39
40
41
42 public Arguments(final Parameters parameters) {
43 this.parameters = parameters;
44 }
45
46
47
48
49
50 public final int count() {
51 return this.parameters.count();
52 }
53
54
55
56
57
58
59
60
61 public final void checkOrder(
62 final List<JavadocTag> tags, final Consumer<JavadocTag> consumer
63 ) {
64 final List<DetailAST> params = this.parameters.parameters();
65 if (tags.size() < params.size()) {
66 throw new IllegalStateException(
67 "Number of Javadoc parameters does not match the number of arguments"
68 );
69 }
70 final Iterator<JavadocTag> iterator = tags.listIterator();
71 for (final DetailAST param : params) {
72 final String type =
73 param.findFirstToken(TokenTypes.IDENT).getText();
74 final JavadocTag tag = iterator.next();
75 final String arg = tag.getFirstArg();
76 if (!arg.equals(type)) {
77 consumer.accept(tag);
78 }
79 }
80 }
81 }