|
17 | 17 | package org.sonar.java.checks; |
18 | 18 |
|
19 | 19 | import java.util.List; |
20 | | -import java.util.function.Predicate; |
21 | 20 |
|
22 | 21 | import org.sonar.check.Rule; |
23 | 22 | import org.sonar.java.matcher.TreeMatcher; |
|
32 | 31 | import org.sonar.plugins.java.api.tree.MethodInvocationTree; |
33 | 32 | import org.sonar.plugins.java.api.tree.Tree; |
34 | 33 |
|
35 | | -import javax.annotation.Nullable; |
36 | | - |
37 | 34 | import static org.sonar.java.matcher.TreeMatcher.calls; |
38 | 35 | import static org.sonar.java.matcher.TreeMatcher.invokedOn; |
39 | 36 | import static org.sonar.java.matcher.TreeMatcher.isIdentifier; |
@@ -107,55 +104,6 @@ public class ClassNameInClassTransformCheck extends IssuableSubscriptionVisitor |
107 | 104 | .addWithoutParametersMatcher() |
108 | 105 | .build(); |
109 | 106 |
|
110 | | - static class ExpressionMatcher { |
111 | | - @Nullable |
112 | | - private final ExpressionTree expressionTree; |
113 | | - |
114 | | - ExpressionMatcher(@Nullable ExpressionTree expressionTree) { |
115 | | - this.expressionTree = expressionTree; |
116 | | - } |
117 | | - |
118 | | - CallMatcher calls(MethodMatchers methodMatchers) { |
119 | | - if (expressionTree instanceof MethodInvocationTree mit && methodMatchers.matches(mit)) { |
120 | | - return new CallMatcher(mit); |
121 | | - } |
122 | | - return new CallMatcher(null); |
123 | | - } |
124 | | - |
125 | | - boolean isIdentifier(IdentifierTree identifier) { |
126 | | - if (expressionTree instanceof IdentifierTree id) { |
127 | | - return id.symbol().equals(identifier.symbol()); |
128 | | - } |
129 | | - return false; |
130 | | - } |
131 | | - |
132 | | - boolean matches(Predicate<ExpressionTree> predicate) { |
133 | | - return expressionTree != null && predicate.test(expressionTree); |
134 | | - } |
135 | | - } |
136 | | - |
137 | | - static class CallMatcher { |
138 | | - |
139 | | - /** When {@link #methodInvocationTree} is null, the matcher doesn't match anything. */ |
140 | | - @Nullable |
141 | | - private final MethodInvocationTree methodInvocationTree; |
142 | | - |
143 | | - CallMatcher(@Nullable MethodInvocationTree methodInvocationTree) { |
144 | | - this.methodInvocationTree = methodInvocationTree; |
145 | | - } |
146 | | - |
147 | | - ExpressionMatcher withArgument(int argumentIndex) { |
148 | | - if (methodInvocationTree != null && methodInvocationTree.arguments().size() >= argumentIndex) { |
149 | | - return new ExpressionMatcher(methodInvocationTree.arguments().get(argumentIndex)); |
150 | | - } |
151 | | - return new ExpressionMatcher(null); |
152 | | - } |
153 | | - } |
154 | | - |
155 | | - static ExpressionMatcher check(ExpressionTree expression) { |
156 | | - return new ExpressionMatcher(expression); |
157 | | - } |
158 | | - |
159 | 107 | @Override |
160 | 108 | public List<Tree.Kind> nodesToVisit() { |
161 | 109 | return List.of(Tree.Kind.METHOD_INVOCATION); |
|
0 commit comments