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.tools.layoutlib.create;
18 
19 import org.objectweb.asm.ClassVisitor;
20 
21 import java.util.Map;
22 import java.util.Set;
23 
24 /**
25  * Interface describing the work to be done by {@link AsmGenerator}.
26  */
27 public interface ICreateInfo {
28 
29     /**
30      * Returns the list of class from layoutlib_create to inject in layoutlib.
31      * The list can be empty but must not be null.
32      */
getInjectedClasses()33     Class<?>[] getInjectedClasses();
34 
35     /**
36      * Returns the list of methods to rewrite as delegates.
37      * The list can be empty but must not be null.
38      */
getDelegateMethods()39     String[] getDelegateMethods();
40 
41     /**
42      * Returns the list of classes on which to delegate all native methods.
43      * The list can be empty but must not be null.
44      */
getDelegateClassNatives()45     String[] getDelegateClassNatives();
46 
47     /**
48      * Returns The list of methods to stub out. Each entry must be in the form
49      * "package.package.OuterClass$InnerClass#MethodName".
50      * The list can be empty but must not be null.
51      */
getOverriddenMethods()52     String[] getOverriddenMethods();
53 
54     /**
55      * Returns the list of classes to rename, must be an even list: the binary FQCN
56      * of class to replace followed by the new FQCN.
57      * The list can be empty but must not be null.
58      */
getRenamedClasses()59     String[] getRenamedClasses();
60 
61     /**
62      * Returns the list of classes for which the methods returning them should be deleted.
63      * The array contains a list of null terminated section starting with the name of the class
64      * to rename in which the methods are deleted, followed by a list of return types identifying
65      * the methods to delete.
66      * The list can be empty but must not be null.
67      */
getDeleteReturns()68     String[] getDeleteReturns();
69 
70     /**
71      * Returns the list of classes to refactor, must be an even list: the
72      * binary FQCN of class to replace followed by the new FQCN. All references
73      * to the old class should be updated to the new class.
74      * The list can be empty but must not be null.
75      */
getJavaPkgClasses()76     String[] getJavaPkgClasses();
77 
getExcludedClasses()78     Set<String> getExcludedClasses();
79 
80     /**
81      * Returns a list of fields which should be promoted to public visibility. The array values
82      * are in the form of the binary FQCN of the class containing the field and the field name
83      * separated by a '#'.
84      */
getPromotedFields()85     String[] getPromotedFields();
86 
87     /**
88      * Returns a map from binary FQCN className to {@link InjectMethodRunnable} which will be
89      * called to inject methods into a class.
90      * Can be empty but must not be null.
91      */
getInjectedMethodsMap()92     Map<String, InjectMethodRunnable> getInjectedMethodsMap();
93 
94     abstract class InjectMethodRunnable {
95         /**
96          * @param cv Must be {@link ClassVisitor}. However, the param type is object so that when
97          * loading the class, ClassVisitor is not loaded. This is because when injecting
98          * CreateInfo in LayoutLib (see {@link #getInjectedClasses()}, we don't want to inject
99          * asm classes also, but still keep CreateInfo loadable.
100          */
generateMethods(Object cv)101         public abstract void generateMethods(Object cv);
102     }
103 }
104