• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.apicommon;
18 
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24 import java.util.concurrent.ConcurrentHashMap;
25 
26 /** Representation of a method in the API with parameters (arguments) and a return value. */
27 public 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 Map<String, Boolean> mCoveredWith = new ConcurrentHashMap<>();
47 
48     // A list of CTS test methods that call this API method.
49     private final Map<String, TestMethodInfo> mCoveredTests = new ConcurrentHashMap<>();
50 
ApiMethod( String name, List<String> parameterTypes, String returnType, boolean deprecated, String visibility, boolean staticMethod, boolean finalMethod, boolean abstractMethod)51     public ApiMethod(
52             String name,
53             List<String> parameterTypes,
54             String returnType,
55             boolean deprecated,
56             String visibility,
57             boolean staticMethod,
58             boolean finalMethod,
59             boolean abstractMethod) {
60         mName = name;
61         mParameterTypes = new ArrayList<String>(parameterTypes);
62         mReturnType = returnType;
63         mDeprecated = deprecated;
64         mVisibility = visibility;
65         mStaticMethod = staticMethod;
66         mFinalMethod = finalMethod;
67         mAbstractMethod = abstractMethod;
68     }
69 
70     @Override
compareTo(ApiMethod another)71     public int compareTo(ApiMethod another) {
72         return mName.compareTo(another.mName);
73     }
74 
getName()75     public String getName() {
76         return mName;
77     }
78 
getParameterTypes()79     public List<String> getParameterTypes() {
80         return Collections.unmodifiableList(mParameterTypes);
81     }
82 
getReturnType()83     public String getReturnType() {
84         return mReturnType;
85     }
86 
isDeprecated()87     public boolean isDeprecated() {
88         return mDeprecated;
89     }
90 
isCovered()91     public boolean isCovered() {
92         return !mCoveredWith.isEmpty();
93     }
94 
getVisibility()95     public String getVisibility() {
96         return mVisibility;
97     }
98 
isAbstractMethod()99     public boolean isAbstractMethod() {
100         return mAbstractMethod;
101     }
102 
isStaticMethod()103     public boolean isStaticMethod() {
104         return mStaticMethod;
105     }
106 
isFinalMethod()107     public boolean isFinalMethod() {
108         return mFinalMethod;
109     }
110 
getCoveredWith()111     public Set<String> getCoveredWith() {
112         return mCoveredWith.keySet();
113     }
114 
getCoveredTests()115     public List<TestMethodInfo> getCoveredTests() {
116         return mCoveredTests.values().stream().toList();
117     }
118 
setCovered(String coveredWithModule)119     public void setCovered(String coveredWithModule) {
120         if (coveredWithModule.endsWith(".apk")) {
121             coveredWithModule = coveredWithModule.substring(0, coveredWithModule.length() - 4);
122         }
123 
124         mCoveredWith.put(coveredWithModule, true);
125     }
126 
127     /** Adds a test method that is calling this API. */
setCoveredTest(TestMethodInfo testMethodInfo)128     public void setCoveredTest(TestMethodInfo testMethodInfo) {
129         mCoveredTests.put(testMethodInfo.signature(), testMethodInfo);
130     }
131 }
132