1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2013 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 */
21package proguard.optimize.info;
22
23import proguard.classfile.Clazz;
24
25/**
26 * This class stores some optimization information that can be attached to
27 * a class.
28 *
29 * @author Eric Lafortune
30 */
31public class ClassOptimizationInfo
32{
33    private boolean isInstantiated                = false;
34    private boolean isInstanceofed                = false;
35    private boolean isDotClassed                  = false;
36    private boolean isCaught                      = false;
37    private boolean containsStaticInitializer     = false;
38    private boolean containsPackageVisibleMembers = false;
39    private boolean invokesPackageVisibleMembers  = false;
40    private Clazz   targetClass;
41
42
43    public void setInstantiated()
44    {
45        isInstantiated = true;
46    }
47
48
49    public boolean isInstantiated()
50    {
51        return isInstantiated;
52    }
53
54
55    public void setInstanceofed()
56    {
57        isInstanceofed = true;
58    }
59
60
61    public boolean isInstanceofed()
62    {
63        return isInstanceofed;
64    }
65
66
67    public void setDotClassed()
68    {
69        isDotClassed = true;
70    }
71
72
73    public boolean isDotClassed()
74    {
75        return isDotClassed;
76    }
77
78
79    public void setCaught()
80    {
81        isCaught = true;
82    }
83
84
85    public boolean isCaught()
86    {
87        return isCaught;
88    }
89
90
91    public void setContainsStaticInitializer()
92    {
93        containsStaticInitializer = true;
94    }
95
96
97    public boolean containsStaticInitializer()
98    {
99        return containsStaticInitializer;
100    }
101
102
103    public void setContainsPackageVisibleMembers()
104    {
105        containsPackageVisibleMembers = true;
106    }
107
108
109    public boolean containsPackageVisibleMembers()
110    {
111        return containsPackageVisibleMembers;
112    }
113
114
115    public void setInvokesPackageVisibleMembers()
116    {
117        invokesPackageVisibleMembers = true;
118    }
119
120
121    public boolean invokesPackageVisibleMembers()
122    {
123        return invokesPackageVisibleMembers;
124    }
125
126
127    public void setTargetClass(Clazz targetClass)
128    {
129        this.targetClass = targetClass;
130    }
131
132
133    public Clazz getTargetClass()
134    {
135        return targetClass;
136    }
137
138
139    public void merge(ClassOptimizationInfo other)
140    {
141        this.isInstantiated                |= other.isInstantiated;
142        this.isInstanceofed                |= other.isInstanceofed;
143        this.isDotClassed                  |= other.isDotClassed;
144        this.isCaught                      |= other.isCaught;
145        this.containsStaticInitializer     |= other.containsStaticInitializer;
146        this.containsPackageVisibleMembers |= other.containsPackageVisibleMembers;
147        this.invokesPackageVisibleMembers  |= other.invokesPackageVisibleMembers;
148    }
149
150
151    public static void setClassOptimizationInfo(Clazz clazz)
152    {
153        clazz.setVisitorInfo(new ClassOptimizationInfo());
154    }
155
156
157    public static ClassOptimizationInfo getClassOptimizationInfo(Clazz clazz)
158    {
159        Object visitorInfo = clazz.getVisitorInfo();
160
161        return visitorInfo instanceof ClassOptimizationInfo ?
162            (ClassOptimizationInfo)visitorInfo :
163            null;
164    }
165}
166