1 /*
2  * Copyright (C) 2022 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.traceinjection;
18 
19 /**
20  * Configuration data for trace method injection.
21  */
22 public class TraceInjectionConfiguration {
23     public final String annotation;
24     public final String startMethodClass;
25     public final String startMethodName;
26     public final String endMethodClass;
27     public final String endMethodName;
28 
TraceInjectionConfiguration(String annotation, String startMethod, String endMethod)29     public TraceInjectionConfiguration(String annotation, String startMethod, String endMethod) {
30         this.annotation = annotation;
31         String[] startMethodComponents = parseMethod(startMethod);
32         String[] endMethodComponents = parseMethod(endMethod);
33         startMethodClass = startMethodComponents[0];
34         startMethodName = startMethodComponents[1];
35         endMethodClass = endMethodComponents[0];
36         endMethodName = endMethodComponents[1];
37     }
38 
toString()39     public String toString() {
40         return "TraceInjectionParams{annotation=" + annotation
41                 + ", startMethod=" + startMethodClass + "." + startMethodName
42                 + ", endMethod=" + endMethodClass + "." + endMethodName + "}";
43     }
44 
parseMethod(String method)45     private static String[] parseMethod(String method) {
46         String[] methodComponents = method.split("\\.");
47         if (methodComponents.length != 2) {
48             throw new IllegalArgumentException("Invalid method descriptor: " + method);
49         }
50         return methodComponents;
51     }
52 }
53