diff options
Diffstat (limited to 'src/proguard/shrink/AnnotationUsageMarker.java')
-rw-r--r-- | src/proguard/shrink/AnnotationUsageMarker.java | 76 |
1 files changed, 22 insertions, 54 deletions
diff --git a/src/proguard/shrink/AnnotationUsageMarker.java b/src/proguard/shrink/AnnotationUsageMarker.java index 9aaae34..b9051a0 100644 --- a/src/proguard/shrink/AnnotationUsageMarker.java +++ b/src/proguard/shrink/AnnotationUsageMarker.java @@ -2,7 +2,7 @@ * ProGuard -- shrinking, optimization, obfuscation, and preverification * of Java bytecode. * - * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) + * Copyright (c) 2002-2013 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 @@ -52,8 +52,7 @@ implements AttributeVisitor, // Fields acting as a return parameters for several methods. private boolean attributeUsed; private boolean annotationUsed; - private boolean elementValueUsed; - private boolean classUsed; + private boolean allClassesUsed; private boolean methodUsed; @@ -151,9 +150,6 @@ implements AttributeVisitor, markConstant(clazz, constantElementValue.u2elementNameIndex); markConstant(clazz, constantElementValue.u2constantValueIndex); - - // The return value. - elementValueUsed = true; } } @@ -163,10 +159,10 @@ implements AttributeVisitor, if (isReferencedMethodUsed(enumConstantElementValue)) { // Check the referenced classes. - classUsed = true; - enumConstantElementValue.referencedClassesAccept(usageMarker); + allClassesUsed = true; + enumConstantElementValue.referencedClassesAccept(this); - if (classUsed) + if (allClassesUsed) { // Mark the element value as being used. usageMarker.markAsUsed(enumConstantElementValue); @@ -174,9 +170,6 @@ implements AttributeVisitor, markConstant(clazz, enumConstantElementValue.u2elementNameIndex); markConstant(clazz, enumConstantElementValue.u2typeNameIndex); markConstant(clazz, enumConstantElementValue.u2constantNameIndex); - - // The return value. - elementValueUsed = true; } } } @@ -186,21 +179,16 @@ implements AttributeVisitor, { if (isReferencedMethodUsed(classElementValue)) { - // Check the referenced classes. - classUsed = true; - classElementValue.referencedClassesAccept(usageMarker); - - if (classUsed) - { - // Mark the element value as being used. - usageMarker.markAsUsed(classElementValue); + // Mark the element value as being used. + usageMarker.markAsUsed(classElementValue); - markConstant(clazz, classElementValue.u2elementNameIndex); - markConstant(clazz, classElementValue.u2classInfoIndex); + markConstant(clazz, classElementValue.u2elementNameIndex); + markConstant(clazz, classElementValue.u2classInfoIndex); - // The return value. - elementValueUsed = true; - } + // Mark the referenced classes, since they can be retrieved from + // the annotation and then used. + // TODO: This could mark more annotation methods, affecting other annotations. + classElementValue.referencedClassesAccept(usageMarker); } } @@ -221,9 +209,6 @@ implements AttributeVisitor, usageMarker.markAsUsed(annotationElementValue); markConstant(clazz, annotationElementValue.u2elementNameIndex); - - // The return value. - elementValueUsed = true; } annotationUsed = oldAnnotationUsed; @@ -235,26 +220,13 @@ implements AttributeVisitor, { if (isReferencedMethodUsed(arrayElementValue)) { - boolean oldelementValueUsed = elementValueUsed; - // Check and mark the contained element values. - elementValueUsed = false; arrayElementValue.elementValuesAccept(clazz, annotation, this); - if (elementValueUsed) - { - // Mark the element value as being used. - usageMarker.markAsUsed(arrayElementValue); - - markConstant(clazz, arrayElementValue.u2elementNameIndex); + // Mark the element value as being used. + usageMarker.markAsUsed(arrayElementValue); - // The return value. - //elementValueUsed = true; - } - else - { - elementValueUsed = oldelementValueUsed; - } + markConstant(clazz, arrayElementValue.u2elementNameIndex); } } @@ -269,17 +241,15 @@ implements AttributeVisitor, public void visitClassConstant(Clazz clazz, ClassConstant classConstant) { - classUsed = usageMarker.isUsed(classConstant); - // Is the class constant marked as being used? - if (!classUsed) + if (!usageMarker.isUsed(classConstant)) { // Check the referenced class. - classUsed = true; + allClassesUsed = true; classConstant.referencedClassAccept(this); // Is the referenced class marked as being used? - if (classUsed) + if (allClassesUsed) { // Mark the class constant and its Utf8 constant. usageMarker.markAsUsed(classConstant); @@ -294,13 +264,12 @@ implements AttributeVisitor, public void visitProgramClass(ProgramClass programClass) { - classUsed = usageMarker.isUsed(programClass); + allClassesUsed &= usageMarker.isUsed(programClass); } public void visitLibraryClass(LibraryClass libraryClass) { - classUsed = true; } @@ -314,7 +283,6 @@ implements AttributeVisitor, public void visitLibraryMethod(LibraryClass LibraryClass, LibraryMethod libraryMethod) { - classUsed = true; } @@ -326,10 +294,10 @@ implements AttributeVisitor, private boolean isReferencedClassUsed(Annotation annotation) { // Check if the referenced class is being used. - classUsed = true; + allClassesUsed = true; annotation.referencedClassAccept(this); - return classUsed; + return allClassesUsed; } |