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.apkcheck; 18 19 import java.util.HashMap; 20 import java.util.Iterator; 21 22 /** 23 * Container representing a package of classes and interfaces. 24 */ 25 public class PackageInfo { 26 private String mName; 27 private HashMap<String,ClassInfo> mClassList; 28 PackageInfo(String name)29 public PackageInfo(String name) { 30 mName = name; 31 mClassList = new HashMap<String,ClassInfo>(); 32 } 33 getName()34 public String getName() { 35 return mName; 36 } 37 38 /** 39 * Retrieves the named class. 40 * 41 * @return the package, or null if no match was found 42 */ getClass(String name)43 public ClassInfo getClass(String name) { 44 return mClassList.get(name); 45 } 46 47 /** 48 * Retrieves the named class, creating it if it doesn't already 49 * exist. 50 * 51 * @param className Binary or non-binary class name without the 52 * package name, e.g. "AlertDialog.Builder". 53 * @param superclassName Fully-qualified binary or non-binary superclass 54 * name (e.g. "java.lang.Enum"). 55 * @param isStatic Class static attribute, may be "true", "false", or null. 56 */ getOrCreateClass(String className, String superclassName, String isStatic)57 public ClassInfo getOrCreateClass(String className, String superclassName, 58 String isStatic) { 59 String fixedName = TypeUtils.simpleClassNameToBinary(className); 60 ClassInfo classInfo = mClassList.get(fixedName); 61 if (classInfo == null) { 62 //System.out.println("--- creating entry for class " + fixedName + 63 // " (super=" + superclassName + ")"); 64 classInfo = new ClassInfo(fixedName, superclassName, isStatic); 65 mClassList.put(fixedName, classInfo); 66 } else { 67 //System.out.println("--- returning existing class " + name); 68 } 69 return classInfo; 70 } 71 72 /** 73 * Returns an iterator for the set of classes in this package. 74 */ getClassIterator()75 public Iterator<ClassInfo> getClassIterator() { 76 return mClassList.values().iterator(); 77 } 78 } 79 80