1 /*
2  * Copyright (C) 2008 The Android Open Source Project
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 
17 package com.android.tools.layoutlib.create;
18 
19 
20 /**
21  * An adapter to make it easier to use {@link MethodListener}.
22  * <p/>
23  * The adapter calls the void {@link #onInvokeV(String, boolean, Object)} listener
24  * for all types (I, L, F, D and A), returning 0 or null as appropriate.
25  */
26 public class MethodAdapter implements MethodListener {
27     /**
28      * A stub method is being invoked.
29      * <p/>
30      * Known limitation: caller arguments are not available.
31      *
32      * @param signature The signature of the method being invoked, composed of the
33      *                  binary class name followed by the method descriptor (aka argument
34      *                  types). Example: "com/foo/MyClass/InnerClass/printInt(I)V".
35      * @param isNative True if the method was a native method.
36      * @param caller The calling object. Null for static methods, "this" for instance methods.
37      */
38     @Override
onInvokeV(String signature, boolean isNative, Object caller)39     public void onInvokeV(String signature, boolean isNative, Object caller) {
40     }
41 
42     /**
43      * Same as {@link #onInvokeV(String, boolean, Object)} but returns an integer or similar.
44      * @see #onInvokeV(String, boolean, Object)
45      * @return an integer, or a boolean, or a short or a byte.
46      */
47     @Override
onInvokeI(String signature, boolean isNative, Object caller)48     public int onInvokeI(String signature, boolean isNative, Object caller) {
49         onInvokeV(signature, isNative, caller);
50         return 0;
51     }
52 
53     /**
54      * Same as {@link #onInvokeV(String, boolean, Object)} but returns a long.
55      * @see #onInvokeV(String, boolean, Object)
56      * @return a long.
57      */
58     @Override
onInvokeL(String signature, boolean isNative, Object caller)59     public long onInvokeL(String signature, boolean isNative, Object caller) {
60         onInvokeV(signature, isNative, caller);
61         return 0;
62     }
63 
64     /**
65      * Same as {@link #onInvokeV(String, boolean, Object)} but returns a float.
66      * @see #onInvokeV(String, boolean, Object)
67      * @return a float.
68      */
69     @Override
onInvokeF(String signature, boolean isNative, Object caller)70     public float onInvokeF(String signature, boolean isNative, Object caller) {
71         onInvokeV(signature, isNative, caller);
72         return 0;
73     }
74 
75     /**
76      * Same as {@link #onInvokeV(String, boolean, Object)} but returns a double.
77      * @see #onInvokeV(String, boolean, Object)
78      * @return a double.
79      */
80     @Override
onInvokeD(String signature, boolean isNative, Object caller)81     public double onInvokeD(String signature, boolean isNative, Object caller) {
82         onInvokeV(signature, isNative, caller);
83         return 0;
84     }
85 
86     /**
87      * Same as {@link #onInvokeV(String, boolean, Object)} but returns an object.
88      * @see #onInvokeV(String, boolean, Object)
89      * @return an object.
90      */
91     @Override
onInvokeA(String signature, boolean isNative, Object caller)92     public Object onInvokeA(String signature, boolean isNative, Object caller) {
93         onInvokeV(signature, isNative, caller);
94         return null;
95     }
96 }
97 
98