1 /* 2 * Copyright (C) 2010 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.cts.apicoverage; 18 19 import java.util.ArrayList; 20 import java.util.Collections; 21 import java.util.HashSet; 22 import java.util.List; 23 import java.util.Map; 24 import java.util.Set; 25 import java.util.concurrent.ConcurrentHashMap; 26 27 28 /** Representation of a method in the API with parameters (arguments) and a return value. */ 29 class ApiMethod implements Comparable<ApiMethod> { 30 31 private final String mName; 32 33 private final List<String> mParameterTypes; 34 35 private final String mReturnType; 36 37 private final boolean mDeprecated; 38 39 private final String mVisibility; 40 41 private final boolean mStaticMethod; 42 43 private final boolean mFinalMethod; 44 45 private final boolean mAbstractMethod; 46 47 // A list of test APKs (aka CTS modules) that use this method. 48 private final Map<String, Boolean> mCoveredWith = new ConcurrentHashMap<>(); 49 ApiMethod( String name, List<String> parameterTypes, String returnType, boolean deprecated, String visibility, boolean staticMethod, boolean finalMethod, boolean abstractMethod)50 ApiMethod( 51 String name, 52 List<String> parameterTypes, 53 String returnType, 54 boolean deprecated, 55 String visibility, 56 boolean staticMethod, 57 boolean finalMethod, 58 boolean abstractMethod) { 59 mName = name; 60 mParameterTypes = new ArrayList<String>(parameterTypes); 61 mReturnType = returnType; 62 mDeprecated = deprecated; 63 mVisibility = visibility; 64 mStaticMethod = staticMethod; 65 mFinalMethod = finalMethod; 66 mAbstractMethod = abstractMethod; 67 } 68 69 @Override compareTo(ApiMethod another)70 public int compareTo(ApiMethod another) { 71 return mName.compareTo(another.mName); 72 } 73 getName()74 public String getName() { 75 return mName; 76 } 77 getParameterTypes()78 public List<String> getParameterTypes() { 79 return Collections.unmodifiableList(mParameterTypes); 80 } 81 getReturnType()82 public String getReturnType() { 83 return mReturnType; 84 } 85 isDeprecated()86 public boolean isDeprecated() { 87 return mDeprecated; 88 } 89 isCovered()90 public boolean isCovered() { 91 return !mCoveredWith.isEmpty(); 92 } 93 getVisibility()94 public String getVisibility() { return mVisibility; } 95 isAbstractMethod()96 public boolean isAbstractMethod() { return mAbstractMethod; } 97 isStaticMethod()98 public boolean isStaticMethod() { return mStaticMethod; } 99 isFinalMethod()100 public boolean isFinalMethod() { return mFinalMethod; } 101 getCoveredWith()102 public Set<String> getCoveredWith() { return mCoveredWith.keySet(); } 103 setCovered(String coveredWithModule)104 public void setCovered(String coveredWithModule) { 105 if (coveredWithModule.endsWith(".apk")) { 106 coveredWithModule = coveredWithModule.substring(0, coveredWithModule.length() - 4); 107 } 108 109 mCoveredWith.put(coveredWithModule, true); 110 } 111 } 112