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