📄 classspecificationvisitorfactory.java
字号:
/* $Id: ClassSpecificationVisitorFactory.java,v 1.5 2004/12/11 16:35:23 eric Exp $ * * ProGuard -- shrinking, optimization, and obfuscation of Java class files. * * Copyright (c) 2002-2003 Eric Lafortune (eric@graphics.cornell.edu) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package proguard;import proguard.classfile.visitor.*;import java.util.*;/** * This factory creates visitors to efficiently travel to specified classes and * class members. * * @author Eric Lafortune */class ClassSpecificationVisitorFactory{ /** * Creates a new ClassPoolVisitor to efficiently travel to the specified * classes and class members. * * @param classSpecifications the specifications of the classes and class * members to visit. * @param classFileVisitor the ClassFileVisitor to be applied to matching * classes. * @param memberInfoVisitor the MemberInfoVisitor to be applied to matching * class members. */ public static ClassPoolVisitor createClassPoolVisitor(List classSpecifications, ClassFileVisitor classFileVisitor, MemberInfoVisitor memberInfoVisitor) { MultiClassPoolVisitor multiClassPoolVisitor = new MultiClassPoolVisitor(); if (classSpecifications != null) { addClassPoolVisitors(classSpecifications, classFileVisitor, memberInfoVisitor, multiClassPoolVisitor); } return multiClassPoolVisitor; } /** * Adds new ClassPoolVisitor instances to the given MultiClassPoolVisitor, * to efficiently travel to the specified classes and class members. * @param classSpecifications the specifications of the classes and class * members to visit. * @param classFileVisitor the ClassFileVisitor to be applied to matching * classes. * @param memberInfoVisitor the MemberInfoVisitor to be applied to matching * class members. * @param multiClassPoolVisitor the MultiClassPoolVisitor to which the new * visitors will be added. */ private static void addClassPoolVisitors(List classSpecifications, ClassFileVisitor classFileVisitor, MemberInfoVisitor memberInfoVisitor, MultiClassPoolVisitor multiClassPoolVisitor) { for (int index = 0; index < classSpecifications.size(); index++) { multiClassPoolVisitor.addClassPoolVisitor( createClassPoolVisitor((ClassSpecification)classSpecifications.get(index), classFileVisitor, memberInfoVisitor)); } } /** * Creates a new ClassPoolVisitor to efficiently travel to the specified * classes and class members. * * @param classSpecification the specifications of the class(es) and class * members to visit. * @param classFileVisitor the ClassFileVisitor to be applied to matching * classes. * @param memberInfoVisitor the MemberInfoVisitor to be applied to matching * class members. */ private static ClassPoolVisitor createClassPoolVisitor(ClassSpecification classSpecification, ClassFileVisitor classFileVisitor, MemberInfoVisitor memberInfoVisitor) { // The class file visitor for class files and their members. MultiClassFileVisitor multiClassFileVisitor = new MultiClassFileVisitor(); // If specified, let the class file visitor visit the class file itself. if ((classSpecification.markClassFiles || classSpecification.markConditionally) && classFileVisitor != null) { multiClassFileVisitor.addClassFileVisitor(classFileVisitor); } // If specified, let the member info visitor visit the class members. if ((classSpecification.fieldSpecifications != null || classSpecification.methodSpecifications != null) && memberInfoVisitor != null) { multiClassFileVisitor.addClassFileVisitor( createClassFileVisitor(classSpecification, memberInfoVisitor)); } // This visitor is the starting point. ClassFileVisitor composedClassFileVisitor = multiClassFileVisitor; // If specified, let the marker visit the class file and its class // members conditionally. if (classSpecification.markConditionally) { composedClassFileVisitor = createClassFileMemberInfoTester(classSpecification, composedClassFileVisitor); } // By default, start visiting from the class name, if it's specified. String className = classSpecification.className; // If wildcarded, only visit class files with matching names. if (className != null && containsWildCards(className)) { composedClassFileVisitor = new ClassFileNameFilter(composedClassFileVisitor, className); // We'll have to visit all classes now. className = null; } // If specified, only visit class files with the right access flags. if (classSpecification.requiredSetAccessFlags != 0 || classSpecification.requiredUnsetAccessFlags != 0) { composedClassFileVisitor = new ClassFileAccessFilter(classSpecification.requiredSetAccessFlags, classSpecification.requiredUnsetAccessFlags, composedClassFileVisitor); } // If it's specified, start visiting from the extended class. String extendsClassName = classSpecification.extendsClassName; if (className == null && extendsClassName != null) { composedClassFileVisitor = new ClassFileHierarchyTraveler(false, false, false, true, composedClassFileVisitor); // If wildcarded, only visit class files with matching names. if (containsWildCards(extendsClassName)) { composedClassFileVisitor = new ClassFileNameFilter(composedClassFileVisitor, extendsClassName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -