Home | History | Annotate | Download | only in proguard
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2014 Eric Lafortune (eric (at) graphics.cornell.edu)
      6  *
      7  * This program is free software; you can redistribute it and/or modify it
      8  * under the terms of the GNU General Public License as published by the Free
      9  * Software Foundation; either version 2 of the License, or (at your option)
     10  * any later version.
     11  *
     12  * This program is distributed in the hope that it will be useful, but WITHOUT
     13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
     15  * more details.
     16  *
     17  * You should have received a copy of the GNU General Public License along
     18  * with this program; if not, write to the Free Software Foundation, Inc.,
     19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     20  */
     21 package proguard;
     22 
     23 import proguard.classfile.util.*;
     24 
     25 import java.util.List;
     26 
     27 /**
     28  * This class checks if the user is specifying to assume no side effects
     29  * for a reasonable number of methods in a class: not none and not all.
     30  *
     31  * @author Eric Lafortune
     32  */
     33 public class AssumeNoSideEffectsChecker
     34 {
     35     private final WarningPrinter notePrinter;
     36 
     37 
     38     /**
     39      * Creates a new KeepClassMemberChecker.
     40      */
     41     public AssumeNoSideEffectsChecker(WarningPrinter notePrinter)
     42     {
     43         this.notePrinter = notePrinter;
     44     }
     45 
     46 
     47     /**
     48      * Checks if the given class specifications try to assume no side effects
     49      * for all methods in a class, printing notes if necessary.
     50      */
     51     public void checkClassSpecifications(List classSpecifications)
     52     {
     53         if (classSpecifications != null)
     54         {
     55             for (int classSpecificationIndex = 0;
     56                  classSpecificationIndex < classSpecifications.size();
     57                  classSpecificationIndex++)
     58             {
     59                 ClassSpecification classSpecification =
     60                     (ClassSpecification)classSpecifications.get(classSpecificationIndex);
     61 
     62                 String className = classSpecification.className;
     63                 if (className == null)
     64                 {
     65                     className = classSpecification.extendsClassName;
     66                 }
     67 
     68                 if (className == null ||
     69                     notePrinter.accepts(className))
     70                 {
     71                     List methodSpecifications =
     72                         classSpecification.methodSpecifications;
     73 
     74                     if (methodSpecifications != null)
     75                     {
     76                         for (int methodSpecificationIndex = 0;
     77                              methodSpecificationIndex < methodSpecifications.size();
     78                              methodSpecificationIndex++)
     79                         {
     80                             final MemberSpecification methodSpecification =
     81                                 (MemberSpecification)methodSpecifications.get(methodSpecificationIndex);
     82 
     83                             if (methodSpecification.name       == null &&
     84                                 methodSpecification.descriptor == null)
     85                             {
     86                                 notePrinter.print(className,
     87                                                   "Note: the configuration specifies that none of the methods of class '" +
     88                                                   (className == null ?
     89                                                        ConfigurationConstants.ANY_CLASS_KEYWORD :
     90                                                        ClassUtil.externalClassName(className)) + "' have any side effects");
     91                             }
     92                         }
     93                     }
     94                 }
     95             }
     96         }
     97     }
     98 }
     99