~ubuntu-branches/ubuntu/wily/proguard/wily-proposed

« back to all changes in this revision

Viewing changes to src/proguard/shrink/UsageMarker.java

  • Committer: Package Import Robot
  • Author(s): komal Sukhani
  • Date: 2015-08-31 14:45:54 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20150831144554-v4gb9hzo8xldfky9
Tags: 5.2.1-1
* Team upload
* New upstream release
* Add new patches
  - correct_properties_file_path
  - enable_building_of_gradle_task
* Add gradle package in build depends
* d/control: Switch Vcs-Browser field to cgit

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3
3
 *             of Java bytecode.
4
4
 *
5
 
 * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
 
5
 * Copyright (c) 2002-2015 Eric Lafortune @ GuardSquare
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or modify it
8
8
 * under the terms of the GNU General Public License as published by the Free
33
33
import proguard.classfile.util.*;
34
34
import proguard.classfile.visitor.*;
35
35
 
36
 
 
37
36
/**
38
37
 * This ClassVisitor and MemberVisitor recursively marks all classes and class
39
38
 * elements that are being used.
67
66
 
68
67
 
69
68
    private final MyInterfaceUsageMarker          interfaceUsageMarker           = new MyInterfaceUsageMarker();
 
69
    private final MyDefaultMethodUsageMarker      defaultMethodUsageMarker       = new MyDefaultMethodUsageMarker();
70
70
    private final MyPossiblyUsedMemberUsageMarker possiblyUsedMemberUsageMarker  = new MyPossiblyUsedMemberUsageMarker();
71
71
    private final MemberVisitor                   nonEmptyMethodUsageMarker      = new AllAttributeVisitor(
72
72
                                                                                   new MyNonEmptyMethodUsageMarker());
181
181
 
182
182
 
183
183
    /**
 
184
     * This MemberVisitor marks ProgramMethod objects of default
 
185
     * implementations that may be present in interface classes.
 
186
     */
 
187
    private class MyDefaultMethodUsageMarker
 
188
    extends       SimplifiedVisitor
 
189
    implements    MemberVisitor
 
190
    {
 
191
        // Implementations for MemberVisitor.
 
192
 
 
193
        public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
 
194
        {
 
195
            if (shouldBeMarkedAsUsed(programMethod))
 
196
            {
 
197
                markAsUsed(programMethod);
 
198
 
 
199
                // Mark the method body.
 
200
                markProgramMethodBody(programClass, programMethod);
 
201
 
 
202
                // Note that, if the method has been marked as possibly used,
 
203
                // the method hierarchy has already been marked (cfr. below).
 
204
            }
 
205
        }
 
206
    }
 
207
 
 
208
 
 
209
    /**
184
210
     * This MemberVisitor marks ProgramField and ProgramMethod objects that
185
211
     * have already been marked as possibly used.
186
212
     */
354
380
     */
355
381
    protected void markMethodHierarchy(Clazz clazz, Method method)
356
382
    {
 
383
        // Only visit the hierarchy if the method is not private, static, or
 
384
        // an initializer.
357
385
        int accessFlags = method.getAccessFlags();
358
386
        if ((accessFlags &
359
387
             (ClassConstants.ACC_PRIVATE |
369
397
                ((accessFlags & ClassConstants.ACC_PUBLIC) == 0 ? 0 :
370
398
                     ClassConstants.ACC_ABSTRACT);
371
399
 
 
400
            // Mark default implementations in interfaces down the hierarchy,
 
401
            // if this is an interface itself.
 
402
            // TODO: This may be premature if there aren't any concrete implementing classes.
 
403
            clazz.accept(new ClassAccessFilter(ClassConstants.ACC_INTERFACE, 0,
 
404
                         new ClassHierarchyTraveler(false, false, false, true,
 
405
                         new ProgramClassFilter(
 
406
                         new ClassAccessFilter(ClassConstants.ACC_INTERFACE, 0,
 
407
                         new NamedMethodVisitor(method.getName(clazz),
 
408
                                                method.getDescriptor(clazz),
 
409
                         new MemberAccessFilter(0, requiredUnsetAccessFlags,
 
410
                         defaultMethodUsageMarker)))))));
 
411
 
 
412
            // Mark other implementations.
372
413
            clazz.accept(new ConcreteClassDownTraveler(
373
414
                         new ClassHierarchyTraveler(true, true, false, true,
374
415
                         new NamedMethodVisitor(method.getName(clazz),
449
490
 
450
491
            markConstant(clazz, invokeDynamicConstant.u2nameAndTypeIndex);
451
492
 
 
493
            // Mark the referenced descriptor classes.
 
494
            invokeDynamicConstant.referencedClassesAccept(this);
 
495
 
452
496
            // Mark the bootstrap methods attribute.
453
497
            clazz.attributesAccept(new MyBootStrapMethodUsageMarker(invokeDynamicConstant.u2bootstrapMethodAttributeIndex));
454
498
        }
662
706
 
663
707
    public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
664
708
    {
665
 
        // Don't mark the attribute and its contents yet. We may mark them later,
666
 
        // in SignatureUsageMarker.
667
 
        //markAsUsed(signatureAttribute);
668
 
        //
669
 
        //markConstant(clazz, signatureAttribute.u2attributeNameIndex);
670
 
        //markConstant(clazz, signatureAttribute.u2signatureIndex);
 
709
        markAsUsed(signatureAttribute);
 
710
 
 
711
        markConstant(clazz, signatureAttribute.u2attributeNameIndex);
 
712
        markConstant(clazz, signatureAttribute.u2signatureIndex);
 
713
 
 
714
        // Don't mark the referenced classes. We'll clean them up in
 
715
        // ClassShrinker, if they appear unused.
 
716
        //// Mark the classes referenced in the descriptor string.
 
717
        //signatureAttribute.referencedClassesAccept(this);
671
718
    }
672
719
 
673
720
 
802
849
    {
803
850
        // Don't mark the attribute and its contents yet. We may mark them later,
804
851
        // in AnnotationUsageMarker.
805
 
//        markAsUsed(annotationDefaultAttribute);
806
 
//
807
 
//        markConstant(clazz, annotationDefaultAttribute.u2attributeNameIndex);
808
 
//
809
 
//        // Mark the constant pool entries referenced by the element value.
810
 
//        annotationDefaultAttribute.defaultValueAccept(clazz, this);
 
852
        //markAsUsed(annotationDefaultAttribute);
 
853
        //
 
854
        //markConstant(clazz, annotationDefaultAttribute.u2attributeNameIndex);
 
855
        //
 
856
        //// Mark the constant pool entries referenced by the element value.
 
857
        //annotationDefaultAttribute.defaultValueAccept(clazz, this);
811
858
    }
812
859
 
813
860