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.implementation.bind;
17
18 import net.bytebuddy.description.method.MethodDescription;
19
20 /**
21  * This {@link net.bytebuddy.implementation.bind.MethodDelegationBinder.AmbiguityResolver} selects
22  * the method with more arguments. If two methods have equally many arguments, the resolution is ambiguous.
23  */

24 public enum ParameterLengthResolver implements MethodDelegationBinder.AmbiguityResolver {
25
26     /**
27      * The singleton instance.
28      */

29     INSTANCE;
30
31     /**
32      * {@inheritDoc}
33      */

34     public Resolution resolve(MethodDescription source,
35                               MethodDelegationBinder.MethodBinding left,
36                               MethodDelegationBinder.MethodBinding right) {
37         int leftLength = left.getTarget().getParameters().size();
38         int rightLength = right.getTarget().getParameters().size();
39         if (leftLength == rightLength) {
40             return Resolution.AMBIGUOUS;
41         } else if (leftLength < rightLength) {
42             return Resolution.RIGHT;
43         } else {
44             return Resolution.LEFT;
45         }
46     }
47 }
48