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