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 classes to rename, must be an even list: the binary FQCN 49 * of class to replace followed by the new FQCN. 50 * The list can be empty but must not be null. 51 */ getRenamedClasses()52 String[] getRenamedClasses(); 53 54 /** 55 * List of classes to refactor. This is similar to combining {@link #getRenamedClasses()} and 56 * {@link #getJavaPkgClasses()}. 57 * Classes included here will be renamed and then all their references in any other classes 58 * will be also modified. 59 * FQCN of class to refactor followed by its new FQCN. 60 */ getRefactoredClasses()61 String[] getRefactoredClasses(); 62 63 /** 64 * Returns the list of classes for which the methods returning them should be deleted. 65 * The array contains a list of null terminated section starting with the name of the class 66 * to rename in which the methods are deleted, followed by a list of return types identifying 67 * the methods to delete. 68 * The list can be empty but must not be null. 69 */ getDeleteReturns()70 String[] getDeleteReturns(); 71 72 /** 73 * Returns the list of classes to refactor, must be an even list: the 74 * binary FQCN of class to replace followed by the new FQCN. All references 75 * to the old class should be updated to the new class. 76 * The list can be empty but must not be null. 77 */ getJavaPkgClasses()78 String[] getJavaPkgClasses(); 79 getExcludedClasses()80 String[] getExcludedClasses(); 81 82 /** 83 * Returns a list of fields which should be promoted to public visibility. The array values 84 * are in the form of the binary FQCN of the class containing the field and the field name 85 * separated by a '#'. 86 */ getPromotedFields()87 String[] getPromotedFields(); 88 89 /** 90 * Returns a list of classes to be promoted to public visibility. 91 */ getPromotedClasses()92 String[] getPromotedClasses(); 93 94 /** 95 * Returns a map from binary FQCN className to {@link InjectMethodRunnable} which will be 96 * called to inject methods into a class. 97 * Can be empty but must not be null. 98 */ getInjectedMethodsMap()99 Map<String, InjectMethodRunnable> getInjectedMethodsMap(); 100 101 abstract class InjectMethodRunnable { 102 /** 103 * @param cv Must be {@link ClassVisitor}. However, the param type is object so that when 104 * loading the class, ClassVisitor is not loaded. This is because when injecting 105 * CreateInfo in LayoutLib (see {@link #getInjectedClasses()}, we don't want to inject 106 * asm classes also, but still keep CreateInfo loadable. 107 */ generateMethods(Object cv)108 public abstract void generateMethods(Object cv); 109 } 110 } 111