1 /* 2 * Copyright (C) 2009 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.dexdeps; 18 19 public class MethodRef { 20 private String mDeclClass, mReturnType, mMethodName; 21 private String[] mArgTypes; 22 23 /** 24 * Initializes a new field reference. 25 */ MethodRef(String declClass, String[] argTypes, String returnType, String methodName)26 public MethodRef(String declClass, String[] argTypes, String returnType, 27 String methodName) { 28 mDeclClass = declClass; 29 mArgTypes = argTypes; 30 mReturnType = returnType; 31 mMethodName = methodName; 32 } 33 34 /** 35 * Gets the name of the method's declaring class. 36 */ getDeclClassName()37 public String getDeclClassName() { 38 return mDeclClass; 39 } 40 41 /** 42 * Gets the method's descriptor. 43 */ getDescriptor()44 public String getDescriptor() { 45 return descriptorFromProtoArray(mArgTypes, mReturnType); 46 } 47 48 /** 49 * Gets the method's name. 50 */ getName()51 public String getName() { 52 return mMethodName; 53 } 54 55 /** 56 * Gets an array of method argument types. 57 */ getArgumentTypeNames()58 public String[] getArgumentTypeNames() { 59 return mArgTypes; 60 } 61 62 /** 63 * Gets the method's return type. Examples: "Ljava/lang/String;", "[I". 64 */ getReturnTypeName()65 public String getReturnTypeName() { 66 return mReturnType; 67 } 68 69 /** 70 * Returns the method descriptor, given the argument and return type 71 * prototype strings. 72 */ descriptorFromProtoArray(String[] protos, String returnType)73 private static String descriptorFromProtoArray(String[] protos, 74 String returnType) { 75 StringBuilder builder = new StringBuilder(); 76 77 builder.append("("); 78 for (int i = 0; i < protos.length; i++) { 79 builder.append(protos[i]); 80 } 81 82 builder.append(")"); 83 builder.append(returnType); 84 85 return builder.toString(); 86 } 87 } 88