summaryrefslogtreecommitdiff
path: root/docs/manual/attributes.html
blob: 08265e7e0b741d41e186c80273827614382c8f67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-style-type" content="text/css">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Attributes</title>
</head>
<body>

<script type="text/javascript" language="JavaScript">
<!--
if (window.self==window.top)
  document.write('<a class="largebutton" target="_top" href="../index.html#manual/attributes.html">ProGuard index</a> <a class="largebutton" target="_top" href="http://www.saikoa.com/dexguard">DexGuard</a> <a class="largebutton" target="_top" href="http://www.saikoa.com/">Saikoa</a> <a class="largebutton" target="other" href="http://sourceforge.net/projects/proguard/">Sourceforge</a>')
//-->
</script>
<noscript>
<a class="largebutton" target="_top"  href="../index.html#manual/attributes.html">ProGuard index</a>
<a class="largebutton" target="_top"  href="http://www.saikoa.com/dexguard">DexGuard</a>
<a class="largebutton" target="_top"  href="http://www.saikoa.com/">Saikoa</a>
<a class="largebutton" target="other" href="http://sourceforge.net/projects/proguard/">Sourceforge</a>
</noscript>

<h2>Attributes</h2>

Class files essentially define classes, their fields, and their methods. A lot
of essential and non-essential data are attached to these classes, fields, and
methods as <i>attributes</i>. For instance, attributes can contain bytecode,
source file names, line number tables, etc.
<p>

ProGuard's obfuscation step removes attributes that are generally not
necessary for executing the code. With
the <a href="usage.html#keepattributes"><code>-keepattributes</code></a>
option, you can specify a filter for attributes that you do want to keep, for
instance, if your code accesses them through reflection or if you want to
preserve some compilation or debugging information. The filter works like
any <a href="usage.html#filters">filter</a> in ProGuard.
<p>

The following wildcards are supported:

<table cellspacing="10">
<tr><td valign="top"><code><b>?</b></code></td>
    <td>matches any single character in an attribute name.</td></tr>
<tr><td valign="top"><code><b>*</b></code></td>
    <td>matches any part of an attribute name.</td></tr>
</table>

An attribute name that is preceded by an exclamation mark '<b>!</b>' is
<i>excluded</i> from further attempts to match with <i>subsequent</i>
attribute names in the filter. Make sure to specify filters correctly, since
they are not checked for potential typos.
<p>

For example, the following setting preserves the optional attributes that are
typically necessary when processing code that is intended to be used as a
library:
<pre>
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
                SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
</pre>
<p>

The Java bytecode specifications currently specify the following list of
attributes.

<h3>Optional attributes</h3>

ProGuard's obfuscation step by default discards the following optional
attributes. You can keep them with
the <a href="usage.html#keepattributes"><code>-keepattributes</code></a>
option.

<dl>
<dt><code><b>SourceFile</b></code></dt>
<dd>Specifies the name of the source file from which the class file was
    compiled. If present, this name is reported in stack traces.</dd>

<dt><div>(J++ extension)</div>
    <code><b>SourceDir</b></code></dt>
<dd>Specifies the name of the source directory from which the class file was
    compiled.</dd>

<dt><code><b>InnerClasses</b></code></dt>
<dd>Specifies the relationship between a class and its inner classes and outer
    classes. Other than this and the naming convention with a '$' separator
    between the names of inner classes and outer classes, inner classes are
    just like ordinary classes. Compilers may need this information to find
    classes referenced in a compiled library. Code may access this information
    by reflection, for instance to derive the simple name of the class.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>EnclosingMethod</b></code></dt>
<dd>Specifies the method in which the class was defined. Compilers may need
    this information to find classes referenced in a compiled library. Code
    may access this information by reflection, for instance to derive the
    simple name of the class.</dd>

<dt><code><b>Deprecated</b></code></dt>
<dd>Indicates that the class, field, or method is deprecated.</dd>

<dt><code><b>Synthetic</b></code></dt>
<dd>Indicates that the class, field, or method was generated by the
    compiler.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>Signature</b></code></dt>
<dd>Specifies the generic signature of the class, field, or method. Compilers
    may need this information to properly compile classes that use generic
    types from compiled libraries. Code may access this signature by
    reflection.</dd>

<dt><div>(Java 8 or higher)</div>
    <code><b>MethodParameters</b></code></dt>
<dd>Specifies the names and access flags of the parameters of the method. Code
    may access this information by reflection.</dd>

<dt><code><b>Exceptions</b></code></dt>
<dd>Specifies the exceptions that a method may throw. Compilers may use this
    information to enforce catching them.</dd>

<dt><code><b>LineNumberTable</b></code></dt>
<dd>Specifies the line numbers of the method. If present, these line numbers
    are reported in stack traces.</dd>

<dt><code><b>LocalVariableTable</b></code></dt>
<dd>Specifies the names and types of local variables of the method. If present,
    some IDEs may use this information for helping with auto-completion.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>LocalVariableTypeTable</b></code></dt>
<dd>Specifies the names and generic types of local variables of the method. If
    present, some IDEs may use this information for helping with
    auto-completion.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>RuntimeVisibleAnnotations</b></code></dt>
<dd>Specifies the annotations that are visible at run-time, for classes,
    fields, and methods. Compilers and annotation processors may use these
    annotations. Code may access them by reflection.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>RuntimeInvisibleAnnotations</b></code></dt>
<dd>Specifies the annotations that are visible at compile-time, for classes,
    fields, and methods. Compilers and annotation processors may use these
    annotations.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>RuntimeVisibleParameterAnnotations</b></code></dt>
<dd>Specifies the annotations that are visible at run-time, for method
    parameters. Compilers and annotation processors may use these
    annotations. Code may access them by reflection.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>RuntimeInvisibleParameterAnnotations</b></code></dt>
<dd>Specifies the annotations that are visible at compile-time, for method
    parameters. Compilers and annotation processors may use these
    annotations.</dd>

<dt><div>(Java 8 or higher)</div>
    <code><b>RuntimeVisibleTypeAnnotations</b></code></dt>
<dd>Specifies the annotations that are visible at run-time, for generic types,
    instructions, etc. Compilers and annotation processors may use these
    annotations. Code may access them by reflection.</dd>

<dt><div>(Java 8 or higher)</div>
    <code><b>RuntimeInvisibleTypeAnnotations</b></code></dt>
<dd>Specifies the annotations that are visible at compile-time, for generic
    types, instructions, etc. Compilers and annotation processors may use
    these annotations.</dd>

<dt><div>(Java 5 or higher)</div>
    <code><b>AnnotationDefault</b></code></dt>
<dd>Specifies a default value for an annotation.</dd>

</dl>
<p>

<h3>Essential attributes</h3>

ProGuard automatically keeps the following essential attributes, processing
them as necessary. We're listing them for the sake of completeness.

<dl>
<dt><code><b>ConstantValue</b></code></dt>
<dd>Specifies a constant integer, float, class, string, etc.</dd>

<dt><code><b>Code</b></code></dt>
<dd>Specifies the actual bytecode of a method.</dd>

<dt><div>(Java Micro Edition)</div>
    <code><b>StackMap</b></code></dt>
<dd>Provides preverification information. The Java Virtual Machine can use
    this information to speed up the verification step when loading a
    class.</dd>

<dt><div>(Java 6 or higher)</div>
    <code><b>StackMapTable</b></code></dt>
<dd>Provides preverification information. The Java Virtual Machine can use
    this information to speed up the verification step when loading a
    class.</dd>

<dt><div>(Java 7 or higher)</div>
    <code><b>BootstrapMethods</b></code></dt>
<dd>Specifies the methods to bootstrap dynamic method invocations.</dd>

</dl>
<p>

<hr />
<address>
Copyright &copy; 2002-2014
<a target="other" href="http://www.lafortune.eu/">Eric Lafortune</a> @ <a target="top" href="http://www.saikoa.com/">Saikoa</a>.
</address>
</body>
</html>