• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  *             of Java bytecode.
4  *
5  * Copyright (c) 2002-2014 Eric Lafortune (eric@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 import proguard.classfile.visitor.ClassVisitor;
25 
26 import java.util.List;
27 
28 /**
29  * This class checks if the user has forgotten to specify class members in
30  * some keep options in the configuration.
31  *
32  * @author Eric Lafortune
33  */
34 public class KeepClassMemberChecker
35 {
36     private final WarningPrinter notePrinter;
37 
38 
39     /**
40      * Creates a new KeepClassMemberChecker.
41      */
KeepClassMemberChecker(WarningPrinter notePrinter)42     public KeepClassMemberChecker(WarningPrinter notePrinter)
43     {
44         this.notePrinter = notePrinter;
45     }
46 
47 
48     /**
49      * Checks if the given class specifications try to keep class members
50      * without actually specifying any, printing notes if necessary.
51      */
checkClassSpecifications(List keepClassSpecifications)52     public void checkClassSpecifications(List keepClassSpecifications)
53     {
54         if (keepClassSpecifications != null)
55         {
56             for (int index = 0; index < keepClassSpecifications.size(); index++)
57             {
58                 KeepClassSpecification keepClassSpecification =
59                     (KeepClassSpecification)keepClassSpecifications.get(index);
60 
61                 if (!keepClassSpecification.markClasses                      &&
62                     (keepClassSpecification.fieldSpecifications  == null ||
63                      keepClassSpecification.fieldSpecifications.size() == 0) &&
64                     (keepClassSpecification.methodSpecifications == null ||
65                      keepClassSpecification.methodSpecifications.size() == 0))
66                 {
67                     String className = keepClassSpecification.className;
68                     if (className == null)
69                     {
70                         className = keepClassSpecification.extendsClassName;
71                     }
72 
73                     if (className == null ||
74                         notePrinter.accepts(className))
75                     {
76                         notePrinter.print(className,
77                                           "Note: the configuration doesn't specify which class members to keep for class '" +
78                                           (className == null ?
79                                               ConfigurationConstants.ANY_CLASS_KEYWORD :
80                                               ClassUtil.externalClassName(className)) + "'");
81                     }
82                 }
83             }
84         }
85     }
86 }
87