All Downloads are FREE. Search and download functionalities are using the official Maven repository.

proguard.classfile.util.ClassInitializer Maven / Gradle / Ivy

Go to download

ProGuardCORE is a free library to read, analyze, modify, and write Java class files.

There is a newer version: 9.1.6
Show newest version
/*
 * ProGuardCORE -- library to process Java bytecode.
 *
 * Copyright (c) 2002-2020 Guardsquare NV
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package proguard.classfile.util;

import proguard.classfile.ClassPool;
import proguard.classfile.Clazz;
import proguard.classfile.visitor.ClassVisitor;

/**
 * This {@link ClassVisitor} initializes the class hierarchy and references of all classes that it
 * visits. It assumes that the class hierarchies of the classes to which it refers have already been
 * initialized. Otherwise, you need to call subsequently call {@link
 * ClassSuperHierarchyInitializer}, {@link ClassSubHierarchyInitializer}, and {@link
 * ClassReferenceInitializer} on all classes.
 *
 * 

* * @author Eric Lafortune * @see ClassSuperHierarchyInitializer * @see ClassSubHierarchyInitializer * @see ClassReferenceInitializer */ public class ClassInitializer implements ClassVisitor { private final ClassSuperHierarchyInitializer classSuperHierarchyInitializer; private final ClassSubHierarchyInitializer classSubHierarchyInitializer; private final ClassReferenceInitializer classReferenceInitializer; /** * Creates a new ClassInitializer that initializes the class hierarchies and references of all * visited class files. */ public ClassInitializer(ClassPool programClassPool, ClassPool libraryClassPool) { this(programClassPool, libraryClassPool, true, null, null); } /** * Creates a new ClassInitializer that initializes the class hierarchies and references of all * visited class files, optionally printing warnings if some classes or class members can't be * found or if they are in the program class pool. */ public ClassInitializer( ClassPool programClassPool, ClassPool libraryClassPool, WarningPrinter missingClassWarningPrinter, WarningPrinter missingProgramMemberWarningPrinter, WarningPrinter missingLibraryMemberWarningPrinter, WarningPrinter dependencyWarningPrinter) { this( programClassPool, libraryClassPool, true, missingClassWarningPrinter, missingProgramMemberWarningPrinter, missingLibraryMemberWarningPrinter, dependencyWarningPrinter); } /** * Creates a new ClassInitializer that initializes the references of all visited class files, * optionally printing warnings if some classes or class members can't be found or if they are in * the program class pool. */ public ClassInitializer( ClassPool programClassPool, ClassPool libraryClassPool, boolean checkAccessRules, WarningPrinter missingClassWarningPrinter, WarningPrinter missingProgramMemberWarningPrinter, WarningPrinter missingLibraryMemberWarningPrinter, WarningPrinter dependencyWarningPrinter) { this.classSuperHierarchyInitializer = new ClassSuperHierarchyInitializer( programClassPool, libraryClassPool, missingClassWarningPrinter, dependencyWarningPrinter); this.classSubHierarchyInitializer = new ClassSubHierarchyInitializer(); this.classReferenceInitializer = new ClassReferenceInitializer( programClassPool, libraryClassPool, checkAccessRules, missingClassWarningPrinter, missingProgramMemberWarningPrinter, missingLibraryMemberWarningPrinter, dependencyWarningPrinter); } /** * Creates a new ClassInitializer that initializes the references of all visited class files, * optionally visiting the provided {@link InvalidReferenceVisitor} or {@link * InvalidClassReferenceVisitor} for any invalid references. */ public ClassInitializer( ClassPool programClassPool, ClassPool libraryClassPool, boolean checkAccessRules, InvalidReferenceVisitor invalidReferenceVisitor, InvalidClassReferenceVisitor invalidClassReferenceVisitor) { this.classSuperHierarchyInitializer = new ClassSuperHierarchyInitializer( programClassPool, libraryClassPool, invalidClassReferenceVisitor); this.classSubHierarchyInitializer = new ClassSubHierarchyInitializer(); this.classReferenceInitializer = new ClassReferenceInitializer( programClassPool, libraryClassPool, checkAccessRules, invalidReferenceVisitor); } // Implementations for ClassVisitor. @Override public void visitAnyClass(Clazz clazz) { // Initialize all references to/from the class. clazz.accept(classSuperHierarchyInitializer); clazz.accept(classSubHierarchyInitializer); clazz.accept(classReferenceInitializer); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy