classreferenceinitializer.java
来自「proguard 一个java的混淆器」· Java 代码 · 共 482 行 · 第 1/2 页
JAVA
482 行
if (warningPrinter != null) { warningPrinter.print("Warning: " + ClassUtil.externalClassName(clazz.getName()) + ": can't find enclosing method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type) + "' in class " + ClassUtil.externalClassName(className)); } return; } // Save the references. enclosingMethodAttribute.referencedClass = referencedClass; enclosingMethodAttribute.referencedMethod = referencedMethod; } public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { // Initialize the nested attributes. codeAttribute.attributesAccept(clazz, method, this); } public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) { // Initialize the local variables. localVariableTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); } public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) { // Initialize the local variable types. localVariableTypeTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); } public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute) { signatureAttribute.referencedClasses = findReferencedClasses(clazz.getString(signatureAttribute.u2signatureIndex)); } public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute) { // Initialize the annotations. annotationsAttribute.annotationsAccept(clazz, this); } public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute) { // Initialize the annotations. parameterAnnotationsAttribute.annotationsAccept(clazz, method, this); } public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) { // Initialize the annotation. annotationDefaultAttribute.defaultValueAccept(clazz, this); } // Implementations for LocalVariableInfoVisitor. public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo) { localVariableInfo.referencedClass = findReferencedClass(clazz.getString(localVariableInfo.u2descriptorIndex)); } // Implementations for LocalVariableTypeInfoVisitor. public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo) { localVariableTypeInfo.referencedClasses = findReferencedClasses(clazz.getString(localVariableTypeInfo.u2signatureIndex)); } // Implementations for AnnotationVisitor. public void visitAnnotation(Clazz clazz, Annotation annotation) { annotation.referencedClasses = findReferencedClasses(clazz.getString(annotation.u2typeIndex)); // Initialize the element values. annotation.elementValuesAccept(clazz, this); } // Implementations for ElementValueVisitor. public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue) { initializeElementValue(clazz, annotation, constantElementValue); } public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue) { initializeElementValue(clazz, annotation, enumConstantElementValue); enumConstantElementValue.referencedClasses = findReferencedClasses(clazz.getString(enumConstantElementValue.u2typeNameIndex)); } public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue) { initializeElementValue(clazz, annotation, classElementValue); classElementValue.referencedClasses = findReferencedClasses(clazz.getString(classElementValue.u2classInfoIndex)); } public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue) { initializeElementValue(clazz, annotation, annotationElementValue); // Initialize the annotation. annotationElementValue.annotationAccept(clazz, this); } public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue) { initializeElementValue(clazz, annotation, arrayElementValue); // Initialize the element values. arrayElementValue.elementValuesAccept(clazz, annotation, this); } /** * Initializes the referenced method of an element value, if any. */ private void initializeElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue) { // See if we have a referenced class. if (annotation != null && annotation.referencedClasses != null && elementValue.u2elementNameIndex != 0) { // See if we can find the method in the referenced class // (ignoring the descriptor). String name = clazz.getString(elementValue.u2elementNameIndex); Clazz referencedClass = annotation.referencedClasses[0]; elementValue.referencedClass = referencedClass; elementValue.referencedMethod = referencedClass.findMethod(name, null); } } // Small utility methods. /** * Returns the single class referenced by the given descriptor, or * <code>null</code> if there isn't any useful reference. */ private Clazz findReferencedClass(String descriptor) { DescriptorClassEnumeration enumeration = new DescriptorClassEnumeration(descriptor); if (enumeration.hasMoreClassNames()) { return findClass(enumeration.nextClassName()); } return null; } /** * Returns an array of classes referenced by the given descriptor, or * <code>null</code> if there aren't any useful references. */ private Clazz[] findReferencedClasses(String descriptor) { DescriptorClassEnumeration enumeration = new DescriptorClassEnumeration(descriptor); int classCount = enumeration.classCount(); if (classCount > 0) { Clazz[] referencedClasses = new Clazz[classCount]; boolean foundReferencedClasses = false; for (int index = 0; index < classCount; index++) { String name = enumeration.nextClassName(); Clazz referencedClass = findClass(name); if (referencedClass != null) { referencedClasses[index] = referencedClass; foundReferencedClasses = true; } } if (foundReferencedClasses) { return referencedClasses; } } return null; } /** * Returns the class with the given name, either for the program class pool * or from the library class pool, or <code>null</code> if it can't be found. */ private Clazz findClass(String name) { // First look for the class in the program class pool. Clazz clazz = programClassPool.getClass(name); // Otherwise look for the class in the library class pool. if (clazz == null) { clazz = libraryClassPool.getClass(name); } return clazz; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?