1
2
3
4
5 package com.qulice.checkstyle.parameters;
6
7 import com.puppycrawl.tools.checkstyle.api.DetailAST;
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.List;
11
12
13
14
15
16
17
18 public class Parameters {
19
20
21
22
23 private final DetailAST node;
24
25
26
27
28
29 private final int parent;
30
31
32
33
34
35 private final int children;
36
37
38
39
40
41
42
43 public Parameters(
44 final DetailAST node, final int parent, final int children
45 ) {
46 this.node = node;
47 this.parent = parent;
48 this.children = children;
49 }
50
51
52
53
54
55 public final int count() {
56 final int result;
57 final DetailAST params = this.node.findFirstToken(this.parent);
58 if (params == null) {
59 result = 0;
60 } else {
61 result = params.getChildCount(this.children);
62 }
63 return result;
64 }
65
66
67
68
69
70 public final List<DetailAST> parameters() {
71 final List<DetailAST> result;
72 final int count = this.count();
73 if (count == 0) {
74 result = Collections.emptyList();
75 } else {
76 final DetailAST params = this.node.findFirstToken(this.parent);
77 result = new ArrayList<>(count);
78 DetailAST child = params.getFirstChild();
79 while (child != null) {
80 if (child.getType() == this.children) {
81 result.add(child);
82 }
83 child = child.getNextSibling();
84 }
85 }
86 return result;
87 }
88 }