• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      */
onInvokeV(String signature, boolean isNative, Object caller)38     public void onInvokeV(String signature, boolean isNative, Object caller) {
39     }
40 
41     /**
42      * Same as {@link #onInvokeV(String, boolean, Object)} but returns an integer or similar.
43      * @see #onInvokeV(String, boolean, Object)
44      * @return an integer, or a boolean, or a short or a byte.
45      */
onInvokeI(String signature, boolean isNative, Object caller)46     public int onInvokeI(String signature, boolean isNative, Object caller) {
47         onInvokeV(signature, isNative, caller);
48         return 0;
49     }
50 
51     /**
52      * Same as {@link #onInvokeV(String, boolean, Object)} but returns a long.
53      * @see #onInvokeV(String, boolean, Object)
54      * @return a long.
55      */
onInvokeL(String signature, boolean isNative, Object caller)56     public long onInvokeL(String signature, boolean isNative, Object caller) {
57         onInvokeV(signature, isNative, caller);
58         return 0;
59     }
60 
61     /**
62      * Same as {@link #onInvokeV(String, boolean, Object)} but returns a float.
63      * @see #onInvokeV(String, boolean, Object)
64      * @return a float.
65      */
onInvokeF(String signature, boolean isNative, Object caller)66     public float onInvokeF(String signature, boolean isNative, Object caller) {
67         onInvokeV(signature, isNative, caller);
68         return 0;
69     }
70 
71     /**
72      * Same as {@link #onInvokeV(String, boolean, Object)} but returns a double.
73      * @see #onInvokeV(String, boolean, Object)
74      * @return a double.
75      */
onInvokeD(String signature, boolean isNative, Object caller)76     public double onInvokeD(String signature, boolean isNative, Object caller) {
77         onInvokeV(signature, isNative, caller);
78         return 0;
79     }
80 
81     /**
82      * Same as {@link #onInvokeV(String, boolean, Object)} but returns an object.
83      * @see #onInvokeV(String, boolean, Object)
84      * @return an object.
85      */
onInvokeA(String signature, boolean isNative, Object caller)86     public Object onInvokeA(String signature, boolean isNative, Object caller) {
87         onInvokeV(signature, isNative, caller);
88         return null;
89     }
90 }
91 
92