1 /*
2 * Copyright 2014 - 2020 Rafael Winterhalter
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.bytebuddy.matcher;
17
18 import net.bytebuddy.build.HashCodeAndEqualsPlugin;
19 import net.bytebuddy.description.method.MethodDescription;
20 import net.bytebuddy.description.method.ParameterDescription;
21 import net.bytebuddy.description.method.ParameterList;
22
23 /**
24 * An element matcher that matches a method's parameters.
25 *
26 * @param <T> The type of the matched entity.
27 */
28 @HashCodeAndEqualsPlugin.Enhance
29 public class MethodParametersMatcher<T extends MethodDescription> extends ElementMatcher.Junction.AbstractBase<T> {
30
31 /**
32 * The matcher to apply to the parameters.
33 */
34 private final ElementMatcher<? super ParameterList<?>> matcher;
35
36 /**
37 * Creates a new matcher for a method's parameters.
38 *
39 * @param matcher The matcher to apply to the parameters.
40 */
41 public MethodParametersMatcher(ElementMatcher<? super ParameterList<? extends ParameterDescription>> matcher) {
42 this.matcher = matcher;
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 public boolean matches(T target) {
49 return matcher.matches(target.getParameters());
50 }
51
52 @Override
53 public String toString() {
54 return "hasParameter(" + matcher + ")";
55 }
56 }
57